Renko Trend Trader free

by ForexCove in category Trend at 10/01/2020
Description

This algo was developed by ForexCove. We would like to highlight some of the interesting opportunities in trading Renko charts, by offering this FREE download from our development team.

The Renko Trend Trader trades on a Renko chart of your choice, making use of two moving averages for signal confirmation, along with an ADX filter to measure trend strength. Additionally, you can enable a multiple-trade functionality, which means that for every time a trade criteria is met, a new position is opened. 

This can prove very profitable in strongly trending markets.

It is an experimental bot, providing programmers interested in Renko trading a viable starting point. 

To see our current cBot library, please click here.

Warning! Executing the following cBot may result in loss of funds. Use it at your own risk.
Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgo
´╗┐using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class RENKO_TREND_TRADER : Robot
    {

        [Parameter(DefaultValue = "RENKO_TREND_TRADER")]
        public string cBotLabel { get; set; }

        [Parameter("Currency pair", DefaultValue = "EURUSD")]
        public string TradeSymbol { get; set; }

        [Parameter("Lot Size", DefaultValue = 0.5, MinValue = 0.01, Step = 0.01)]
        public double LotSize { get; set; }

        [Parameter("Trade entry - Use green/red candle", DefaultValue = true)]
        public bool UseCandle { get; set; }

        [Parameter("Trade entry - Use candle above/below MAs", DefaultValue = true)]
        public bool UseCandleMAs { get; set; }

        [Parameter("MA01 Type", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType MAType1 { get; set; }

        [Parameter("MA01 Period", DefaultValue = 16)]
        public int MAPeriod1 { get; set; }

        [Parameter("MA02 Type", DefaultValue = MovingAverageType.Exponential)]
        public MovingAverageType MAType2 { get; set; }

        [Parameter("MA02 Period", DefaultValue = 8)]
        public int MAPeriod2 { get; set; }

        [Parameter("Trade entry - Use ADX", DefaultValue = true)]
        public bool UseADX { get; set; }

        [Parameter("ADX Period", DefaultValue = 6)]
        public int ADXPeriod { get; set; }

        [Parameter("ADX Level", DefaultValue = 32)]
        public int ADXLevel { get; set; }

        [Parameter("Multiply trades", DefaultValue = false)]
        public bool UseMT { get; set; }

        [Parameter("StopLoss in pips", DefaultValue = 40.0)]
        public double StopLoss { get; set; }

        [Parameter("TakeProfit in pips", DefaultValue = 40.0)]
        public double TakeProfit { get; set; }

        [Parameter("Run in backtesting mode", DefaultValue = false)]
        public bool UseBacktesting { get; set; }

        [Parameter("Renko brick in pips", DefaultValue = 10)]
        public double RenkoPips { get; set; }

        [Parameter("Renko bricks to show", DefaultValue = 100)]
        public int BricksToShow { get; set; }

        Symbol CurrentSymbol;
        private MovingAverage MA1;
        private MovingAverage MA2;
        //private DirectionalMovementSystem DMS;
        private MarketSeries TMS;
        private Renko renko;
        private DMS DMS;
        private double renko_bar_close;

        protected override void OnStart()
        {
            //check symbol
            CurrentSymbol = Symbols.GetSymbol(TradeSymbol);

            if (CurrentSymbol == null)
            {
                Print("Currency pair is not supported,please check!");
                OnStop();
            }
            if (UseBacktesting == false)
            {
                TMS = MarketData.GetSeries(TradeSymbol, MarketSeries.TimeFrame);
                MA1 = Indicators.MovingAverage(TMS.Close, MAPeriod1, MAType1);
                MA2 = Indicators.MovingAverage(TMS.Close, MAPeriod2, MAType2);
                DMS = Indicators.GetIndicator<DMS>(TMS.High, TMS.Low, TMS.Close, ADXPeriod, MovingAverageType.WilderSmoothing);
            }
            else
            {
                renko = Indicators.GetIndicator<Renko>(RenkoPips, BricksToShow, 3, "SeaGreen", "Tomato");
                renko_bar_close = renko.Close.Last(1);
                MA1 = Indicators.MovingAverage(renko.Close, MAPeriod1, MAType1);
                MA2 = Indicators.MovingAverage(renko.Close, MAPeriod2, MAType2);
                DMS = Indicators.GetIndicator<DMS>(renko.High, renko.Low, renko.Close, ADXPeriod, MovingAverageType.WilderSmoothing);
            }
        }

        protected override void OnBar()
        {
            if (UseBacktesting == false)
            {
                DoTrade(TMS.Open.Last(1), TMS.Close.Last(1));
            }
        }

        protected override void OnTick()
        {
            if (UseBacktesting == true)
            {
                if (renko.Close.Last(1) != renko_bar_close)
                {
                    renko_bar_close = renko.Close.Last(1);
                    Print("Renko last bar close = {0}", renko_bar_close);
                    DoTrade(renko.Open.Last(1), renko.Close.Last(1));
                }
            }
        }

        private void DoTrade(double lastBarOpen, double lastBarClose)
        {
            if (IsTradePossible() == true && ((UseMT == false && Positions.FindAll(cBotLabel, TradeSymbol).Length == 0) || (UseMT == true)))
            {
                if (((UseCandle == true && lastBarClose > lastBarOpen) || UseCandle == false) && ((UseCandleMAs == true && lastBarClose > MA1.Result.Last(1) && lastBarClose > MA2.Result.Last(1)) || (UseCandleMAs == false)))
                {
                    OpenMarketOrder(TradeType.Buy, LotSize);
                }
                else if (((UseCandle == true && lastBarClose < lastBarOpen) || UseCandle == false) && ((UseCandleMAs == true && lastBarClose < MA1.Result.Last(1) && lastBarClose < MA2.Result.Last(1)) || (UseCandleMAs == false)))
                {
                    OpenMarketOrder(TradeType.Sell, LotSize);
                }
            }
            if (lastBarClose < lastBarOpen)
                ClosePositions(TradeType.Buy);
            else if (lastBarClose > lastBarOpen)
                ClosePositions(TradeType.Sell);

        }

        private void ClosePositions(TradeType tradeType)
        {
            foreach (var position in Positions.FindAll(cBotLabel, TradeSymbol, tradeType))
            {
                var result = ClosePosition(position);
                if (!result.IsSuccessful)
                {
                    Print("Closing market order error: {0}", result.Error);
                    OnStop();
                }
            }
        }

        private void OpenMarketOrder(TradeType tradeType, double dLots)
        {
            var volumeInUnits = CurrentSymbol.QuantityToVolumeInUnits(dLots);
            volumeInUnits = CurrentSymbol.NormalizeVolumeInUnits(volumeInUnits, RoundingMode.Down);

            //in final version need add attempts counter
            var result = ExecuteMarketOrder(tradeType, CurrentSymbol.Name, volumeInUnits, cBotLabel, StopLoss, TakeProfit);
            if (!result.IsSuccessful)
            {
                Print("Execute Market Order Error: {0}", result.Error.Value);
                OnStop();
            }
        }

        private bool IsTradePossible()
        {

            if (UseADX == true && DMS.ADX.Last(0) < ADXLevel)
            {
                Print("No trade - ADX is low - {0}", DMS.ADX.Last(0));
                return false;
            }

                        /*
            if (DMS.ADX.Last(1) > DMS.ADX.Last(0))
            {
                Print("No trade - ADX is go down - current {0} previous - ", DMS.ADX.Last(0), DMS.ADX.Last(1));
                return false;
            }
            */

return true;
        }

        protected override void OnStop()
        {

        }
    }
}
Comments

Terzys - January 12, 2020 @ 19:54

I am trading with the exact same way, using renkos and ADX.

 

Can you guys shoot a quick tutorial video on how to use this cBot?

ForexCove - January 13, 2020 @ 15:10

Yes, it can make for an interesting strategy combining the two. I'll put your video request on our list. Take care!

Renegade - January 15, 2020 @ 15:14

I backtested this from Jan 2018 to Jan 2019 using 0.1 lots and the bot incurred more losses than wins.

Which of your paid cbots works best

ForexCove - January 15, 2020 @ 21:40

Hi Renegade,

Thanks for your comment. Firstly, the free code provided is a programming example of a RENKO trading algo, and will not be made available for commercial use. It was meant to serve as a basis for other programmers interested in RENKO. Also, you cannot backtest with candle or tick data, you have to use RENKO. And cTrader cannot backtest RENKO, so the results you report cannot be taken literally.

I suggest you look into our Swiss Army Knife. A very capable robot.

Detailed description here: https://www.forexcove.com/swiss-army-knife-forex-robot-trader/

In-depth video here:  https://vimeo.com/385086551/99b712da62

Regards,

Nielsen

ForexCove - January 15, 2020 @ 21:45

Renegade, failed to mention we are running with 25% discount on the Swiss Army Knife until January 25.

Use coupon: FXCOVE25

5