martignal

Created at 19 Jul 2024, 20:09
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
AX

AXEOTH

Joined 06.12.2023

martignal
19 Jul 2024, 20:09


Hello,

Can someone explain me how to add the martignal code into my Algo please ? Or just implement it ?

I try to implement this private void OnPositionsClosed(PositionClosedEventArgs args) but so much errors

 

using System;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo.Robots
{
    
    }

    [Robot(AccessRights = AccessRights.None, AddIndicators = true)]
    public class RENKO1 : Robot
    {
        [Parameter(DefaultValue = 1000)]
        public double Volume { get; set; }
          
        [Parameter(DefaultValue = 2)]
        public double StopLoss { get; set; }
        
        [Parameter(DefaultValue = 4)]
        public double TakeProfit { get; set; }

        protected override void OnBarClosed()
        {
           
           
           if(Positions.Count < 1 && Bars.Last(10).Close < Bars.Last(10).Open && Bars.Last(9).Close < Bars.Last(9).Open && Bars.Last(8).Close < Bars.Last(8).Open && Bars.Last(7).Close < Bars.Last(7).Open && Bars.Last(6).Close < Bars.Last(6).Open && Bars.Last(5).Close < Bars.Last(5).Open && Bars.Last(4).Close < Bars.Last(4).Open && Bars.Last(3).Close < Bars.Last(3).Open && Bars.Last(2).Close < Bars.Last(2).Open && Bars.Last(1).Close < Bars.Last(1).Open && Bars.Last(0).Close > Bars.Last(0).Open)
           {
           ExecuteMarketOrder(TradeType.Sell, SymbolName, Volume, InstanceId, StopLoss, TakeProfit);
           }
           if(Positions.Count < 1 && Bars.Last(10).Close > Bars.Last(10).Open && Bars.Last(9).Close > Bars.Last(9).Open && Bars.Last(8).Close > Bars.Last(8).Open && Bars.Last(7).Close > Bars.Last(7).Open && Bars.Last(6).Close > Bars.Last(6).Open && Bars.Last(5).Close > Bars.Last(5).Open && Bars.Last(4).Close > Bars.Last(4).Open && Bars.Last(3).Close > Bars.Last(3).Open && Bars.Last(2).Close > Bars.Last(2).Open && Bars.Last(1).Close > Bars.Last(1).Open && Bars.Last(0).Close < Bars.Last(0).Open)
           {
           ExecuteMarketOrder(TradeType.Buy, SymbolName, Volume, InstanceId, StopLoss, TakeProfit);
           }
          
        }
        protected override void OnTick()
        {
            // Handle price updates here
        }

     protected override void OnStop()
        {
            // Handle cBot stop here
        }
   
   }


@AXEOTH