how should I shift the value of Donchian's Low

Created at 15 Sep 2023, 05:01
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!
JXTA's avatar

JXTA

Joined 23.08.2023

how should I shift the value of Donchian's Low
15 Sep 2023, 05:01


This is the Donchian Robot sample

using cAlgo.API;
using cAlgo.API.Indicators;
namespace cAlgo.Robots
{
    /// This sample cBot shows how to use the Donchian Channel indicator
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class DonchianChannelSample : Robot
    {
        private double _volumeInUnits;
        private DonchianChannel _donchianChannel;
        [Parameter("Volume (Lots)", DefaultValue = 0.01)]
        public double VolumeInLots { get; set; }
        [Parameter("Label", DefaultValue = "Sample")]
        public string Label { get; set; }
        [Parameter("Source")]
        public DataSeries Source { get; set; }
        public Position[] BotPositions
        {
            get
            {
                return Positions.FindAll(Label);
            }
        }
        protected override void OnStart()
        {
            _volumeInUnits = Symbol.QuantityToVolumeInUnits(VolumeInLots);
            _donchianChannel = Indicators.DonchianChannel(20);
        }
        protected override void OnBar()
        {
            if (Bars.LowPrices.Last(1) <= _donchianChannel.Bottom.Last(1) && Bars.LowPrices.Last(2) > _donchianChannel.Bottom.Last(2))
            {
                ClosePositions(TradeType.Sell);
                ExecuteMarketOrder(TradeType.Buy, SymbolName, _volumeInUnits, Label);
            }
            else if (Bars.HighPrices.Last(1) >= _donchianChannel.Top.Last(1) && Bars.HighPrices.Last(2) < _donchianChannel.Top.Last(2))
            {
                ClosePositions(TradeType.Buy);
                ExecuteMarketOrder(TradeType.Sell, SymbolName, _volumeInUnits, Label);
            }
        }
        private void ClosePositions(TradeType tradeType)
        {
            foreach (var position in BotPositions)
            {
                if (position.TradeType != tradeType) continue;
                ClosePosition(position);
            }
        }
    }
}
 

is there anyway I could shift/offset any of the donchian value by 10 bars ? lets see I wanna shift _donchianChannel.Bottom.LastValue by 10bars to right hand side

lets say when I am retrieving donchian bottom value in the yellow index, I want to receive a ready shifted value, how can I do that? what formula should I write in the robot?


@JXTA
Replies

PanagiotisChar
15 Sep 2023, 06:40

Hi there,

Just take the _donchianChannel.Bottom.Last(10) value. More generally use _donchianChannel.Bottom.Last(1 + offset)

 


@PanagiotisChar

JXTA
18 Sep 2023, 09:43

RE: how should I shift the value of Donchian's Low

PanagiotisChar said: 

Hi there,

Just take the _donchianChannel.Bottom.Last(10) value. More generally use _donchianChannel.Bottom.Last(1 + offset)

 

Thank you so much!


@JXTA