MA Crossing Renko free

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

By ForexCove. Ride the trend at the earliest moment. Combine slow MA, with a tight 1 or 5 brick Renko brick for best results.

This robot is a free module from our upcoming advanced Renko trading algo, which is slated for release Q2 2020. We have found that combining a slow moving average, with small renko bricks, can generate very interesting results. As always, for any trend trading algo, go for currency pairs that historically have been most likely to trend.

Trading logic

When Renko brick closes above MA, open buy position

When Renko brick closes below MA, open sell position

When fixed TP is disabled, the bot will hold position until brick closes on opposite side of MA. This free module also allows for trailing SL.

Suggested settings

MA: 800 - 1200

Renko size: 1 or 5

Snapshots 01 EURUSD

 Snapshots 02 EURUSD

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Be sure to visit ForexCove for free downloads and discounts on commercially available Forex Trading Algos.

 

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 MA_Crossing_cBot : Robot
    {

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

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

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

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

        [Parameter("MA Period", DefaultValue = 14)]
        public int MAPeriod { get; set; }

        [Parameter("Signal candle,in bars", DefaultValue = 1, MinValue = 0)]
        public int SignalCandle { get; set; }

        [Parameter("Fixed TP", DefaultValue = false)]
        public bool UseTP { get; set; }

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

        [Parameter("TrailingStop", DefaultValue = false)]
        public bool UseTS { get; set; }

        [Parameter("Trailing Trigger", DefaultValue = 15.0)]
        public double TrailingTrigger { get; set; }

        [Parameter("Trailing Pips", DefaultValue = 4.0)]
        public double TrailingPips { get; set; }

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

            if (CurrentSymbol == null)
            {
                Print("Currency pair is not supported,please check!");
                OnStop();
            }

            MA = Indicators.MovingAverage(MarketSeries.Close, MAPeriod, MAType);
        }

        protected override void OnBar()
        {
            if (MA.Result.Last(SignalCandle) < MarketSeries.Close.Last(SignalCandle) && MA.Result.Last(SignalCandle) > MarketSeries.Low.Last(SignalCandle) && Positions.FindAll(cBotLabel, TradeSymbol, TradeType.Buy).Length == 0)
            {
                ClosePosition(TradeType.Sell);
                OpenMarketOrder(TradeType.Buy, TradeSymbol, LotSize);
            }
            else if (MA.Result.Last(SignalCandle) > MarketSeries.Close.Last(SignalCandle) && MA.Result.Last(SignalCandle) < MarketSeries.High.Last(SignalCandle) && Positions.FindAll(cBotLabel, TradeSymbol, TradeType.Sell).Length == 0)
            {
                ClosePosition(TradeType.Buy);
                OpenMarketOrder(TradeType.Sell, TradeSymbol, LotSize);
            }
        }

        protected override void OnTick()
        {
            if (UseTS == true && Positions.FindAll(cBotLabel, TradeSymbol).Length > 0)
                DoTrailingStop();
        }

        private void ClosePosition(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, string strSymbol, double dLots)
        {
            var volumeInUnits = Symbol.QuantityToVolumeInUnits(dLots);
            volumeInUnits = Symbol.NormalizeVolumeInUnits(volumeInUnits, RoundingMode.Down);
            double TP_in_pips = 0.0;
            if (UseTP == true)
                TP_in_pips = TakeProfit;

            var result = ExecuteMarketOrder(tradeType, strSymbol, volumeInUnits, cBotLabel, 0, TP_in_pips);
            if (!result.IsSuccessful)
            {
                Print("Execute Market Order Error: {0}", result.Error.Value);
                OnStop();
            }
        }

        private void DoTrailingStop()
        {
            var cBotPositions = Positions.FindAll(cBotLabel, TradeSymbol);

            foreach (var position in cBotPositions)
            {
                if (position.TradeType == TradeType.Buy && position.Pips >= TrailingTrigger && position.HasTrailingStop == false)
                {
                    var NewSL = position.TradeType == TradeType.Buy ? (position.EntryPrice + (TrailingPips * Symbol.PipSize)) : (position.EntryPrice - (TrailingPips * Symbol.PipSize));
                    ModifyPosition(position, NewSL, position.TakeProfit, true);
                }
            }

        }

        protected override void OnStop()
        {

        }
    }
}
Comments
5