Hi think-Script community.
I found this code (see below) here https://usethinkscript.com/threads/consecutive-bar-count-indicator-for-thinkorswim.324/ and modified it to suit my purpose and it works really well as you can see in the photos below (the "def Condition" is only for demonstration purposes, this isn't my trade signal).
The first one gives me accumulated positive bars with a two-bar cushion (the within 2 bars added), once the cycle is broken it returns to zero.
The second chart with the modified 11th line ("else barUpCount[1]") you can see below it keeps accumulating and never returns to zero.
What I've been trying to do over the last few days unsuccessfully, is find whereby the total amount of signals in any given time spell, say one hour (see below 10-minute bars).
BAR 1 = 1 Result = 1
BAR 2 = 0 Result = 1
BAR 3 = 1 Result = 2
BAR 4 = 1 Result = 3
BAR 5 = 0 Result = 3
BAR 6 = 0 Result = 3
BAR 7 = 0 Result = 3
BAR 8 = 0 Result = 3
BAR 9 = 0 Result = 3
BAR 10 = 0 Result = 0
Then returning to zero and then restart the cycle, if no new signal occurs on the 6th bar after one hour having elapsed.
#1st CODE#
declare lower;
declare once_per_bar;
def zeroLine = 10;
plot pZeroLine = zeroLine;
pZeroLine.SetDefaultColor(Color.RED);
def upLine = 3;
plot pUpLine = upLine;
pUpLine.SetDefaultColor(Color.GREEN);
def Condition = (close is greater than reference VWAP()."VWAP" and high is not equal to low and close is greater than open and close is greater than close from 1 bars ago) within 2 bars;
def Conbar = Condition [0];
def barUpCount = CompoundValue (1, if Conbar then barUpCount[1] + 1 else 0, 0);
plot pBarUpCount = if barUpCount > 0 then barUpCount else 0;
pBarUpCount.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
pBarUpCount.AssignValueColor(Color.GREEN);
(#2nd CODE changed 11th line#)
def barUpCount = CompoundValue (1, if Conbar then barUpCount[1] + 1 else barUpCount[1], 0);
Anyone that can help? it would be much appreciated.
Thanking you in advance.
Jean-Claude
I found this code (see below) here https://usethinkscript.com/threads/consecutive-bar-count-indicator-for-thinkorswim.324/ and modified it to suit my purpose and it works really well as you can see in the photos below (the "def Condition" is only for demonstration purposes, this isn't my trade signal).
The first one gives me accumulated positive bars with a two-bar cushion (the within 2 bars added), once the cycle is broken it returns to zero.
The second chart with the modified 11th line ("else barUpCount[1]") you can see below it keeps accumulating and never returns to zero.
What I've been trying to do over the last few days unsuccessfully, is find whereby the total amount of signals in any given time spell, say one hour (see below 10-minute bars).
BAR 1 = 1 Result = 1
BAR 2 = 0 Result = 1
BAR 3 = 1 Result = 2
BAR 4 = 1 Result = 3
BAR 5 = 0 Result = 3
BAR 6 = 0 Result = 3
BAR 7 = 0 Result = 3
BAR 8 = 0 Result = 3
BAR 9 = 0 Result = 3
BAR 10 = 0 Result = 0
Then returning to zero and then restart the cycle, if no new signal occurs on the 6th bar after one hour having elapsed.
#1st CODE#
declare lower;
declare once_per_bar;
def zeroLine = 10;
plot pZeroLine = zeroLine;
pZeroLine.SetDefaultColor(Color.RED);
def upLine = 3;
plot pUpLine = upLine;
pUpLine.SetDefaultColor(Color.GREEN);
def Condition = (close is greater than reference VWAP()."VWAP" and high is not equal to low and close is greater than open and close is greater than close from 1 bars ago) within 2 bars;
def Conbar = Condition [0];
def barUpCount = CompoundValue (1, if Conbar then barUpCount[1] + 1 else 0, 0);
plot pBarUpCount = if barUpCount > 0 then barUpCount else 0;
pBarUpCount.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
pBarUpCount.AssignValueColor(Color.GREEN);
(#2nd CODE changed 11th line#)
def barUpCount = CompoundValue (1, if Conbar then barUpCount[1] + 1 else barUpCount[1], 0);
Anyone that can help? it would be much appreciated.
Thanking you in advance.
Jean-Claude
Last edited by a moderator: