lukenum
Pine Script Rookie
Pine Script Rookie
Posts: 6
Joined: January 15th, 2023

Need help with the error

Hello all -

I'm so glad to be in this forum! I have been trying to debug a code that I adopted from someone else for the past two days and still can't get it to work as I expected. Apparently, there are some errors and would love to have someone take a quick look at what I might have missed and point me to the right direction...Note that I'm super new to Pine Script and just had time to watch a crash course today.

Following is the source code I'm working on.
https://www.tradingview.com/script/F4Zm ... promuckaj/

In short, I am trying to add two Fibo alert lines and want an alert to go off after a couple of conditions are met. For the Up Fibo Alert, I would like the price to 1) break up first before triggering an alert to see if the price comes back to breach the Fibo Up Alert Line. Vice versa for the Down Fibo Alert. I tried to set the "if UPLabel" to check but that doesn't seem to work.

Any help would be greatly appreciated.

Cheers,
Luke

Steve Burman
Moderator
Moderator
Posts: 109
Joined: January 13th, 2023

Re: Need help with the error

I'm happy to help but I need further info on this. Have you coded the 2 fibo lines? Also in your comment... price to break up/down first before triggering an alert... how many pip or points or how many bars from your fibo lines before the alert is triggered?

lukenum
Pine Script Rookie
Pine Script Rookie
Posts: 6
Joined: January 15th, 2023

Re: Need help with the error

Hi again Steve - Yes, I have coded both lines, FiboAlertLine (green) and FiboMAlertLine (red). In the code, for the green line, I tried to check whether or not the price is breaching down the line using the following code :
if UPLabel
if close < LfiboVal + ((HfiboVal-LfiboVal)*fiboUpAlertLevel) and close[i+1] >= LfiboVal + ((HfiboVal-LfiboVal)*fiboUpAlertLevel)
BreachesUpFiboAlert := BreachesUpFiboAlert+1
BreachUpFiboAlert := true
To my understanding, this block of codes should check both the current candle and the previous candle to see if the price is breaching the line. I then set the alert to trigger when the condition is true. Somehow, this BreachUpFiboAlert is not working.

And to answer your question, I want to just check whether the price breaches the line (close < the fib line price) in the current candle. Did not set the threshold in term of pip or point.

Steve Burman
Moderator
Moderator
Posts: 109
Joined: January 13th, 2023

Re: Need help with the error

Oh boy that's a long complicated script with no comments!!!

This code is checking if the current candle closes lower than the green alert line and if the prior candle's close is higher or equal to the green alert line. Shouldn't it be that both the current close and prior close is < the green alert line?

From what I see it should be...
if close < LfiboVal + ((HfiboVal-LfiboVal)*fiboUpAlertLevel) and close[i+1] < LfiboVal + ((HfiboVal-LfiboVal)*fiboUpAlertLevel)

lukenum
Pine Script Rookie
Pine Script Rookie
Posts: 6
Joined: January 15th, 2023

Re: Need help with the error

Sorry about the long code 😀 I adopted it from someone else and believe me I wish I had better comments.

So, for the green fib check, I was hoping to detect the first candle breaching the line (from the upside). So, the previous candle close should be above the fib line but the next (current) candle should be closing below the line before the alert triggered… As a result, price of the previous candle value should be greater than the line and the other price value of the current candle should be less than the line per the code. Does that make sense to you?

Return to “Pine Script Q&A”