买入和卖出信号在情节方面因蜡烛而异 [英] Buy and Sell signals are differing by a candle with respect to plot

查看:56
本文介绍了买入和卖出信号在情节方面因蜡烛而异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试根据以下策略生成的信号绘制图表.但我从脚本中观察到的是信号产生点相差一个蜡烛.如果有人知道这件事,请帮助我.作为参考,我附在下面的快照

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.买入信号快照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)

推荐答案

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

这篇关于买入和卖出信号在情节方面因蜡烛而异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆