Page 1 of 1

Error message dividing lines

Posted: Mon Feb 13, 2023 8:53 pm
by Jan76
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)

Re: Error message dividing lines

Posted: Tue Feb 14, 2023 6:42 am
by Steve Burman
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

Re: Error message dividing lines

Posted: Tue Feb 14, 2023 11:01 am
by Jan76
Thanks Steve, I'll try then I'll update you!

Re: Error message dividing lines

Posted: Tue Feb 14, 2023 8:27 pm
by Jan76
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

Re: Error message dividing lines

Posted: Wed Feb 15, 2023 8:40 pm
by Steve Burman
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?

Re: Error message dividing lines

Posted: Thu Feb 16, 2023 1:20 am
by Steve Burman
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

Re: Error message dividing lines

Posted: Thu Feb 16, 2023 9:24 am
by Jan76
Hi, seriously I don't know what to do with this script, made by ChatGPT. Can you correct it for me please?

Gianluca

Re: Error message dividing lines

Posted: Thu Feb 16, 2023 11:32 pm
by Steve Burman
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.

Re: Error message dividing lines

Posted: Fri Feb 17, 2023 6:24 pm
by Jan76
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.

Re: Error message dividing lines

Posted: Mon Feb 20, 2023 1:31 am
by Steve Burman
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.