Set Trade Delay

Hi there.

I am trying to get a time delay for the next open day.

When i apply the following formula:

SetTradeDelays(1,1,1,1);

My plot shape arrows do not delay to the next open day. It stays on the same day.

I am trying to get the buy signal once the price is more than 75 moving day average.
And sell once it is below.

Any help is much appreciated.

Thanks,

SetOption ( "maxopenpositions", mp = 20 );

SetPositionSize(5, spsPercentOfEquity);


MovingAv = MA(C, 75);

LongEntry = C > MovingAv;
LongExit = C < MovingAv;

Buy = LongEntry;
Sell = LongExit;




Buy= ExRem( Buy, Sell);
Sell= ExRem( Sell, Buy);
BuyPrice=SellPrice=Open;
SetTradeDelays(1,1,1,1);



Plot( C, "close ", colorDefault , styleCandle );

Plot(MA(Close,75), "MA", colorYellow, styleLine, Null, Null, 0 );


PlotShapes(Buy * ShapeUpArrow, colorBlue, 0, L);
PlotShapes(Sell * ShapeUpArrow, colorYellow, 0, L);

_SECTION_END();
)`

As it explains in the documentation, the SetTradeDelays() function "Sets trade delays applied by the backtester." It doesn't affect plotting. You could easily shift your Buy and Sell arrays using the Ref() function:

plotBuy = Ref(Buy,-1);
plotSell = Ref(Sell,-1);

Then you would use plotBuy and plotSell in your PlotShapes() call instead of using Buy and Sell.

4 Likes

One way to do it is to recall the value of the Buy and Sell delays from the Status function and use that to offset the arrows in your PlotShapes call.

eg

PlotShapes((Ref(Buy, -Status("BuyDelay")) > 0) * shapeUpArrow, colorBrightGreen, 0, L);
PlotShapes((Ref(Sell, -Status("SellDelay")) > 0) * shapeDownArrow, colorRed, 0, H);
3 Likes