convert this bot to martingale bot

Created at 14 Nov 2022, 18:48
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!
Leo4's avatar

Leo4

Joined 18.08.2022

convert this bot to martingale bot
14 Nov 2022, 18:48


Hello my friends!

I really need  help;  I want to convert this bot to martingale bot (Open the position just only on my Conditions).

thank you.

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

namespace cAlgo.Robots30
{

    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class FractalsSample : Robot
    {
        private double _volumeInUnits;
        private ExponentialMovingAverage _EMA;
 
        [Parameter("Source")]
        public DataSeries SourceSeries { get; set; }

        [Parameter("Max Spread", DefaultValue = 1, MinValue = 0, MaxValue = 300)]
        public double MaxSpread { get; set; }

        [Parameter("Volume (Lots)", DefaultValue = 0.01)]
        public double VolumeInLots { get; set; }

        [Parameter("Stop Loss (Pips)", DefaultValue = 15)]
        public double StopLossInPips { get; set; }

        [Parameter("Take Profit (Pips)", DefaultValue = 15)]
        public double TakeProfitInPips { get; set; }

  
        [Parameter("Label", DefaultValue = "name")]
        public string Label { get; set; }

 

        public Position[] BotPositions
        {
            get { return Positions.FindAll(Label); }
       
       }

 
        protected override void OnStart()
        {
            _volumeInUnits = Symbol.QuantityToVolumeInUnits(VolumeInLots);
            _EMA  = Indicators.ExponentialMovingAverage (SourceSeries ,100); 
            
 }

        protected override void OnBar()
        {
 
 
                var cBotPositions = Positions.FindAll(Label);
                var lastIndex = MarketSeries.Close.Count - 1;
                double EMA = _EMA.Result[lastIndex - 1];

            if ( EMA  < Bars.ClosePrices.Last(1)                                  &&
                Bars.ClosePrices.Last(2)  <  Bars.ClosePrices.Last(1)  &&
                    cBotPositions.Length == 0  
                    )
                {
                    ExecuteMarketOrder(TradeType.Buy, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips);
                }
  
        if  ( EMA  > Bars.ClosePrices.Last(1)                                    &&
              Bars.ClosePrices.Last(2) > Bars.ClosePrices.Last(1)     &&
                    cBotPositions.Length == 0  )
                {
                    ExecuteMarketOrder(TradeType.Sell, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips);
                }
    }  }
}
 


cTrader Automate
@Leo4
Replies