Surya Obulareddy
Surya Obulareddy

Reputation: 5

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

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)

Upvotes: 0

Views: 441

Answers (1)

Andrey D
Andrey D

Reputation: 1714

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

Upvotes: 1

Related Questions