EveryDayBetter
Pine Script Master
Pine Script Master
Posts: 27
Joined: February 16th, 2022

How can I get the buy signal earlier?

In the picture, you see the entry signal of a pullback strategy. It's a daily chart.
My problem is, that the entry signal appears with a delay (when candle has opend at the next day).

I would like to get the signal before the market closes. I tried to changed everything with "close" in the script below to "open", but that doesn't worked.
What can I do that the signal comes at the same day without a delay?

Image

Code: Select all

//@version=5
strategy('pullback', overlay=true)

if close > ta.sma(close, 200) and close < ta.sma(close, 21)
    strategy.entry('long', strategy.long)

//Declaring percentage numbers
SL = 0.10
TP = 0.08

//Calculating the exit price for sl and tp
longstop = strategy.position_avg_price * (1 - SL)
longprofit = strategy.position_avg_price * (1 + TP)

//for long positions
if strategy.position_size > 0
    strategy.exit(id='close', stop=longstop, limit=longprofit)

sma1 = ta.sma(close, 21)
sma2 = ta.sma(close, 50)

plot(sma1)
plot(sma2)


processingclouds
Pine Script Master
Pine Script Master
Posts: 115
Joined: January 30th, 2022

Re: How can I get the buy signal earlier?

Set the calc_on_every_tick to true, so in your code :

Code: Select all

strategy('pullback', overlay=true, calc_on_every_tick =true)


Return to “Pine Script Q&A”