Reputation: 599
I have written a sample strategy in pinescript. I am confused as to how using this current data gives me No data
in backtesting.
//@version=5
strategy("My strategy", overlay=true, margin_long=100, margin_short=100)
ma1 = ta.ema(close, 28)
ma2 = ta.ema(close, 36)
ma3 = ta.sma(close, 20)
ma4 = ta.sma(close, 50)
plot(ma1, title='MA 1')
plot(ma2, title='MA 2')
plot(ma3, title='MA 3')
plot(ma4, title='MA 4')
longCondition = ((close<=ma1) and (close>ma2) and (close>ma3) and (close<=ma4))?true:false
if (longCondition)
strategy.entry(id = 'Long Entry', direction = strategy.long, when = longCondition, alert_message = 'Long(' + syminfo.ticker + '): Started')
shortCondition = ta.crossover(ma1,ma2)
if (shortCondition)
strategy.entry(id = 'Long Entry', direction = strategy.short, when = shortCondition, alert_message = 'Short(' + syminfo.ticker + '): Started')
However, if change the longCondition
to
longCondition = ((close<=ma1) and (close>ma2) and (close<=ma3) and (close<=ma4))?true:false
I can see the backtesting results.
I noticed this happens when the current candle is satisfying the condition then it shows the backtest results, if on the current candle the condition is not satisfied then no data error is given.
But I think no matter which condition I select backtesting data should be generated because this condition should have occurred somewhere in the past, right? So that point of entry should be taken and backtest chart should be generated.
Please tell me how does this work and where am I going wrong here in understanding.
Upvotes: 0
Views: 1713
Reputation: 21294
no matter which condition I select backtesting data should be generated because this condition should have occurred somewhere in the past, right?
Not really. Unless you can provide proof that your conditions have been satisfied and the strategy tester shows "no data", I will take the strategy tester's word for it.
I added your script (without the change you mentioned) to BTCBUSD Binance 1W chart. There is no entry, hence -> no data
If I go to 1D time frame, then there are some trades and there is data for those.
Upvotes: 1