3 Types of Gaps

Trigun1127

Member
Hey guys I've seen multiple really good gap scripts but are unable to modify them myself. I have three types of gaps that I look for but if its too much work there's one I need in particular that should be easy to script.




I need the gap script to create a cloud where when price enters the gap the cloud closes. I'm looking at gaps between each bar or three bars consecutive bars. I primarily work on the 5 minute time frame, on futures /MES - RTH w/ no Extended hours on.

1. First gap variation are open-close/ Close - Open gaps (really need this one)

EX: On bull bars: if the second bars open is greater than the first bars Close.
And vice versa for bear bars which would be the second bars open is less than the first bars close.

2. Tail gaps: For Bulls -when there are three bars the first bars high must be less than the third bars low and vice versa
For Bears the first bars low must be greater than the third bars high

These tail gaps take priority over normal gaps when the script needs to choose which to use. If the tail gap does get filled It can turn that cloud off and leave only the normal gap cloud (normal gaps are the last variation)

3. Normal gaps: in between three bars the first bars close is less than the third bars open
vice versa for bear bars the first bars close is greater than the third bars open.

Attached below are pictures of these types of gaps

 
Solution
@Trigun1127 Biggest issue here is the amount of unique plot and addcloud statements that would need to be coded nevermind that each cloud takes two plots.

Without arrays, this is almost impossible.

Best I can do is a modified script I wrote for another user. Modified it to plot what would be the upper edge of the clouds for bullish price movement and the lower edge of clouds for bearish price movement.

As you can see quite a few plots are generated.
" "

You will have to uncheck 'Fit Studies' in order to view in expansion area.

Ruby:
######################################################################################
#Definition of Signal. ###############################################################...
@Trigun1127 Biggest issue here is the amount of unique plot and addcloud statements that would need to be coded nevermind that each cloud takes two plots.

Without arrays, this is almost impossible.

Best I can do is a modified script I wrote for another user. Modified it to plot what would be the upper edge of the clouds for bullish price movement and the lower edge of clouds for bearish price movement.

As you can see quite a few plots are generated.
" "

You will have to uncheck 'Fit Studies' in order to view in expansion area.

Ruby:
######################################################################################
#Definition of Signal. ###############################################################
######################################################################################
input Number_Of_Days = 2;
def CurrentAgg = GetAggregationPeriod();
def agg = AggregationPeriod.DAY;
def LastDay = IsNaN(close(period = agg)[-Number_Of_Days]);
def SameDay = GetDay() == GetDay()[1];

def Gap1Up = open > close[1];
def Gap1Dn = open < close[1];

def TailGapUp = 0;#low > high[2];
def TailGapDn = 0;#high < low[2];

def Gap3Up = 0;#open > close[2];
def Gap3Dn = 0;#open < close[2];
######################################################################################
#Defintions of Support Levels.########################################################
######################################################################################
plot SupportLevel;
if CurrentAgg >= AggregationPeriod.DAY {
SupportLevel = if Gap1Up then close[1] else if TailGapUp then close[1] else if Gap3Up then close[1] else Double.NaN;
}else{
SupportLevel = if Gap1Up and LastDay and SameDay then close[1] else if TailGapUp and LastDay and SameDay then close[1] else if Gap3Up and LastDay and SameDay then close[1] else Double.NaN;}

SupportLevel.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
SupportLevel.Hide();

def SLine0;
def SLine1;
def SLine2;
def SLine3;
def SLine4;
def SLine5;
def SLine6;
def SLine7;
def SLine8;
def SLine9;
def SLine10;
def SLine11;
def SLine12;
def SLine13;
def SLine14;
def SLine15;
def SLine16;
def SLine17;
def SLine18;
def SLine19;
def SLine20;

def SLineCount;
if BarNumber()==1 { SLineCount = 0;
#}else if SecondsTillTime(0000) == 0 { SLineCount = 0; 
}else if (IsNaN(SupportLevel) and SLine0[1]<>0 and low<=SLine0[1]) { SLineCount=20;
}else if (IsNaN(SupportLevel) and SLine1[1]<>0 and low<=SLine1[1]) { SLineCount=0;
}else if (IsNaN(SupportLevel) and SLine2[1]<>0 and low<=SLine2[1]) { SLineCount=1;
}else if (IsNaN(SupportLevel) and SLine3[1]<>0 and low<=SLine3[1]) { SLineCount=2;
}else if (IsNaN(SupportLevel) and SLine4[1]<>0 and low<=SLine4[1]) { SLineCount=3;
}else if (IsNaN(SupportLevel) and SLine5[1]<>0 and low<=SLine5[1]) { SLineCount=4;
}else if (IsNaN(SupportLevel) and SLine6[1]<>0 and low<=SLine6[1]) { SLineCount=5;
}else if (IsNaN(SupportLevel) and SLine7[1]<>0 and low<=SLine7[1]) { SLineCount=6;
}else if (IsNaN(SupportLevel) and SLine8[1]<>0 and low<=SLine8[1]) { SLineCount=7;
}else if (IsNaN(SupportLevel) and SLine9[1]<>0 and low<=SLine9[1]) { SLineCount=8;
}else if (IsNaN(SupportLevel) and SLine10[1]<>0 and low<=SLine10[1]) { SLineCount=9;
}else if (IsNaN(SupportLevel) and SLine11[1]<>0 and low<=SLine11[1]) { SLineCount=10;
}else if (IsNaN(SupportLevel) and SLine12[1]<>0 and low<=SLine12[1]) { SLineCount=11;
}else if (IsNaN(SupportLevel) and SLine13[1]<>0 and low<=SLine13[1]) { SLineCount=12;
}else if (IsNaN(SupportLevel) and SLine14[1]<>0 and low<=SLine14[1]) { SLineCount=13;
}else if (IsNaN(SupportLevel) and SLine15[1]<>0 and low<=SLine15[1]) { SLineCount=14;
}else if (IsNaN(SupportLevel) and SLine16[1]<>0 and low<=SLine16[1]) { SLineCount=15;
}else if (IsNaN(SupportLevel) and SLine17[1]<>0 and low<=SLine17[1]) { SLineCount=16;
}else if (IsNaN(SupportLevel) and SLine18[1]<>0 and low<=SLine18[1]) { SLineCount=17;
}else if (IsNaN(SupportLevel) and SLine19[1]<>0 and low<=SLine19[1]) { SLineCount=18;
}else if (IsNaN(SupportLevel) and SLine20[1]<>0 and low<=SLine20[1]) { SLineCount=19;

}else if (!IsNaN(SupportLevel) and SLine0[1]<>0 and low<=SLine0[1]) { SLineCount=0;
}else if (!IsNaN(SupportLevel) and SLine1[1]<>0 and low<=SLine1[1]) { SLineCount=1;
}else if (!IsNaN(SupportLevel) and SLine2[1]<>0 and low<=SLine2[1]) { SLineCount=2;
}else if (!IsNaN(SupportLevel) and SLine3[1]<>0 and low<=SLine3[1]) { SLineCount=3;
}else if (!IsNaN(SupportLevel) and SLine4[1]<>0 and low<=SLine4[1]) { SLineCount=4;
}else if (!IsNaN(SupportLevel) and SLine5[1]<>0 and low<=SLine5[1]) { SLineCount=5;
}else if (!IsNaN(SupportLevel) and SLine6[1]<>0 and low<=SLine6[1]) { SLineCount=6;
}else if (!IsNaN(SupportLevel) and SLine7[1]<>0 and low<=SLine7[1]) { SLineCount=7;
}else if (!IsNaN(SupportLevel) and SLine8[1]<>0 and low<=SLine8[1]) { SLineCount=8;
}else if (!IsNaN(SupportLevel) and SLine9[1]<>0 and low<=SLine9[1]) { SLineCount=9;
}else if (!IsNaN(SupportLevel) and SLine10[1]<>0 and low<=SLine10[1]) { SLineCount=10;
}else if (!IsNaN(SupportLevel) and SLine11[1]<>0 and low<=SLine11[1]) { SLineCount=11;
}else if (!IsNaN(SupportLevel) and SLine12[1]<>0 and low<=SLine12[1]) { SLineCount=12;
}else if (!IsNaN(SupportLevel) and SLine13[1]<>0 and low<=SLine13[1]) { SLineCount=13;
}else if (!IsNaN(SupportLevel) and SLine14[1]<>0 and low<=SLine14[1]) { SLineCount=14;
}else if (!IsNaN(SupportLevel) and SLine15[1]<>0 and low<=SLine15[1]) { SLineCount=15;
}else if (!IsNaN(SupportLevel) and SLine16[1]<>0 and low<=SLine16[1]) { SLineCount=16;
}else if (!IsNaN(SupportLevel) and SLine17[1]<>0 and low<=SLine17[1]) { SLineCount=17;
}else if (!IsNaN(SupportLevel) and SLine18[1]<>0 and low<=SLine18[1]) { SLineCount=18;
}else if (!IsNaN(SupportLevel) and SLine19[1]<>0 and low<=SLine19[1]) { SLineCount=19;
}else if (!IsNaN(SupportLevel) and SLine20[1]<>0 and low<=SLine20[1]) { SLineCount=20;
}else if (!IsNaN(SupportLevel)) and SLineCount[1]!=20 { SLineCount = SLineCount[1] + 1;
}else if (!IsNaN(SupportLevel)) and SLineCount[1]==20 { SLineCount = 0;
} else {
    SLineCount = SLineCount[1];
}

#green candles
######################################################################################
#Plots of Support Levels. ############################################################
######################################################################################
SLine0 = if !IsNaN(SupportLevel) and SLineCount == 0 then SupportLevel else if IsNaN(close) then SLine0[1] else if !IsNaN(SLine0[1]) and low <= SLine0[1] then 0 else SLine0[1];
plot SLineP0 = if SLine0 > 0 then SLine0 else Double.NaN;
SLineP0.SetStyle(Curve.POINTS);
SLineP0.SetDefaultColor(Color.LIGHT_GREEN);
SLineP0.SetLineWeight(1);
SLineP0.HideBubble();
#----------------------------------------------------------------------------------
SLine1 = if !IsNaN(SupportLevel) and SLineCount == 1 then SupportLevel else if IsNaN(close) then SLine1[1] else if !IsNaN(SLine1[1]) and low <= SLine1[1] then 0 else SLine1[1];
plot SLineP1 = if SLine1 > 0 then SLine1 else Double.NaN;
SLineP1.SetStyle(Curve.POINTS);
SLineP1.SetDefaultColor(Color.LIGHT_GREEN);
SLineP1.SetLineWeight(1);
SLineP1.HideBubble();
#----------------------------------------------------------------------------------
SLine2 = if !IsNaN(SupportLevel) and SLineCount == 2 then SupportLevel else if IsNaN(close) then SLine2[1] else if !IsNaN(SLine2[1]) and low <= SLine2[1] then 0 else SLine2[1];
plot SLineP2 = if SLine2 > 0 then SLine2 else Double.NaN;
SLineP2.SetStyle(Curve.POINTS);
SLineP2.SetDefaultColor(Color.LIGHT_GREEN);
SLineP2.SetLineWeight(1);
SLineP2.HideBubble();
#----------------------------------------------------------------------------------
SLine3 = if !IsNaN(SupportLevel) and SLineCount == 3 then SupportLevel else if IsNaN(close) then SLine3[1] else if !IsNaN(SLine3[1]) and low <= SLine3[1] then 0 else SLine3[1];
plot SLineP3 = if SLine3 > 0 then SLine3 else Double.NaN;
SLineP3.SetStyle(Curve.POINTS);
SLineP3.SetDefaultColor(Color.LIGHT_GREEN);
SLineP3.SetLineWeight(1);
SLineP3.HideBubble();
#----------------------------------------------------------------------------------
SLine4 = if !IsNaN(SupportLevel) and SLineCount == 4 then SupportLevel else if IsNaN(close) then SLine4[1] else if !IsNaN(SLine4[1]) and low <= SLine4[1] then 0 else SLine4[1];
plot SLineP4 = if SLine4 > 0 then SLine4 else Double.NaN;
SLineP4.SetStyle(Curve.POINTS);
SLineP4.SetDefaultColor(Color.LIGHT_GREEN);
SLineP4.SetLineWeight(1);
SLineP4.HideBubble();
#----------------------------------------------------------------------------------
SLine5 = if !IsNaN(SupportLevel) and SLineCount == 5 then SupportLevel else if IsNaN(close) then SLine5[1] else if !IsNaN(SLine5[1]) and low <= SLine5[1] then 0 else SLine5[1];
plot SLineP5 = if SLine5 > 0 then SLine5 else Double.NaN;
SLineP5.SetStyle(Curve.POINTS);
SLineP5.SetDefaultColor(Color.LIGHT_GREEN);
SLineP5.SetLineWeight(1);
SLineP5.HideBubble();
#----------------------------------------------------------------------------------
SLine6 = if !IsNaN(SupportLevel) and SLineCount == 6 then SupportLevel else if IsNaN(close) then SLine6[1] else if !IsNaN(SLine6[1]) and low <= SLine6[1] then 0 else SLine6[1];
plot SLineP6 = if SLine6 > 0 then SLine6 else Double.NaN;
SLineP6.SetStyle(Curve.POINTS);
SLineP6.SetDefaultColor(Color.LIGHT_GREEN);
SLineP6.SetLineWeight(1);
SLineP6.HideBubble();
#----------------------------------------------------------------------------------
SLine7 = if !IsNaN(SupportLevel) and SLineCount == 7 then SupportLevel else if IsNaN(close) then SLine7[1] else if !IsNaN(SLine7[1]) and low <= SLine7[1] then 0 else SLine7[1];
plot SLineP7 = if SLine7 > 0 then SLine7 else Double.NaN;
SLineP7.SetStyle(Curve.POINTS);
SLineP7.SetDefaultColor(Color.LIGHT_GREEN);
SLineP7.SetLineWeight(1);
SLineP7.HideBubble();
#----------------------------------------------------------------------------------
SLine8 = if !IsNaN(SupportLevel) and SLineCount == 8 then SupportLevel else if IsNaN(close) then SLine8[1] else if !IsNaN(SLine8[1]) and low <= SLine8[1] then 0 else SLine8[1];
plot SLineP8 = if SLine8 > 0 then SLine8 else Double.NaN;
SLineP8.SetStyle(Curve.POINTS);
SLineP8.SetDefaultColor(Color.LIGHT_GREEN);
SLineP8.SetLineWeight(1);
SLineP8.HideBubble();
#----------------------------------------------------------------------------------
SLine9 = if !IsNaN(SupportLevel) and SLineCount == 9 then SupportLevel else if IsNaN(close) then SLine9[1] else if !IsNaN(SLine9[1]) and low <= SLine9[1] then 0 else SLine9[1];
plot SLineP9 = if SLine9 > 0 then SLine9 else Double.NaN;
SLineP9.SetStyle(Curve.POINTS);
SLineP9.SetDefaultColor(Color.LIGHT_GREEN);
SLineP9.SetLineWeight(1);
SLineP9.HideBubble();
#----------------------------------------------------------------------------------
SLine10 = if !IsNaN(SupportLevel) and SLineCount == 10 then SupportLevel else if IsNaN(close) then SLine10[1] else if !IsNaN(SLine10[1]) and low <= SLine10[1] then 0 else SLine10[1];
plot SLineP10 = if SLine10 > 0 then SLine10 else Double.NaN;
SLineP10.SetStyle(Curve.POINTS);
SLineP10.SetDefaultColor(Color.LIGHT_GREEN);
SLineP10.SetLineWeight(1);
SLineP10.HideBubble();
#----------------------------------------------------------------------------------
SLine11 = if !IsNaN(SupportLevel) and SLineCount == 11 then SupportLevel else if IsNaN(close) then SLine11[1] else if !IsNaN(SLine11[1]) and low <= SLine11[1] then 0 else SLine11[1];
plot SLineP11 = if SLine11 > 0 then SLine11 else Double.NaN;
SLineP11.SetStyle(Curve.POINTS);
SLineP11.SetDefaultColor(Color.LIGHT_GREEN);
SLineP11.SetLineWeight(1);
SLineP11.HideBubble();
#----------------------------------------------------------------------------------
SLine12 = if !IsNaN(SupportLevel) and SLineCount == 12 then SupportLevel else if IsNaN(close) then SLine12[1] else if !IsNaN(SLine12[1]) and low <= SLine12[1] then 0 else SLine12[1];
plot SLineP12 = if SLine12 > 0 then SLine12 else Double.NaN;
SLineP12.SetStyle(Curve.POINTS);
SLineP12.SetDefaultColor(Color.LIGHT_GREEN);
SLineP12.SetLineWeight(1);
SLineP12.HideBubble();
#----------------------------------------------------------------------------------
SLine13 = if !IsNaN(SupportLevel) and SLineCount == 13 then SupportLevel else if IsNaN(close) then SLine13[1] else if !IsNaN(SLine13[1]) and low <= SLine13[1] then 0 else SLine13[1];
plot SLineP13 = if SLine13 > 0 then SLine13 else Double.NaN;
SLineP13.SetStyle(Curve.POINTS);
SLineP13.SetDefaultColor(Color.LIGHT_GREEN);
SLineP13.SetLineWeight(1);
SLineP13.HideBubble();
#----------------------------------------------------------------------------------
SLine14 = if !IsNaN(SupportLevel) and SLineCount == 14 then SupportLevel else if IsNaN(close) then SLine14[1] else if !IsNaN(SLine14[1]) and low <= SLine14[1] then 0 else SLine14[1];
plot SLineP14 = if SLine14 > 0 then SLine14 else Double.NaN;
SLineP14.SetStyle(Curve.POINTS);
SLineP14.SetDefaultColor(Color.LIGHT_GREEN);
SLineP14.SetLineWeight(1);
SLineP14.HideBubble();
#----------------------------------------------------------------------------------
SLine15 = if !IsNaN(SupportLevel) and SLineCount == 15 then SupportLevel else if IsNaN(close) then SLine15[1] else if !IsNaN(SLine15[1]) and low <= SLine15[1] then 0 else SLine15[1];
plot SLineP15 = if SLine15 > 0 then SLine15 else Double.NaN;
SLineP15.SetStyle(Curve.POINTS);
SLineP15.SetDefaultColor(Color.LIGHT_GREEN);
SLineP15.SetLineWeight(1);
SLineP15.HideBubble();
#----------------------------------------------------------------------------------
SLine16 = if !IsNaN(SupportLevel) and SLineCount == 16 then SupportLevel else if IsNaN(close) then SLine16[1] else if !IsNaN(SLine16[1]) and low <= SLine16[1] then 0 else SLine16[1];
plot SLineP16 = if SLine16 > 0 then SLine16 else Double.NaN;
SLineP16.SetStyle(Curve.POINTS);
SLineP16.SetDefaultColor(Color.LIGHT_GREEN);
SLineP16.SetLineWeight(1);
SLineP16.HideBubble();
#----------------------------------------------------------------------------------
SLine17 = if !IsNaN(SupportLevel) and SLineCount == 17 then SupportLevel else if IsNaN(close) then SLine17[1] else if !IsNaN(SLine17[1]) and low <= SLine17[1] then 0 else SLine17[1];
plot SLineP17 = if SLine17 > 0 then SLine17 else Double.NaN;
SLineP17.SetStyle(Curve.POINTS);
SLineP17.SetDefaultColor(Color.LIGHT_GREEN);
SLineP17.SetLineWeight(1);
SLineP17.HideBubble();
#----------------------------------------------------------------------------------
SLine18 = if !IsNaN(SupportLevel) and SLineCount == 18 then SupportLevel else if IsNaN(close) then SLine18[1] else if !IsNaN(SLine18[1]) and low < SLine18[1] then 0 else SLine18[1];
plot SLineP18 = if SLine18 > 0 then SLine18 else Double.NaN;
SLineP18.SetStyle(Curve.POINTS);
SLineP18.SetDefaultColor(Color.LIGHT_GREEN);
SLineP18.SetLineWeight(1);
SLineP18.HideBubble();
#----------------------------------------------------------------------------------
SLine19 = if !IsNaN(SupportLevel) and SLineCount == 19 then SupportLevel else if IsNaN(close) then SLine19[1] else if !IsNaN(SLine19[1]) and low <= SLine19[1] then 0 else SLine19[1];
plot SLineP19 = if SLine19 > 0 then SLine19 else Double.NaN;
SLineP19.SetStyle(Curve.POINTS);
SLineP19.SetDefaultColor(Color.LIGHT_GREEN);
SLineP19.SetLineWeight(1);
SLineP19.HideBubble();
#----------------------------------------------------------------------------------
SLine20 = if !IsNaN(SupportLevel) and SLineCount == 20 then SupportLevel else if IsNaN(close) then SLine20[1] else if !IsNaN(SLine20[1]) and low <= SLine20[1] then 0 else SLine20[1];
plot SLineP20 = if SLine20 > 0 then SLine20 else Double.NaN;
SLineP20.SetStyle(Curve.POINTS);
SLineP20.SetDefaultColor(Color.CYAN);
SLineP20.SetLineWeight(1);
SLineP20.HideBubble();
#----------------------------------------------------------------------------------
#####################################################################################
########################################################################################


#red candles
######################################################################################
#Definitons of Resistance Levels.#####################################################
######################################################################################
plot ResistanceLevel;
if CurrentAgg >= AggregationPeriod.DAY {
ResistanceLevel = if Gap1Dn then close[1] else if TailGapDn then close[1] else if Gap3Dn then close[1] else Double.NaN;
}else{
ResistanceLevel = if Gap1Dn and LastDay and SameDay then close[1] else if TailGapDn and LastDay and SameDay then close[1] else if Gap3Dn and LastDay and SameDay then close[1] else Double.NaN;}

ResistanceLevel.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
ResistanceLevel.Hide();

def RLine0;
def RLine1;
def RLine2;
def RLine3;
def RLine4;
def RLine5;
def RLine6;
def RLine7;
def RLine8;
def RLine9;
def RLine10;
def RLine11;
def RLine12;
def RLine13;
def RLine14;
def RLine15;
def RLine16;
def RLine17;
def RLine18;
def RLine19;
def RLine20;

def RLineCount;
if BarNumber()==1 { RLineCount = 0;
#}else if SecondsTillTime(0000) == 0 { RLineCount = 0; 
}else if (IsNaN(ResistanceLevel) and RLine0[1]<>0 and high>=RLine0[1]) { RLineCount=20;
}else if (IsNaN(ResistanceLevel) and RLine1[1]<>0 and high>=RLine1[1]) { RLineCount=0;
}else if (IsNaN(ResistanceLevel) and RLine2[1]<>0 and high>=RLine2[1]) { RLineCount=1;
}else if (IsNaN(ResistanceLevel) and RLine3[1]<>0 and high>=RLine3[1]) { RLineCount=2;
}else if (IsNaN(ResistanceLevel) and RLine4[1]<>0 and high>=RLine4[1]) { RLineCount=3;
}else if (IsNaN(ResistanceLevel) and RLine5[1]<>0 and high>=RLine5[1]) { RLineCount=4;
}else if (IsNaN(ResistanceLevel) and RLine6[1]<>0 and high>=RLine6[1]) { RLineCount=5;
}else if (IsNaN(ResistanceLevel) and RLine7[1]<>0 and high>=RLine7[1]) { RLineCount=6;
}else if (IsNaN(ResistanceLevel) and RLine8[1]<>0 and high>=RLine8[1]) { RLineCount=7;
}else if (IsNaN(ResistanceLevel) and RLine9[1]<>0 and high>=RLine9[1]) { RLineCount=8;
}else if (IsNaN(ResistanceLevel) and RLine10[1]<>0 and high>=RLine10[1]) { RLineCount=9;
}else if (IsNaN(ResistanceLevel) and RLine11[1]<>0 and high>=RLine11[1]) { RLineCount=10;
}else if (IsNaN(ResistanceLevel) and RLine12[1]<>0 and high>=RLine12[1]) { RLineCount=11;
}else if (IsNaN(ResistanceLevel) and RLine13[1]<>0 and high>=RLine13[1]) { RLineCount=12;
}else if (IsNaN(ResistanceLevel) and RLine14[1]<>0 and high>=RLine14[1]) { RLineCount=13;
}else if (IsNaN(ResistanceLevel) and RLine15[1]<>0 and high>=RLine15[1]) { RLineCount=14;
}else if (IsNaN(ResistanceLevel) and RLine16[1]<>0 and high>=RLine16[1]) { RLineCount=15;
}else if (IsNaN(ResistanceLevel) and RLine17[1]<>0 and high>=RLine17[1]) { RLineCount=16;
}else if (IsNaN(ResistanceLevel) and RLine18[1]<>0 and high>=RLine18[1]) { RLineCount=17;
}else if (IsNaN(ResistanceLevel) and RLine19[1]<>0 and high>=RLine19[1]) { RLineCount=18;
}else if (IsNaN(ResistanceLevel) and RLine20[1]<>0 and high>=RLine20[1]) { RLineCount=19;

}else if (!IsNaN(ResistanceLevel) and RLine0[1]<>0 and high>=RLine0[1]) { RLineCount=0;
}else if (!IsNaN(ResistanceLevel) and RLine1[1]<>0 and high>=RLine1[1]) { RLineCount=1;
}else if (!IsNaN(ResistanceLevel) and RLine2[1]<>0 and high>=RLine2[1]) { RLineCount=2;
}else if (!IsNaN(ResistanceLevel) and RLine3[1]<>0 and high>=RLine3[1]) { RLineCount=3;
}else if (!IsNaN(ResistanceLevel) and RLine4[1]<>0 and high>=RLine4[1]) { RLineCount=4;
}else if (!IsNaN(ResistanceLevel) and RLine5[1]<>0 and high>=RLine5[1]) { RLineCount=5;
}else if (!IsNaN(ResistanceLevel) and RLine6[1]<>0 and high>=RLine6[1]) { RLineCount=6;
}else if (!IsNaN(ResistanceLevel) and RLine7[1]<>0 and high>=RLine7[1]) { RLineCount=7;
}else if (!IsNaN(ResistanceLevel) and RLine8[1]<>0 and high>=RLine8[1]) { RLineCount=8;
}else if (!IsNaN(ResistanceLevel) and RLine9[1]<>0 and high>=RLine9[1]) { RLineCount=9;
}else if (!IsNaN(ResistanceLevel) and RLine10[1]<>0 and high>=RLine10[1]) { RLineCount=10;
}else if (!IsNaN(ResistanceLevel) and RLine11[1]<>0 and high>=RLine11[1]) { RLineCount=11;
}else if (!IsNaN(ResistanceLevel) and RLine12[1]<>0 and high>=RLine12[1]) { RLineCount=12;
}else if (!IsNaN(ResistanceLevel) and RLine13[1]<>0 and high>=RLine13[1]) { RLineCount=13;
}else if (!IsNaN(ResistanceLevel) and RLine14[1]<>0 and high>=RLine14[1]) { RLineCount=14;
}else if (!IsNaN(ResistanceLevel) and RLine15[1]<>0 and high>=RLine15[1]) { RLineCount=15;
}else if (!IsNaN(ResistanceLevel) and RLine16[1]<>0 and high>=RLine16[1]) { RLineCount=16;
}else if (!IsNaN(ResistanceLevel) and RLine17[1]<>0 and high>=RLine17[1]) { RLineCount=17;
}else if (!IsNaN(ResistanceLevel) and RLine18[1]<>0 and high>=RLine18[1]) { RLineCount=18;
}else if (!IsNaN(ResistanceLevel) and RLine19[1]<>0 and high>=RLine19[1]) { RLineCount=19;
}else if (!IsNaN(ResistanceLevel) and RLine20[1]<>0 and high>=RLine20[1]) { RLineCount=20;
}else if (!IsNaN(ResistanceLevel)) and RLineCount[1]!=20 { RLineCount = RLineCount[1] + 1;
}else if (!IsNaN(ResistanceLevel)) and RLineCount[1]==20 { RLineCount = 0;
} else {
    RLineCount = RLineCount[1];
}
#addchartbubble(yes,high,RLineCount,color.white);
######################################################################################
#Plots of Resistance Levels.##########################################################
######################################################################################
RLine0 = if !IsNaN(ResistanceLevel) and RLineCount == 0 then ResistanceLevel else if IsNaN(close) then RLine0[1] else if !IsNaN(RLine0[1]) and high >= RLine0[1] then 0 else RLine0[1];
plot RLineP0 = if RLine0 > 0 then RLine0 else Double.NaN;
RLineP0.SetStyle(Curve.POINTS);
RLineP0.SetDefaultColor(Color.LIGHT_RED);
RLineP0.SetLineWeight(1);
RLineP0.HideBubble();
#----------------------------------------------------------------------------------
RLine1 = if !IsNaN(ResistanceLevel) and RLineCount == 1 then ResistanceLevel else if IsNaN(close) then RLine1[1] else if !IsNaN(RLine1[1]) and high >= RLine1[1] then 0 else RLine1[1];
plot RLineP1 = if RLine1[-1] > 0 then RLine1[-1] else Double.NaN;
RLineP1.SetStyle(Curve.POINTS);
RLineP1.SetDefaultColor(Color.LIGHT_RED);
RLineP1.SetLineWeight(1);
RLineP1.HideBubble();
#----------------------------------------------------------------------------------
RLine2 = if !IsNaN(ResistanceLevel) and RLineCount == 2 then ResistanceLevel else if IsNaN(close) then RLine2[1] else if !IsNaN(RLine2[1]) and high >= RLine2[1] then 0 else RLine2[1];
plot RLineP2 = if RLine2 > 0 then RLine2 else Double.NaN;
RLineP2.SetStyle(Curve.POINTS);
RLineP2.SetDefaultColor(Color.LIGHT_RED);
RLineP2.SetLineWeight(1);
RLineP2.HideBubble();
#----------------------------------------------------------------------------------
RLine3 = if !IsNaN(ResistanceLevel) and RLineCount == 3 then ResistanceLevel else if IsNaN(close) then RLine3[1] else if !IsNaN(RLine3[1]) and high >= RLine3[1] then 0 else RLine3[1];
plot RLineP3 = if RLine3 > 0 then RLine3 else Double.NaN;
RLineP3.SetStyle(Curve.POINTS);
RLineP3.SetDefaultColor(Color.LIGHT_RED);
RLineP3.SetLineWeight(1);
RLineP3.HideBubble();
#----------------------------------------------------------------------------------
RLine4 = if !IsNaN(ResistanceLevel) and RLineCount == 4 then ResistanceLevel else if IsNaN(close) then RLine4[1] else if !IsNaN(RLine4[1]) and high >= RLine4[1] then 0 else RLine4[1];
plot RLineP4 = if RLine4 > 0 then RLine4 else Double.NaN;
RLineP4.SetStyle(Curve.POINTS);
RLineP4.SetDefaultColor(Color.LIGHT_RED);
RLineP4.SetLineWeight(1);
RLineP4.HideBubble();
#----------------------------------------------------------------------------------
RLine5 = if !IsNaN(ResistanceLevel) and RLineCount == 5 then ResistanceLevel else if IsNaN(close) then RLine5[1] else if !IsNaN(RLine5[1]) and high >= RLine5[1] then 0 else RLine5[1];
plot RLineP5 = if RLine5 > 0 then RLine5 else Double.NaN;
RLineP5.SetStyle(Curve.POINTS);
RLineP5.SetDefaultColor(Color.LIGHT_RED);
RLineP5.SetLineWeight(1);
RLineP5.HideBubble();
#----------------------------------------------------------------------------------
RLine6 = if !IsNaN(ResistanceLevel) and RLineCount == 6 then ResistanceLevel else if IsNaN(close) then RLine6[1] else if !IsNaN(RLine6[1]) and high >= RLine6[1] then 0 else RLine6[1];
plot RLineP6 = if RLine6 > 0 then RLine6 else Double.NaN;
RLineP6.SetStyle(Curve.POINTS);
RLineP6.SetDefaultColor(Color.LIGHT_RED);
RLineP6.SetLineWeight(1);
RLineP6.HideBubble();
#----------------------------------------------------------------------------------
RLine7 = if !IsNaN(ResistanceLevel) and RLineCount == 7 then ResistanceLevel else if IsNaN(close) then RLine7[1] else if !IsNaN(RLine7[1]) and high >= RLine7[1] then 0 else RLine7[1];
plot RLineP7 = if RLine7 > 0 then RLine7 else Double.NaN;
RLineP7.SetStyle(Curve.POINTS);
RLineP7.SetDefaultColor(Color.LIGHT_RED);
RLineP7.SetLineWeight(1);
RLineP7.HideBubble();
#----------------------------------------------------------------------------------
RLine8 = if !IsNaN(ResistanceLevel) and RLineCount == 8 then ResistanceLevel else if IsNaN(close) then RLine8[1] else if !IsNaN(RLine8[1]) and high >= RLine8[1] then 0 else RLine8[1];
plot RLineP8 = if RLine8 > 0 then RLine8 else Double.NaN;
RLineP8.SetStyle(Curve.POINTS);
RLineP8.SetDefaultColor(Color.LIGHT_RED);
RLineP8.SetLineWeight(1);
RLineP8.HideBubble();
#----------------------------------------------------------------------------------
RLine9 = if !IsNaN(ResistanceLevel) and RLineCount == 9 then ResistanceLevel else if IsNaN(close) then RLine9[1] else if !IsNaN(RLine9[1]) and high >= RLine9[1] then 0 else RLine9[1];
plot RLineP9 = if RLine9 > 0 then RLine9 else Double.NaN;
RLineP9.SetStyle(Curve.POINTS);
RLineP9.SetDefaultColor(Color.LIGHT_RED);
RLineP9.SetLineWeight(1);
RLineP9.HideBubble();
#----------------------------------------------------------------------------------
RLine10 = if !IsNaN(ResistanceLevel) and RLineCount == 10 then ResistanceLevel else if IsNaN(close) then RLine10[1] else if !IsNaN(RLine10[1]) and high >= RLine10[1] then 0 else RLine10[1];
plot RLineP10 = if RLine10 > 0 then RLine10 else Double.NaN;
RLineP10.SetStyle(Curve.POINTS);
RLineP10.SetDefaultColor(Color.LIGHT_RED);
RLineP10.SetLineWeight(1);
RLineP10.HideBubble();
#----------------------------------------------------------------------------------
RLine11 = if !IsNaN(ResistanceLevel) and RLineCount == 11 then ResistanceLevel else if IsNaN(close) then RLine11[1] else if !IsNaN(RLine11[1]) and high >= RLine11[1] then 0 else RLine11[1];
plot RLineP11 = if RLine11 > 0 then RLine11 else Double.NaN;
RLineP11.SetStyle(Curve.POINTS);
RLineP11.SetDefaultColor(Color.LIGHT_RED);
RLineP11.SetLineWeight(1);
RLineP11.HideBubble();
#----------------------------------------------------------------------------------
RLine12 = if !IsNaN(ResistanceLevel) and RLineCount == 12 then ResistanceLevel else if IsNaN(close) then RLine12[1] else if !IsNaN(RLine12[1]) and high >= RLine12[1] then 0 else RLine12[1];
plot RLineP12 = if RLine12 > 0 then RLine12 else Double.NaN;
RLineP12.SetStyle(Curve.POINTS);
RLineP12.SetDefaultColor(Color.LIGHT_RED);
RLineP12.SetLineWeight(1);
RLineP12.HideBubble();
#----------------------------------------------------------------------------------
RLine13 = if !IsNaN(ResistanceLevel) and RLineCount == 13 then ResistanceLevel else if IsNaN(close) then RLine13[1] else if !IsNaN(RLine13[1]) and high >= RLine13[1] then 0 else RLine13[1];
plot RLineP13 = if RLine13 > 0 then RLine13 else Double.NaN;
RLineP13.SetStyle(Curve.POINTS);
RLineP13.SetDefaultColor(Color.LIGHT_RED);
RLineP13.SetLineWeight(1);
RLineP13.HideBubble();
#----------------------------------------------------------------------------------
RLine14 = if !IsNaN(ResistanceLevel) and RLineCount == 14 then ResistanceLevel else if IsNaN(close) then RLine14[1] else if !IsNaN(RLine14[1]) and high >= RLine14[1] then 0 else RLine14[1];
plot RLineP14 = if RLine14 > 0 then RLine14 else Double.NaN;
RLineP14.SetStyle(Curve.POINTS);
RLineP14.SetDefaultColor(Color.LIGHT_RED);
RLineP14.SetLineWeight(1);
RLineP14.HideBubble();
#----------------------------------------------------------------------------------
RLine15 = if !IsNaN(ResistanceLevel) and RLineCount == 15 then ResistanceLevel else if IsNaN(close) then RLine15[1] else if !IsNaN(RLine15[1]) and high >= RLine15[1] then 0 else RLine15[1];
plot RLineP15 = if RLine15 > 0 then RLine15 else Double.NaN;
RLineP15.SetStyle(Curve.POINTS);
RLineP15.SetDefaultColor(Color.LIGHT_RED);
RLineP15.SetLineWeight(1);
RLineP15.HideBubble();
#----------------------------------------------------------------------------------
RLine16 = if !IsNaN(ResistanceLevel) and RLineCount == 16 then ResistanceLevel else if IsNaN(close) then RLine16[1] else if !IsNaN(RLine16[1]) and high >= RLine16[1] then 0 else RLine16[1];
plot RLineP16 = if RLine16 > 0 then RLine16 else Double.NaN;
RLineP16.SetStyle(Curve.POINTS);
RLineP16.SetDefaultColor(Color.LIGHT_RED);
RLineP16.SetLineWeight(1);
RLineP16.HideBubble();
#----------------------------------------------------------------------------------
RLine17 = if !IsNaN(ResistanceLevel) and RLineCount == 17 then ResistanceLevel else if IsNaN(close) then RLine17[1] else if !IsNaN(RLine17[1]) and high >= RLine17[1] then 0 else RLine17[1];
plot RLineP17 = if RLine17 > 0 then RLine17 else Double.NaN;
RLineP17.SetStyle(Curve.POINTS);
RLineP17.SetDefaultColor(Color.LIGHT_RED);
RLineP17.SetLineWeight(1);
RLineP17.HideBubble();
#----------------------------------------------------------------------------------
RLine18 = if !IsNaN(ResistanceLevel) and RLineCount == 18 then ResistanceLevel else if IsNaN(close) then RLine18[1] else if !IsNaN(RLine18[1]) and high >= RLine18[1] then 0 else RLine18[1];
plot RLineP18 = if RLine18 > 0 then RLine18 else Double.NaN;
RLineP18.SetStyle(Curve.POINTS);
RLineP18.SetDefaultColor(Color.LIGHT_RED);
RLineP18.SetLineWeight(1);
RLineP18.HideBubble();
#----------------------------------------------------------------------------------
RLine19 = if !IsNaN(ResistanceLevel) and RLineCount == 19 then ResistanceLevel else if IsNaN(close) then RLine19[1] else if !IsNaN(RLine19[1]) and high >= RLine19[1] then 0 else RLine19[1];
plot RLineP19 = if RLine19 > 0 then RLine19 else Double.NaN;
RLineP19.SetStyle(Curve.POINTS);
RLineP19.SetDefaultColor(Color.LIGHT_RED);
RLineP19.SetLineWeight(1);
RLineP19.HideBubble();
#----------------------------------------------------------------------------------
RLine20 = if !IsNaN(ResistanceLevel) and RLineCount == 20 then ResistanceLevel else if IsNaN(close) then RLine20[1] else if !IsNaN(RLine20[1]) and high >= RLine20[1] then 0 else RLine20[1];
plot RLineP20 = if RLine20 > 0 then RLine20 else Double.NaN;
RLineP20.SetStyle(Curve.POINTS);
RLineP20.SetDefaultColor(Color.LIGHT_ORANGE);
RLineP20.SetLineWeight(1);
RLineP20.HideBubble();
#####################################################################################
#####################################################################################

#End of Code#
 
Last edited:
Solution
Thanks Svanoy for working with me on this! So here's a couple observations and perhaps suggestions?
Halcyonguy made an indicator that is very similar to what I need
you can see that code here.

Technically 70+% of the bars on the chart most likely will have some form of these gaps and therefore many many plots.
1. I think a Today only toggle function would be useful for clutter. Meanwhile past days can be toggled test lines.
1a. If the gap is filled no need to display where it ran into price to the right of it. ( it again would be nice to have as a test toggle so I can use it as a study to understand their interactions better.
2. The gaps don't need to be only between green bars or only between red bars. So it could be for instance the 1st candle is red with a high the second bar is a green bar and the third bar is a green bar with a low. The high of the first bar and the low of the third candle do not overlap therefore creating a gap and a stronger one then a normal gap.
3. That should apply for all gaps it can be any mixture of bars between 3 candles. any candle can be a gap with any combination of 3 candles
4. One really important thing needed is that each gaps color can be user defined. These gaps are in a hierarchy so I need to see at a glance which takes priority. If nothing else can be done i really would like the open/close gaps since they are the most important to me.

Take a look at these pictures for examples and note the following
1. How normal gaps and tail gaps interact
2. Note the color differences in priority (orange = open /close - Close/open gaps | Lighter color = tail gap green) Darker color = normal gap
3. How if tail gaps get filled body gaps can still remain.

 
@Trigun1127 For now, I removed the greenbar/redbar condition and only plotting open close gaps. Also added an input for number of days to show plots.

Setting a plot priority and color and then carrying that priority and color along with the plot and also doubling the plots in order to have clouds are all issues that may or may not be possible, will have to spend some time checking.
 
Instead of a cloud is it possible to use a rectangle/square which is found in the draw tools? The top left point could be plotted to the open of the third bar and the bottom right point could be plotted to the close of the first. That would just need to be extended to the right? Not sure if that’s a possibility.

another note for Close-Open Gaps - They remain filled until price closes the gap, so tails overlapping in front of close open gap does not count.
 
Last edited:
@Trigun1127 For now, I removed the greenbar/redbar condition and only plotting open close gaps. Also added an input for number of days to show plots.

Setting a plot priority and color and then carrying that priority and color along with the plot and also doubling the plots in order to have clouds are all issues that may or may not be possible, will have to spend some time checking.
Hey Svanoy could you edit the start time? It thinks there's a gap1up or gap1dn with the prior day. That's mainly because I have extended hours off. So it should only start looking for gap1up/gap1dn between the first and second bar then onward not the first bar and the prior day.
 
So still trying to figure this out you can see here what ive done but I cant get this to out put the bars where Gaps remain open.
Code:
[QUOTE]
#red candles
######################################################################################
#Definitons of Resistance Levels.#####################################################
######################################################################################
plot ResistanceLevel = if Gap1Dn and SameDay then open else if TailGapDn and SameDay then open else if Gap3Dn and SameDay then open else Double.NaN;
ResistanceLevel.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
ResistanceLevel.Hide();

def RLine0;
def RLine1;
def RLine2;
def RLine3;
def RLine4;
def RLine5;
def RLine6;
def RLine7;
def RLine8;
def RLine9;
def RLine10;
def RLine11;
def RLine12;
def RLine13;
def RLine14;
def RLine15;
def RLine16;
def RLine17;
def RLine18;
def RLine19;
def RLine20;

def RLineCount;
if BarNumber()==1 { RLineCount = 0;
#}else if SecondsTillTime(0000) == 0 { RLineCount = 0;
}else if (IsNaN(ResistanceLevel) and RLine0[1]<>0 and close>=RLine0[1]) { RLineCount=20;
}else if (IsNaN(ResistanceLevel) and RLine1[1]<>0 and close>=RLine1[1]) { RLineCount=0;
}else if (IsNaN(ResistanceLevel) and RLine2[1]<>0 and close>=RLine2[1]) { RLineCount=1;
}else if (IsNaN(ResistanceLevel) and RLine3[1]<>0 and close>=RLine3[1]) { RLineCount=2;
}else if (IsNaN(ResistanceLevel) and RLine4[1]<>0 and close>=RLine4[1]) { RLineCount=3;
}else if (IsNaN(ResistanceLevel) and RLine5[1]<>0 and close>=RLine5[1]) { RLineCount=4;
}else if (IsNaN(ResistanceLevel) and RLine6[1]<>0 and close>=RLine6[1]) { RLineCount=5;
}else if (IsNaN(ResistanceLevel) and RLine7[1]<>0 and close>=RLine7[1]) { RLineCount=6;
}else if (IsNaN(ResistanceLevel) and RLine8[1]<>0 and close>=RLine8[1]) { RLineCount=7;
}else if (IsNaN(ResistanceLevel) and RLine9[1]<>0 and close>=RLine9[1]) { RLineCount=8;
}else if (IsNaN(ResistanceLevel) and RLine10[1]<>0 and close>=RLine10[1]) { RLineCount=9;
}else if (IsNaN(ResistanceLevel) and RLine11[1]<>0 and close>=RLine11[1]) { RLineCount=10;
}else if (IsNaN(ResistanceLevel) and RLine12[1]<>0 and close>=RLine12[1]) { RLineCount=11;
}else if (IsNaN(ResistanceLevel) and RLine13[1]<>0 and close>=RLine13[1]) { RLineCount=12;
}else if (IsNaN(ResistanceLevel) and RLine14[1]<>0 and close>=RLine14[1]) { RLineCount=13;
}else if (IsNaN(ResistanceLevel) and RLine15[1]<>0 and close>=RLine15[1]) { RLineCount=14;
}else if (IsNaN(ResistanceLevel) and RLine16[1]<>0 and close>=RLine16[1]) { RLineCount=15;
}else if (IsNaN(ResistanceLevel) and RLine17[1]<>0 and close>=RLine17[1]) { RLineCount=16;
}else if (IsNaN(ResistanceLevel) and RLine18[1]<>0 and close>=RLine18[1]) { RLineCount=17;
}else if (IsNaN(ResistanceLevel) and RLine19[1]<>0 and close>=RLine19[1]) { RLineCount=18;
}else if (IsNaN(ResistanceLevel) and RLine20[1]<>0 and close>=RLine20[1]) { RLineCount=19;

}else if (!IsNaN(ResistanceLevel) and RLine0[1]<>0 and close>=RLine0[1]) { RLineCount=0;
}else if (!IsNaN(ResistanceLevel) and RLine1[1]<>0 and close>=RLine1[1]) { RLineCount=1;
}else if (!IsNaN(ResistanceLevel) and RLine2[1]<>0 and close>=RLine2[1]) { RLineCount=2;
}else if (!IsNaN(ResistanceLevel) and RLine3[1]<>0 and close>=RLine3[1]) { RLineCount=3;
}else if (!IsNaN(ResistanceLevel) and RLine4[1]<>0 and close>=RLine4[1]) { RLineCount=4;
}else if (!IsNaN(ResistanceLevel) and RLine5[1]<>0 and close>=RLine5[1]) { RLineCount=5;
}else if (!IsNaN(ResistanceLevel) and RLine6[1]<>0 and close>=RLine6[1]) { RLineCount=6;
}else if (!IsNaN(ResistanceLevel) and RLine7[1]<>0 and close>=RLine7[1]) { RLineCount=7;
}else if (!IsNaN(ResistanceLevel) and RLine8[1]<>0 and close>=RLine8[1]) { RLineCount=8;
}else if (!IsNaN(ResistanceLevel) and RLine9[1]<>0 and close>=RLine9[1]) { RLineCount=9;
}else if (!IsNaN(ResistanceLevel) and RLine10[1]<>0 and close>=RLine10[1]) { RLineCount=10;
}else if (!IsNaN(ResistanceLevel) and RLine11[1]<>0 and close>=RLine11[1]) { RLineCount=11;
}else if (!IsNaN(ResistanceLevel) and RLine12[1]<>0 and close>=RLine12[1]) { RLineCount=12;
}else if (!IsNaN(ResistanceLevel) and RLine13[1]<>0 and close>=RLine13[1]) { RLineCount=13;
}else if (!IsNaN(ResistanceLevel) and RLine14[1]<>0 and close>=RLine14[1]) { RLineCount=14;
}else if (!IsNaN(ResistanceLevel) and RLine15[1]<>0 and close>=RLine15[1]) { RLineCount=15;
}else if (!IsNaN(ResistanceLevel) and RLine16[1]<>0 and close>=RLine16[1]) { RLineCount=16;
}else if (!IsNaN(ResistanceLevel) and RLine17[1]<>0 and close>=RLine17[1]) { RLineCount=17;
}else if (!IsNaN(ResistanceLevel) and RLine18[1]<>0 and close>=RLine18[1]) { RLineCount=18;
}else if (!IsNaN(ResistanceLevel) and RLine19[1]<>0 and close>=RLine19[1]) { RLineCount=19;
}else if (!IsNaN(ResistanceLevel) and RLine20[1]<>0 and close>=RLine20[1]) { RLineCount=20;
}else if (!IsNaN(ResistanceLevel)) and RLineCount[1]!=20 { RLineCount = RLineCount[1] + 1;
}else if (!IsNaN(ResistanceLevel)) and RLineCount[1]==20 { RLineCount = 0;
} else {
    RLineCount = RLineCount[1];
}

######################################################################################
#Plots of Resistance Levels.##########################################################
######################################################################################
RLine0 = if !IsNaN(ResistanceLevel) and RLineCount == 0 then ResistanceLevel else if IsNaN(close) then RLine0[1] else if !IsNaN(RLine0[1]) and close >= RLine0[1] then 0 else RLine0[1];
plot RLineP0 = if RLine0 > 0 then RLine0 else Double.NaN;
RLineP0.SetStyle(Curve.POINTS);
RLineP0.SetDefaultColor(Color.LIGHT_RED);
RLineP0.SetLineWeight(1);
RLineP0.HideBubble();
#----------------------------------------------------------------------------------
RLine1 = if !IsNaN(ResistanceLevel) and RLineCount == 1 then ResistanceLevel else if IsNaN(close) then RLine1[1] else if !IsNaN(RLine1[1]) and close >= RLine1[1] then 0 else RLine1[1];
plot RLineP1 = if RLine1 > 0 then RLine1 else Double.NaN;
RLineP1.SetStyle(Curve.POINTS);
RLineP1.SetDefaultColor(Color.LIGHT_RED);
RLineP1.SetLineWeight(1);
RLineP1.HideBubble();
#----------------------------------------------------------------------------------
RLine2 = if !IsNaN(ResistanceLevel) and RLineCount == 2 then ResistanceLevel else if IsNaN(close) then RLine2[1] else if !IsNaN(RLine2[1]) and close >= RLine2[1] then 0 else RLine2[1];
plot RLineP2 = if RLine2 > 0 then RLine2 else Double.NaN;
RLineP2.SetStyle(Curve.POINTS);
RLineP2.SetDefaultColor(Color.LIGHT_RED);
RLineP2.SetLineWeight(1);
RLineP2.HideBubble();
#----------------------------------------------------------------------------------
RLine3 = if !IsNaN(ResistanceLevel) and RLineCount == 3 then ResistanceLevel else if IsNaN(close) then RLine3[1] else if !IsNaN(RLine3[1]) and close >= RLine3[1] then 0 else RLine3[1];
plot RLineP3 = if RLine3 > 0 then RLine3 else Double.NaN;
RLineP3.SetStyle(Curve.POINTS);
RLineP3.SetDefaultColor(Color.LIGHT_RED);
RLineP3.SetLineWeight(1);
RLineP3.HideBubble();
#----------------------------------------------------------------------------------
RLine4 = if !IsNaN(ResistanceLevel) and RLineCount == 4 then ResistanceLevel else if IsNaN(close) then RLine4[1] else if !IsNaN(RLine4[1]) and close >= RLine4[1] then 0 else RLine4[1];
plot RLineP4 = if RLine4 > 0 then RLine4 else Double.NaN;
RLineP4.SetStyle(Curve.POINTS);
RLineP4.SetDefaultColor(Color.LIGHT_RED);
RLineP4.SetLineWeight(1);
RLineP4.HideBubble();
#----------------------------------------------------------------------------------
RLine5 = if !IsNaN(ResistanceLevel) and RLineCount == 5 then ResistanceLevel else if IsNaN(close) then RLine5[1] else if !IsNaN(RLine5[1]) and close >= RLine5[1] then 0 else RLine5[1];
plot RLineP5 = if RLine5 > 0 then RLine5 else Double.NaN;
RLineP5.SetStyle(Curve.POINTS);
RLineP5.SetDefaultColor(Color.LIGHT_RED);
RLineP5.SetLineWeight(1);
RLineP5.HideBubble();
#----------------------------------------------------------------------------------
RLine6 = if !IsNaN(ResistanceLevel) and RLineCount == 6 then ResistanceLevel else if IsNaN(close) then RLine6[1] else if !IsNaN(RLine6[1]) and close >= RLine6[1] then 0 else RLine6[1];
plot RLineP6 = if RLine6 > 0 then RLine6 else Double.NaN;
RLineP6.SetStyle(Curve.POINTS);
RLineP6.SetDefaultColor(Color.LIGHT_RED);
RLineP6.SetLineWeight(1);
RLineP6.HideBubble();
#----------------------------------------------------------------------------------
RLine7 = if !IsNaN(ResistanceLevel) and RLineCount == 7 then ResistanceLevel else if IsNaN(close) then RLine7[1] else if !IsNaN(RLine7[1]) and close >= RLine7[1] then 0 else RLine7[1];
plot RLineP7 = if RLine7 > 0 then RLine7 else Double.NaN;
RLineP7.SetStyle(Curve.POINTS);
RLineP7.SetDefaultColor(Color.LIGHT_RED);
RLineP7.SetLineWeight(1);
RLineP7.HideBubble();
#----------------------------------------------------------------------------------
RLine8 = if !IsNaN(ResistanceLevel) and RLineCount == 8 then ResistanceLevel else if IsNaN(close) then RLine8[1] else if !IsNaN(RLine8[1]) and close >= RLine8[1] then 0 else RLine8[1];
plot RLineP8 = if RLine8 > 0 then RLine8 else Double.NaN;
RLineP8.SetStyle(Curve.POINTS);
RLineP8.SetDefaultColor(Color.LIGHT_RED);
RLineP8.SetLineWeight(1);
RLineP8.HideBubble();
#----------------------------------------------------------------------------------
RLine9 = if !IsNaN(ResistanceLevel) and RLineCount == 9 then ResistanceLevel else if IsNaN(close) then RLine9[1] else if !IsNaN(RLine9[1]) and close >= RLine9[1] then 0 else RLine9[1];
plot RLineP9 = if RLine9 > 0 then RLine9 else Double.NaN;
RLineP9.SetStyle(Curve.POINTS);
RLineP9.SetDefaultColor(Color.LIGHT_RED);
RLineP9.SetLineWeight(1);
RLineP9.HideBubble();
#----------------------------------------------------------------------------------
RLine10 = if !IsNaN(ResistanceLevel) and RLineCount == 10 then ResistanceLevel else if IsNaN(close) then RLine10[1] else if !IsNaN(RLine10[1]) and close >= RLine10[1] then 0 else RLine10[1];
plot RLineP10 = if RLine10 > 0 then RLine10 else Double.NaN;
RLineP10.SetStyle(Curve.POINTS);
RLineP10.SetDefaultColor(Color.LIGHT_RED);
RLineP10.SetLineWeight(1);
RLineP10.HideBubble();
#----------------------------------------------------------------------------------
RLine11 = if !IsNaN(ResistanceLevel) and RLineCount == 11 then ResistanceLevel else if IsNaN(close) then RLine11[1] else if !IsNaN(RLine11[1]) and close >= RLine11[1] then 0 else RLine11[1];
plot RLineP11 = if RLine11 > 0 then RLine11 else Double.NaN;
RLineP11.SetStyle(Curve.POINTS);
RLineP11.SetDefaultColor(Color.LIGHT_RED);
RLineP11.SetLineWeight(1);
RLineP11.HideBubble();
#----------------------------------------------------------------------------------
RLine12 = if !IsNaN(ResistanceLevel) and RLineCount == 12 then ResistanceLevel else if IsNaN(close) then RLine12[1] else if !IsNaN(RLine12[1]) and close >= RLine12[1] then 0 else RLine12[1];
plot RLineP12 = if RLine12 > 0 then RLine12 else Double.NaN;
RLineP12.SetStyle(Curve.POINTS);
RLineP12.SetDefaultColor(Color.LIGHT_RED);
RLineP12.SetLineWeight(1);
RLineP12.HideBubble();
#----------------------------------------------------------------------------------
RLine13 = if !IsNaN(ResistanceLevel) and RLineCount == 13 then ResistanceLevel else if IsNaN(close) then RLine13[1] else if !IsNaN(RLine13[1]) and close >= RLine13[1] then 0 else RLine13[1];
plot RLineP13 = if RLine13 > 0 then RLine13 else Double.NaN;
RLineP13.SetStyle(Curve.POINTS);
RLineP13.SetDefaultColor(Color.LIGHT_RED);
RLineP13.SetLineWeight(1);
RLineP13.HideBubble();
#----------------------------------------------------------------------------------
RLine14 = if !IsNaN(ResistanceLevel) and RLineCount == 14 then ResistanceLevel else if IsNaN(close) then RLine14[1] else if !IsNaN(RLine14[1]) and close >= RLine14[1] then 0 else RLine14[1];
plot RLineP14 = if RLine14 > 0 then RLine14 else Double.NaN;
RLineP14.SetStyle(Curve.POINTS);
RLineP14.SetDefaultColor(Color.LIGHT_RED);
RLineP14.SetLineWeight(1);
RLineP14.HideBubble();
#----------------------------------------------------------------------------------
RLine15 = if !IsNaN(ResistanceLevel) and RLineCount == 15 then ResistanceLevel else if IsNaN(close) then RLine15[1] else if !IsNaN(RLine15[1]) and close >= RLine15[1] then 0 else RLine15[1];
plot RLineP15 = if RLine15 > 0 then RLine15 else Double.NaN;
RLineP15.SetStyle(Curve.POINTS);
RLineP15.SetDefaultColor(Color.LIGHT_RED);
RLineP15.SetLineWeight(1);
RLineP15.HideBubble();
#----------------------------------------------------------------------------------
RLine16 = if !IsNaN(ResistanceLevel) and RLineCount == 16 then ResistanceLevel else if IsNaN(close) then RLine16[1] else if !IsNaN(RLine16[1]) and close >= RLine16[1] then 0 else RLine16[1];
plot RLineP16 = if RLine16 > 0 then RLine16 else Double.NaN;
RLineP16.SetStyle(Curve.POINTS);
RLineP16.SetDefaultColor(Color.LIGHT_RED);
RLineP16.SetLineWeight(1);
RLineP16.HideBubble();
#----------------------------------------------------------------------------------
RLine17 = if !IsNaN(ResistanceLevel) and RLineCount == 17 then ResistanceLevel else if IsNaN(close) then RLine17[1] else if !IsNaN(RLine17[1]) and close >= RLine17[1] then 0 else RLine17[1];
plot RLineP17 = if RLine17 > 0 then RLine17 else Double.NaN;
RLineP17.SetStyle(Curve.POINTS);
RLineP17.SetDefaultColor(Color.LIGHT_RED);
RLineP17.SetLineWeight(1);
RLineP17.HideBubble();
#----------------------------------------------------------------------------------
RLine18 = if !IsNaN(ResistanceLevel) and RLineCount == 18 then ResistanceLevel else if IsNaN(close) then RLine18[1] else if !IsNaN(RLine18[1]) and close >= RLine18[1] then 0 else RLine18[1];
plot RLineP18 = if RLine18 > 0 then RLine18 else Double.NaN;
RLineP18.SetStyle(Curve.POINTS);
RLineP18.SetDefaultColor(Color.LIGHT_RED);
RLineP18.SetLineWeight(1);
RLineP18.HideBubble();
#----------------------------------------------------------------------------------
RLine19 = if !IsNaN(ResistanceLevel) and RLineCount == 19 then ResistanceLevel else if IsNaN(close) then RLine19[1] else if !IsNaN(RLine19[1]) and close >= RLine19[1] then 0 else RLine19[1];
plot RLineP19 = if RLine19 > 0 then RLine19 else Double.NaN;
RLineP19.SetStyle(Curve.POINTS);
RLineP19.SetDefaultColor(Color.LIGHT_RED);
RLineP19.SetLineWeight(1);
RLineP19.HideBubble();
#----------------------------------------------------------------------------------
RLine20 = if !IsNaN(ResistanceLevel) and RLineCount == 20 then ResistanceLevel else if IsNaN(close) then RLine20[1] else if !IsNaN(RLine20[1]) and high >= RLine20[1] then 0 else RLine20[1];
plot RLineP20 = if RLine20 > 0 then RLine20 else Double.NaN;
RLineP20.SetStyle(Curve.POINTS);
RLineP20.SetDefaultColor(Color.LIGHT_ORANGE);
RLineP20.SetLineWeight(1);
RLineP20.HideBubble();
#####################################################################################
#####################################################################################

#End of Code#


# count_signals_00

def na = Double.NaN;
def bn = BarNumber();
#-----------------------
# test data
def x = Random() * 100;
input percent_of_test_signals = 20;
def t = (x <= percent_of_test_signals);
#-----------------------
# replace t,
# set desired signal variable equal to signal
def signal = gap1dn  and close>=Rline1
and close>=Rline2
and close>=Rline3
and close>=Rline4
and close>=Rline5
and close>=Rline6
and close>=Rline7
and close>=Rline8
and close>=Rline9
and close>=Rline10
and close>=Rline11
and close>=Rline12
and close>=Rline13
and close>=Rline14
and close>=Rline15
and close>=Rline16
and close>=Rline17
and close>=Rline18
and close>=Rline19
and close>=Rline20
or gap1up  and close<=Sline1
and close<=Sline2
and close<=Sline3
and close<=Sline4
and close<=Sline5
and close<=Sline6
and close<=Sline7
and close<=Sline8
and close<=Sline9
and close<=Sline10
and close<=Sline11
and close<=Sline12
and close<=Sline13
and close<=Sline14
and close<=Sline15
and close<=Sline16
and close<=Sline17
and close<=Sline18
and close<=Sline19
and close<=Sline20 ;


#-----------------------
# signals on chart
def sig_cnt_chart = if bn == 1 and signal then 1
else if bn == 1 then 0
else if signal then sig_cnt_chart[1] + 1
else sig_cnt_chart[1];

addlabel(1, "quantity of Signal = True on chart " + sig_cnt_chart, color.yellow);

input show_signals_on_chart = yes;
def vert = 0.006;
plot z1 = if show_signals_on_chart and signal then high*(1+vert) else na;
z1.SetPaintingStrategy(PaintingStrategy.POINTS);
z1.SetDefaultColor(Color.cyan);
z1.setlineweight(2);
z1.hidebubble();

input show_signal_count_bubbles_on_chart = yes;
addchartbubble(show_signal_count_bubbles_on_chart and t, low*(1-vert),
 sig_cnt_chart
, color.yellow, no);
#
[/QUOTE]
 
Last edited:
@Trigun1127 I think you actually want to track SLineCount and RLineCount because they are used to track the highest numbered plot still in use to make efficient use of the plots. Say a new signal occurs on the Gap1Up side, the value of SLineCount is incremented up by 1 and the corresponding SLine def and plot are used. (ex: SLineCount = 3 then Sline3 and Sline3P are used.). This also works when a Gap is closed and the plot ends. (ex: Sline3P plot is filled then SLine3 value becomes 0 and SLine3P value is NaN and SLineCount decreases by 1 to 2.

So everytime a Gap1Up is filled SLineCount decrease by 1.
The same is true for RLineCount.

So, you can easily def a counter to start at 0 and every time SLineCount is decreased, increment the counter up
by SLineCount[1]-SLineCount (This is because mulitple gaps can be filled in one bar.).

The ending value of the counter would be the number of Gap1Up that have been filled and the current value of SlineCount would be the number of Gap1Up yet to be filled.


 
I think I understand. This would just work as a running counter though wouldn’t it? I’m trying to look at historical data and see how often these gaps close. I’m also trying to get other statistical data on them. Average of how many a day, how many bars on average between activation and fill, probability of closing same day, probability of closing next day. That’s another thing entirely but ultimately my goal.
 
@Trigun1127 instead of defining it as a running counter, just define it as SlineCounter[1]-SLineCounter. If the value is negative a Gap1Up occured, if positive, that amount of Gap1Ups were filled.
That should allow you to calculate an average amount for a time period.
In order to determine bars between activation and fill you would have to define another variable for every SLine to count starting when the SLineP becomes not NaN and stop when SLineP becomes NaN and then def another variable to record the final bar count when SLineP becomes NaN.

Actually I already did the bar count in the thread I originally wrote this code for.
https://usethinkscript.com/threads/support-resistance-that-ends-once-touched.9491/page-3#posts
Post #46.
 
I'm sorry Svanoy I get it to a degree but I'm so unfamiliar with everything I feel like I'm in a mirror room with all the code. I know next to nothing. If you could apply the code so then I can see what you did it would make more sense to me.
 
Hey Svanoy is it possible to have the gap lines extend at the close of the first bar that creates the gap and when going up the close of the first bar that creates the gap. Currently during Gap 1 down the line extends out at 2nd bars open and during gap1up it extends at the 2nd bars open as well. It just needs to be the first bars close.
 
Hey Svanoy is it possible to have the gap lines extend at the close of the first bar that creates the gap and when going up the close of the first bar that creates the gap. Currently during Gap 1 down the line extends out at 2nd bars open and during gap1up it extends at the 2nd bars open as well. It just needs to be the first bars close.

Updated code in post #2 to plot close value of first bar that creates gap.
 
Fantastic. For some reason this code wont work on higher time frames now. Trying to get it to work on daily and weekly charts. Also Svanoy Do you know if its possible to take data from sline and rline from lower time frames and plot it onto higher ones? I know you can plot Higher time frames on to lower.
 
Fantastic. For some reason this code wont work on higher time frames now. Trying to get it to work on daily and weekly charts. Also Svanoy Do you know if its possible to take data from sline and rline from lower time frames and plot it onto higher ones? I know you can plot Higher time frames on to lower.
Updated code on post #2 to disregard day limitation if chart aggregation is DAY or higher.
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
262 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top