Buy and Sell signals are differing by a candle with respect to plot

[亡魂溺海] 提交于 2021-02-11 14:34:53

问题


I tried to plot a graph based on the signals which are generated from the below strategy. But I observed from the script is signal generation points are differing by a Candle. If anyone will know about this please help me. For reference, I attached below snapshots

1. Buy signal snapshot 2. Sell signal snapshots


//@version=4
strategy("My Strategy", overlay=true)
orderType = 0
longCondition = crossover(sma(close, 14), sma(close, 28))
if (longCondition)
    strategy.entry("My Long Entry Id", strategy.long)
    orderType := 1

shortCondition = crossunder(sma(close, 14), sma(close, 28))
if (shortCondition)
    strategy.entry("My Short Entry Id", strategy.short)
    orderType := -1
plot(orderType,"OrderType",color.black)

回答1:


//@version=4
strategy("My Strategy", overlay=true, process_orders_on_close=true)
orderType = 0
longCondition = crossover(sma(close, 14), sma(close, 28))
if (longCondition)
    strategy.entry("My Long Entry Id", strategy.long)
    orderType := 1

shortCondition = crossunder(sma(close, 14), sma(close, 28))
if (shortCondition)
    strategy.entry("My Short Entry Id", strategy.short)
    orderType := -1
plot(orderType,"OrderType",color.black)


来源:https://stackoverflow.com/questions/60693501/buy-and-sell-signals-are-differing-by-a-candle-with-respect-to-plot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!