Dear All,
I'm having trouble creating a simple index that records how often an event (in this case, and inside bar) has occurred over a given look back period (10).
It appears to count the event twice: once correctly at the close of the bar fitting the conditions and then again in the following bar even if the condition isn't met. The index then adjusts correctly in the third bar, barring another trigger.
Here's the code:
Inputs:
LookbackPeriod (10);
Variables:
IBCount(0),
SumIB(0);
SumIB= sum(IBCount,LookbackPeriod);
Condition1 = High < High[1] and Low > Low[1]; {The Inside Bar Condition}
If condition1 = true then begin
IBCount = 1;
end
Else begin IBCount=0;
end;
Plot1(SumIB);
What am I doing wrong please? I've searched the site and only found a discussion surrounding a "Once Begin" bug and another suggesting it may be an architecture issue. I've tried fitting the MaxBarsBack number to the look back period but no dice.
Thanks in advance.
Best regards,
JH
Indicator counting condition twice [SOLVED]
-
- Posts: 4
- Joined: 28 Dec 2014
- Location: London
- Has thanked: 3 times
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
-
- Posts: 4
- Joined: 28 Dec 2014
- Location: London
- Has thanked: 3 times
Re: Indicator counting condition twice
Apologies, TJ:
Code: Select all
Inputs:
LookbackPeriod (10);
Variables:
IBCount(0),
SumIB(0);
SumIB= sum(IBCount,LookbackPeriod);
Condition1 = High < High[1] and Low > Low[1];
If condition1 = true then begin
IBCount = 1;
end
Else begin IBCount=0;
end;
Plot1(SumIB);
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: Indicator counting condition twice
I don't have time to test much (sorry), but if it isn't related to MaxBarsBack -- have you tried using BarStatus so that the count is only performed on bar close?Dear All,
I'm having trouble creating a simple index that records how often an event (in this case, and inside bar) has occurred over a given look back period (10).
It appears to count the event twice: once correctly at the close of the bar fitting the conditions and then again in the following bar even if the condition isn't met. The index then adjusts correctly in the third bar, barring another trigger.
(...)
What am I doing wrong please? I've searched the site and only found a discussion surrounding a "Once Begin" bug and another suggesting it may be an architecture issue. I've tried fitting the MaxBarsBack number to the look back period but no dice.
Using BarStatus the code would look like:
Code: Select all
Inputs:
LookbackPeriod(10);
Variables:
IBCount(0),
SumIB(0),
insideBar(False);
if (BarStatus(1) = 2) then begin
SumIB = sum(IBCount, LookbackPeriod);
insideBar = (High < High[1]) and (Low > Low[1]);
if (insideBar = true) then
IBCount = 1
else
IBCount = 0;
end;
Plot1(SumIB);
-
- Posts: 4
- Joined: 28 Dec 2014
- Location: London
- Has thanked: 3 times
Re: Indicator counting condition twice
Dear Josh, TJ,
Thank you for your help. I tried the code you suggested, but the error still occurs.
I've attached a picture of the problem. I've marked the inside bars with a solid yellow point. The count in the subchart after such a bar jumps to 2 then drops off to 1 the next bar (assuming no further IB).
Many thanks again,
James H
Thank you for your help. I tried the code you suggested, but the error still occurs.
I've attached a picture of the problem. I've marked the inside bars with a solid yellow point. The count in the subchart after such a bar jumps to 2 then drops off to 1 the next bar (assuming no further IB).
Many thanks again,
James H
- Attachments
-
- InsideBarCounter.jpg
- (223.64 KiB) Downloaded 479 times
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
Re: Indicator counting condition twice [SOLVED]
Try this:
Code: Select all
Inputs:
LookbackPeriod (10);
Variables:
IBCount(0),
SumIB(0),
InsideBar(false);
InsideBar = High < High[1] and Low > Low[1];
If InsideBar = true then
begin
IBCount = 1;
end
Else
begin
IBCount = 0;
end;
SumIB = sum( IBCount, LookbackPeriod );
Plot1(SumIB);
-
- Posts: 4
- Joined: 28 Dec 2014
- Location: London
- Has thanked: 3 times
Re: Indicator counting condition twice
Dear TJ,
That worked, thank you. Just trying to understand the subtle difference between the two solutions provided above. Was the issue one of not re-starting the count for the counter-argument? i.e. not beginning again if the event didn't occur?
Thanks again!
That worked, thank you. Just trying to understand the subtle difference between the two solutions provided above. Was the issue one of not re-starting the count for the counter-argument? i.e. not beginning again if the event didn't occur?
Thanks again!