首页 > 解决方案 > 就图而言,买入和卖出信号相差一根蜡烛

问题描述

我试图根据以下策略生成的信号绘制图表。但我从脚本中观察到信号生成点与 Candle 不同。如果有人知道这件事,请帮助我。作为参考,我附在下面的快照

1. 买入信号快照 2. 卖出信号快照


//@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)

标签: pine-script

解决方案


//@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)

推荐阅读