Page 1 of 1

Function not plotting as intended. PLEASE HELP.

Posted: Thu Feb 23, 2023 6:20 pm
by Ponderosa
So I got this script layout from a youtube video. I finally got it to send alerts, however it isn't triggering properly. The first plot function (yellow triangleup) is not working as intended. The second plot function (orange diamonds) seems to work correctly. I want them to print together. When I set this up for 'COINBASE:BTCUSD' it works perfectly, but for some reason on stocks, it gets out of wack. It almost seems like the time periods are offset by half an hour or something. I've been trying to figure this out for days now. If you have any ideas I'd love to hear them. Thank you!!

//@version=5
indicator('Test Script', overlay=true)

Timeframe = input.timeframe('60')

i_T26 = input.symbol('NYSE:DINO')

f_strategy() =>
test = close > open*1.001 and barstate.isconfirmed ? 1 : close < open*0.999 and barstate.isconfirmed ? -1 : 0

f_screener(_ticker) =>
message = ''
[signal, _tickerClose] = request.security(_ticker, Timeframe, [f_strategy(), close])
if signal == 1
message := 'Go Long ' + _ticker + '@' + str.tostring(_tickerClose)
else if signal == -1
message := 'Go Short ' + _ticker + '@' + str.tostring(_tickerClose)

if signal == 1 or signal == -1
alert(message, alert.freq_once_per_bar_close)
signal

t26_signal = f_screener(i_T26)
plotshape(t26_signal, title='Alert', style=shape.triangleup, location=location.belowbar,
color=color.yellow, size=size.large)

plotshape(f_strategy()==-1 or f_strategy()==1, title='debug', style=shape.diamond,
location=location.belowbar, color=color.orange, size=size.large)

Image Image

Re: Function not plotting as intended. PLEASE HELP.

Posted: Thu Feb 23, 2023 6:38 pm
by Ponderosa
Also, had never written a line of code before about a month ago so please bear with my limited understanding on Pine. Thanks.

Re: Function not plotting as intended. PLEASE HELP.

Posted: Fri Feb 24, 2023 7:06 am
by Steve Burman
Hey Ponderosa,

Firstly when you copy code can you please indent if statements, custom functions and line continuations

Your code is not compiling because of the 3rd line below does not assign anything to signal
if signal == 1 or signal == -1
alert(message, alert.freq_once_per_bar_close)
signal

I'm also trying to understand your custom function f_screener(_ticker). Can you please exiplain what it is doing?

Thanks

Re: Function not plotting as intended. PLEASE HELP.

Posted: Sat Feb 25, 2023 12:25 am
by Ponderosa
Sorry, I'm pretty sure it was indented in the draft but they were realigned when submitted. I saw that immediately and was like aww what the heck?

The script does compile and like I say, it runs well on crypto markets but goes haywire on regular equities. The 'signal' line is part of the screener function; it will not compile without it. I really wish I could post a screenshot of my chart but here it is on twitter so you can see what I'm talking about: https://twitter.com/GrayMan1111/status/ ... XqEyw&s=19

The purpose of the script is to run alerts on multiple securities from a single alert. So I can add:
i_T1 = input.symbol('AAPL')
i_T2 = input.symbol('AFL')
i_T3 = input.symbol('ALLY')
i_T4 = input.symbol('AMD')
i_T5 = input.symbol('AMZN')
etcetera, and a plotshape function for each. Then just ignore the symbol the alert was generated on and read the message.

Thanks a lot for the reply Steve, I really really do appreciate it.

Re: Function not plotting as intended. PLEASE HELP.

Posted: Sat Feb 25, 2023 1:00 am
by Ponderosa
I'm sure you know this but just in case you overlooked it, the first plotshape function is pulling from the input.symbol input while the second plotshape function is pulling from the chart.

Re: Function not plotting as intended. PLEASE HELP.

Posted: Sat Feb 25, 2023 4:22 am
by Ponderosa
The issue also vanishes on the daily timeframe, so only happening on the shorter intraday timeframes. It definitely seems to be a timeframe issue to me but I have no idea how to remedy it.

Re: Function not plotting as intended. PLEASE HELP.

Posted: Tue Feb 28, 2023 10:56 pm
by Steve Burman
Sorry I can't help you on this one. Hopefully someone else can.

Re: Function not plotting as intended. PLEASE HELP.

Posted: Fri Mar 17, 2023 8:18 pm
by RobAgrees
Not sure what the issue was. I reformatted the script and it works on every timeframe and asset I tried

Image

Code: Select all

//@version=5
indicator('Test Script', overlay=true)

Timeframe = input.timeframe('60')

i_T26 = input.symbol('NYSE:DINO')

f_strategy() =>
    test = close > open*1.001 and barstate.isconfirmed ? 1 : close < open*0.999 and barstate.isconfirmed ? -1 : 0

f_screener(_ticker) =>
    message = ''

    [signal, _tickerClose] = request.security(i_T26, Timeframe, [f_strategy(), close])

    if signal == 1
        message := 'Go Long ' + _ticker + '@' + str.tostring(_tickerClose)
    else if signal == -1
        message := 'Go Short ' + _ticker + '@' + str.tostring(_tickerClose)

    if signal == 1 or signal == -1
        alert(message, alert.freq_once_per_bar_close)
        signal

t26_signal = f_screener(i_T26)
plotshape(t26_signal, title='Alert', style=shape.triangleup, location=location.belowbar,color=color.yellow, size=size.large)

plotshape(f_strategy()==-1 or f_strategy()==1, title='debug', style=shape.diamond,location=location.belowbar, color=color.orange, size=size.large)

Re: Function not plotting as intended. PLEASE HELP.

Posted: Thu May 18, 2023 1:02 am
by Ponderosa
Thank you Rob. If you look closely, they don't always both plot, particularly late on the 8th. It's difficult to tell because it's so cluttered, but there are actually several instances where only one function plots.