H=L in the last 10 bars  [SOLVED]

Questions about MultiCharts and user contributed studies.
Splint
Posts: 96
Joined: 25 Nov 2011
Has thanked: 12 times
Been thanked: 1 time

Compile error line 0, column 0

Postby Splint » 19 Oct 2018

I'm trying to compile this simple code which I intend using to filter out thinly traded stocks but it wont compile and it indicates that the issue is in the vars statement which I believe to be OK. Anyone able to take a look and tell me what you think?

Code: Select all

vars: HL(0);

if high(10) = low(10) then

begin
HL=1 ;
Plot1(HL) ;
end;

sptrader
Posts: 710
Joined: 09 Apr 2010
Location: Colorado
Has thanked: 470 times
Been thanked: 261 times
Contact:

Re: Compile error line 0, column 0

Postby sptrader » 20 Oct 2018

I'm trying to compile this simple code which I intend using to filter out thinly traded stocks but it wont compile and it indicates that the issue is in the vars statement which I believe to be OK. Anyone able to take a look and tell me what you think?

Code: Select all

vars: HL(0);

if high(10) = low(10) then

begin
HL=1 ;
Plot1(HL) ;
end;

Code: Select all

vars: HL(0);

if high[10] = low[10] then

HL=1 else HL = 0;

Plot1(HL);
Try this version: you need [ ] not ( ) after the high and low to show bars back, if that's what you want.
What your code says is: if the high 10 bars ago = low 10 bars ago plot a 1 else plot a 0.
good trading.

Splint
Posts: 96
Joined: 25 Nov 2011
Has thanked: 12 times
Been thanked: 1 time

H=L in the last 10 bars

Postby Splint » 20 Oct 2018

Hi,

I'm trying to figure out what's going on with this code. The theory is that if the high equals the low for any given bar in the last ten bars then variable HL is set to 1. It seems that HL is set to 1 regardless of whether the condition is met or not. Any idea where I went wrong?

Code: Select all

Inputs: Barsback(10);

vars: HL(0),
x(Barsback);

for x = Barsback downto 0 Begin

if high[x] = Low[x]

then

HL=1;
x=x-1;

end;

Plot1(HL);

User avatar
TJ
Posts: 7235
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 991 times
Been thanked: 2058 times

Re: H=L in the last 10 bars

Postby TJ » 20 Oct 2018

Hi,

I'm trying to figure out what's going on with this code. The theory is that if the high equals the low for any given bar in the last ten bars then variable HL is set to 1. It seems that HL is set to 1 regardless of whether the condition is met or not. Any idea where I went wrong?

Code: Select all

Inputs: Barsback(10);

vars: HL(0),
x(Barsback);

for x = Barsback downto 0 Begin

if high[x] = Low[x]

then

HL=1;
x=x-1;

end;

Plot1(HL);

The computer is very dumb.
It can only do what you tell it to do.
If you want it to plot a ONE, it will plot a ONE... and continue to plot a ONE until you TELL it to do otherwise.

In your code above... have you told it to do "OTHERWISE"?

stefanols
Posts: 51
Joined: 01 Jan 2014
Has thanked: 14 times
Been thanked: 2 times

Re: compile error:"line 0, column 0"

Postby stefanols » 20 Oct 2018

Hi,

This happens especially when you are using
highD(1) that is using ( ) and not [ ].
An easy way to sort this out would be to have the compiler guide
you and instead of showing compile error it say wrong in row xx.

//Stefan

Splint
Posts: 96
Joined: 25 Nov 2011
Has thanked: 12 times
Been thanked: 1 time

Re: H=L in the last 10 bars

Postby Splint » 21 Oct 2018

Thanks for the feedback TJ. Strictly speaking, not I haven't told it to do otherwise such as an else statement. To my way of thinking HL is initialized as 0 and will switch to and remain at 1 if any bar in the last 10 bars has a high the same value as the low. If every bar in the last 10 bars has a high different from the low then HL should remain at 0, then HL is initialized to 0 as the first line of code is run for the next instrument. Is my understanding incorrect?

User avatar
TJ
Posts: 7235
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 991 times
Been thanked: 2058 times

Re: H=L in the last 10 bars

Postby TJ » 21 Oct 2018

Thanks for the feedback TJ. Strictly speaking, not I haven't told it to do otherwise such as an else statement. To my way of thinking HL is initialized as 0 and will switch to and remain at 1 if any bar in the last 10 bars has a high the same value as the low. If every bar in the last 10 bars has a high different from the low then HL should remain at 0, then HL is initialized to 0 as the first line of code is run for the next instrument. Is my understanding incorrect?

Initialization means -- assigning a value at the BEGINNING.
This is done when you load the indicator into the chart, before anything is running.
ie. it is done only ONCE.

During the course of running your indicator, if you have changed the value of the variable,
the value will stay with the variable . . . until you ask MultiCharts to change it again.

Splint
Posts: 96
Joined: 25 Nov 2011
Has thanked: 12 times
Been thanked: 1 time

Re: H=L in the last 10 bars

Postby Splint » 22 Oct 2018

Thanks TJ, I'm running into problems with the compiler now, syntax error line 18, column 5, only issue is that there is only 16 lines in use.

Anyway, does this look a little better?

Code: Select all

Inputs: Barsback(10);

vars: HL(0),
x(Barsback);

for x = Barsback downto 0 Begin

if high[x] = Low[x]then
begin
HL=1;
x=x-1;
end
else
HL=0;
x=x-1;
Plot1(HL);

User avatar
ABC
Posts: 636
Joined: 16 Dec 2006
Has thanked: 120 times
Been thanked: 359 times
Contact:

Re: H=L in the last 10 bars

Postby ABC » 22 Oct 2018

Hi Split,

your code appears to miss an ending statement for the for loop.
Apart from that you might be able to accomplish what you have by simply storing the value for CurrentBar in a variable when ever High = Low.
Then you can check if the difference between CurrentBar (on the current bar) and the value stored in your variable is within your Barsback value.
If it is plot 1 else plot 0. This way you wouldn't need a loop and your code would be more efficient.

Regards,

ABC

User avatar
TJ
Posts: 7235
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 991 times
Been thanked: 2058 times

Re: H=L in the last 10 bars

Postby TJ » 22 Oct 2018

Try this:

Code: Select all


Inputs: Barsback(10);

vars: HL(0),
x(0);

for x = Barsback downto 0
BEGIN

if high[x] = Low[x]then
begin
HL=1;
// x=x-1;
end
else
begin
HL=0;
//x=x-1;
end;
END;

Plot1(HL);

Splint
Posts: 96
Joined: 25 Nov 2011
Has thanked: 12 times
Been thanked: 1 time

Re: H=L in the last 10 bars

Postby Splint » 24 Oct 2018

Thanks. Minor modification to the code as it was only picking the stock with the H=L condition on the last bar. All good now.

Code: Select all

Inputs: Barsback(100);

vars: HL(0),
x(0);

for x = Barsback downto 0
BEGIN

if high[x] = Low[x]then
begin
HL=1;
end;

END;

Plot1(HL);

if HL=1 then
begin
HL=0;
end;

User avatar
TJ
Posts: 7235
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 991 times
Been thanked: 2058 times

Re: H=L in the last 10 bars  [SOLVED]

Postby TJ » 24 Oct 2018

Thanks. Minor modification to the code as it was only picking the stock with the H=L condition on the last bar. All good now.

. . .

It is good to hear the code is working now.
Thanks for reporting back and sharing your updated code.


Return to “MultiCharts”