0

I was trying to backtest a breakout strategy.

The problem is when the longCondition is met, buystop is triggered. But this buy order if not fulfilled in the next candle looks for signals in the following candles. How to stop looking for fulfillment once it is not met in next candle? I tried using strategy. Cancel but it could not cancel the order fulfillment if not fulfilled in the next candle.

hh = highest(high,13)
longCondition=close >= hh[1]
if (longCondition)
    StopPrice= high+syminfo.mintick
    LimitPrice= StopPrice+(4*syminfo.mintick)
    strategy.entry("13 days breakout",long=true, stop=StopPrice, limit= LimitPrice)
bad_coder
  • 11,289
  • 20
  • 44
  • 72
Abhay Sahu
  • 11
  • 2

1 Answers1

0

Check how many bars passed since your long condition by storing bar_index in some variable.

var bars = bar_index
if (longCondition)
    StopPrice= high+syminfo.mintick
    LimitPrice= StopPrice+(4*syminfo.mintick)
    strategy.entry("13 days breakout",long=true, stop=StopPrice, limit= LimitPrice)
    bars := bar_index    
    
if (bar_index - bars) >=2
    strategy.cancel("13 days breakout")
    
Starr Lucky
  • 1,578
  • 1
  • 7
  • 8