Jan76
Pine Script Rookie
Pine Script Rookie
Posts: 5
Joined: February 13th, 2023

Error message dividing lines

Hi to all,
For the compiler the dividing lines of this code are not correct. Can you explain please?
if (macdResult == 0 || stochResult == 0 || bollingerResult == 0)

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

Re: Error message dividing lines

Hey Jan,

Those dividing lines are not valid syntax. I've never seen them before in pinescript. What are you trying to achieve?

If it's testing whether all 3 booleans are true, you can do this?
if macdResult == 0 and stochResult == 0 and bollingerResult == 0
do something

If it's testing only whether macdResult is true, you can do this?
if macdResult == 0
stochResult == 0
bollingerResult == 0

I hope this helps

Jan76
Pine Script Rookie
Pine Script Rookie
Posts: 5
Joined: February 13th, 2023

Re: Error message dividing lines

Thanks Steve, I'll try then I'll update you!

Jan76
Pine Script Rookie
Pine Script Rookie
Posts: 5
Joined: February 13th, 2023

Re: Error message dividing lines

Hi Steve,
I changed the wrong line with the first one suggested by you and seems correct. By the way the compiler still doesn't want to load the script, even there are apparently no errors.
So I would let you see all the script so you could see if there's something wrong, and if you like make some corrections. Maybe you will get some fun:)
It's a script for scalping EUR/USD at 15 mins, but I think it could work also for cryptovalues.
Here's the script


//@version=5
study("My EUR/USD Trade")

// Set the currency pair to trade
string symbol = "EUR/USD"

// Set the lot size to trade
double lot = 0.01

// Set the stop loss and take profit levels in pips
int sl = 30
int tp = 60

// Calculate the stop loss and take profit levels in terms of the symbol's base currency
double stopLoss = SymbolInfoDouble(symbol, SYMBOL_BID) - sl * SymbolInfoDouble(symbol, SYMBOL_POINT)
double takeProfit = SymbolInfoDouble(symbol, SYMBOL_BID) + tp * SymbolInfoDouble(symbol, SYMBOL_POINT)

// Create arrays to store the MACD, Stochastic and Bollinger Bands values
double macd[]
double macdSignal[]
double macdHist[]
double slowK[]
double slowD[]
double upperBand[]
double middleBand[]
double lowerBand[]

// Calculate the MACD values
int fastLength = 12
int slowLength = 26
int signalLength = 9
int macdResult = iMACD(symbol, PERIOD_M15, fastLength, slowLength, signalLength, PRICE_CLOSE, macd, macdSignal, macdHist)

// Calculate the Stochastic values
int stochLength = 14
int stochSmoothing = 3
int stochResult = iStochastic(symbol, PERIOD_M15, stochLength, stochSmoothing, PRICE_CLOSE, MODE_MAIN, slowK, slowD)

// Calculate the Bollinger Bands values
int bollingerPeriod = 20
int bollingerDeviation = 2
int bollingerResult = iBands(symbol, PERIOD_M15, bollingerPeriod, bollingerDeviation, PRICE_CLOSE, MODE_MAIN, upperBand, middleBand, lowerBand)

// Check if the MACD, Stochastic and Bollinger Bands calculations were successful
if macdResult == 0 and stochResult == 0 and bollingerResult == 0
{
Print("Failed to calculate MACD, Stochastic or Bollinger Bands. Error code: ", GetLastError())
return
}

// Get the latest MACD, Stochastic and Bollinger Bands values
double currentMacd = macd[macdResult - 1]
double currentMacdSignal = macdSignal[macdResult - 1]
double currentSlowK = slowK[stochResult - 1]
double currentSlowD = slowD[stochResult - 1]
double currentUpperBand = upperBand[bollingerResult - 1]
double currentMiddleBand = middleBand[bollingerResult - 1]
double currentLowerBand = lowerBand[bollingerResult - 1]

// Check if the MACD histogram is above the signal line and the Stochastic %K is above %D, which signals a bullish trend
if (currentMacd > currentMacdSignal && currentSlowK > currentSlowD)
{
// Buy entry

Gianluca

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

Re: Error message dividing lines

The syntax is wrong for version 5. We don't use double types but instead use float. Also we don't use {

Have you tried converting this from Python on some other language?

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

Re: Error message dividing lines

If there's no errors and it's not loading, look for a small red circle with a white exclamation mark near the top left of the chart near where the script would be situated. That is for errors related to the market rather than the script

Jan76
Pine Script Rookie
Pine Script Rookie
Posts: 5
Joined: February 13th, 2023

Re: Error message dividing lines

Hi, seriously I don't know what to do with this script, made by ChatGPT. Can you correct it for me please?

Gianluca

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

Re: Error message dividing lines

Ok that makes sense where it came from. ChatGPT will only create what you ask for and it's not accurate because it has only recently started learning pinescript but will get better over time. The script doesn't make sense to me so I don't know what you are wanting it to do. Moreover, I don't have the time to build scripts for people. What I suggest for your next step is to define what it is you want the script to do. Set it out in steps. I'm happy to critique it for you if you post it here.

Jan76
Pine Script Rookie
Pine Script Rookie
Posts: 5
Joined: February 13th, 2023

Re: Error message dividing lines

My purpose was to build a script for 15 min scalping especially for the pair EUR/USD, as I wrote in a previous post. Unfortunately I don't have the knowledge to make it better and I guess Gpt would not be able to improve it without the right advices.

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

Re: Error message dividing lines

Again I am happy to critique your strategy. Tell me in plain English what your entry reasons are including any filtering and what your exit reasons are. Also how do you want this to display on the chart and any alerts you would require.

Also have you considered doing the Pine Script Mastery Course? I can vouch for how it has made a HUGE difference in my scripting as well as in the success of my trading.

Return to “Pine Script Q&A”