Reputation: 35
i am planning to test one very simple strategy in tradingview which needs to be executed based on time and color of previous candle. Below is my code. I am trying to run it on 15 Minute candle, if the 9:15 to 9:30 candle is green then buy else sell.
strategy("Time_Strategy", overlay=true, margin_long=100, margin_short=100)
if hour(time) == 09 and minute(time) == 31
longCondition = open[1] < close[1]
strategy.entry("Buy", strategy.long,1, when = longCondition)
shortCondition = open[1] > close[1]
strategy.entry("Buy", strategy.long,1, when = shortCondition)
When i run this i get "No Data" error in tradingview strategy tester.
Can someone please help if i am missing something.
Upvotes: 1
Views: 6888
Reputation: 21121
You have two issues:
strategy.entry()
call should be of short
type.This should work:
//@version=5
strategy("Time_Strategy", overlay=true, margin_long=100, margin_short=100)
if hour(time) == 09 and minute(time) == 30
longCondition = open[1] < close[1]
strategy.entry("Buy", strategy.long,1, when = longCondition)
shortCondition = open[1] > close[1]
strategy.entry("Sell", strategy.short,1, when = shortCondition)
Upvotes: 2