简体   繁体   中英

No data shows after writing a strategy code in trading view

I have written a PineScript strategy that uses volume, 3 most popular EMA's (Exponential Moving Averages), Divergences and key levels (daily and weekly) to generate buy and sell signals. However, when I try to test the script on TradingView, it says "no data."

I have double-checked that I am using the correct symbol and the correct timeframe in the chart, but the issue persists. I have also checked that I have enough historical data available for the script to generate the signals, but the problem still persists.

Is there any way to fix this "no data" issue in my PineScript strategy on TradingView? Or is there any way to diagnose the problem and find out what is causing it?

//@version=4
strategy("Volume, EMA and POC Strategy", overlay=true)

// Define the lookback period for the volume
lookback_volume = 30

// Define the lookback period for the EMA
lookback_ema10 = 10
lookback_ema20 = 20
lookback_ema50 = 50

// Define the lookback period for the POC
lookback_poc = 30

// Calculate the average volume
avg_volume = sma(volume, lookback_volume)

// Calculate the 3 EMA's
ema10 = ema(close, lookback_ema10)
ema20 = ema(close, lookback_ema20)
ema50 = ema(close, lookback_ema50)

// Get the number of bars since the last bar with highest volume
highest_volume_index = barssince(volume == max(volume[1], lookback_poc))

// Get the price level associated with that bar
poc_price = close[highest_volume_index]

// Define the buy condition as volume above average and EMA's are trending upwards
buy = volume > avg_volume and ema10 > ema20 and ema20 > ema50

// Define the sell condition as volume profile is bearish and POC is below the close price
sell = poc_price < close

// Plot the signals on the chart
plotshape(buy, location=location.belowbar, style=shape.arrowup, color=color.green, text="Buy")
plotshape(sell, location=location.abovebar, style=shape.arrowdown, color=color.red, text="Sell")

tried to tweak the time frames, but didnt work

Your code correctly execute, it plot on the chart the plotshape you ask.
Your code send you a No data in the strategy tester tab because your code doesn't enter any trade.
To enter a trade in a pinescript strategy, you should use at least a 'strategy.enter' function.
Please read this for more complete information: https://www.tradingview.com/pine-script-docs/en/v5/concepts/Strategies.html?highlight=strategy

Also, your code should be in the version 5 (the version 4 of pinescript is obsolete), here the converted code:

//@version=5
strategy('Volume, EMA and POC Strategy', overlay=true)

// Define the lookback period for the volume
lookback_volume = 30

// Define the lookback period for the EMA
lookback_ema10 = 10
lookback_ema20 = 20
lookback_ema50 = 50
…
// Define the sell condition as volume profile is bearish and POC is below the close price
sell = poc_price < close

// Plot the signals on the chart
plotshape(buy, location=location.belowbar, style=shape.arrowup, color=color.new(color.green, 0), text='Buy')
plotshape(sell, location=location.abovebar, style=shape.arrowdown, color=color.new(color.red, 0), text='Sell')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM