Page 1 of 1

Cannot figure out error message.

Posted: Thu Jan 04, 2024 3:46 am
by cjdavis
I am getting the following error message for the code below. I have been stuck on this for days. Can anyone help trouble shoot?

Error at 28:16 Syntax error at input 'VPAIndx'

// © cnddavis

//@version=5
//Looking for anomalies between Volume and the Price Range/Body/Spread of the current bar.
indicator(title="Volume_Price_Analysis_Index", shorttitle = "VPA_Indx",precision=2, overlay=false)

// Would like this input below to be variable based on the Chart TF.
//Can we input the number of days and convert it to the number of bars needed based on the TF?
//I.E. 3 days = 234 bars on the 5' Chart; 78 bars on the 15' Chart; 39 bars on the 30' chart, etc.??
Bar_Count = input.int(title="How many bars to average:", defval=21)

// Compare current bar volume to average volume
AvgVolume = ta.sma(volume, Bar_Count)
VolumeIndx = (volume/AvgVolume)

// Compare current bar price (spread) range to average bar price range
CurrentSpread = math.abs(open-close)
AvgSpread = ta.sma(CurrentSpread, Bar_Count)
SpreadIndx = (CurrentSpread/AvgSpread)

// Compare current bar volume index to price range (spread) index
VPAIndx = VolumeIndx/SpreadIndx

// A value of 1 means that both the volume and price range are average.
// Less than 1 means that the volume is low for the price range so want to subtract 1 to make this a negative number.
// The difference between 1 and 0 are small compared to how large the greater than 1 results are so want to accentuate these negative numbers to see them better on the chart indicator.
if VPAIndx < 1 // <= This is line 28
VPAIndx := ((VolumeIndx/SpreadIndx)-1)*100

plotColor = (open<close) ? color.green : (open>close) ? color.red : color.silver

plot(VPAIndx, style=plot.style_histogram, linewidth=4,color=plotColor)

Re: Cannot figure out error message.

Posted: Thu Jan 04, 2024 4:22 am
by Gokkul
Code that is to be part of the "IF Condition" should be indented (1 Tab Space)

Your Code

Code: Select all

if VPAIndx < 1 // <= This is line 28
VPAIndx := ((VolumeIndx/SpreadIndx)-1)*100
Correct Code

Code: Select all

if VPAIndx < 1 // <= This is line 28
	VPAIndx := ((VolumeIndx/SpreadIndx)-1)*100
This is the error I could see when I tried to run the script.
Correcting this the script runs for me.

Hope this helps

Cheers
Gokkul

Re: Cannot figure out error message.

Posted: Thu Jan 04, 2024 4:50 am
by cjdavis
Thank you for your reply. The indentation did not come through when I copied and pasted. I do have it in my code and it still throws the error.

Image

Not sure if the screen shot copied into this reply properly?

CJD

Re: Cannot figure out error message.

Posted: Thu Jan 11, 2024 2:52 am
by cjdavis
Lot's of views but still no answer? I thought this may be an easy fix. I do have the indentation like Gokkol suggests, but am still getting the same error. Any help would be appreciated.

Re: Cannot figure out error message.

Posted: Fri Jan 12, 2024 6:59 am
by Gokkul
Hello

The script runs fine for me.
But then I tried to recreating the error you have.

One way I could recreate the error is by adding an extra space.


Correct code with indentation : No error for me

Code: Select all

if VPAIndx < 1 // <= This is line 28
    VPAIndx := ((VolumeIndx/SpreadIndx)-1)*100


Code with indentation and an extra space : Error at 28:16 Syntax error at input 'VPAIndx'

Code: Select all

if VPAIndx < 1 // <= This is line 28
     VPAIndx := ((VolumeIndx/SpreadIndx)-1)*100
Maybe you have an extra space.

Hope this helps

Cheers
Gokkul