armybender
Active member
I have absolutely no idea what to call this indicator, but here's the idea. Rather than counting things like up bars or down bars, or trying to measure line breaks, etc., I thought about trying to visualize the structure of the market in a different way.
This indicator counts anytime 2 bars do NOT have overlapping bodies, either up or down and keeps a running total. I don't quite know how to use it yet, but have noticed it does a really good job of highlighting divergence between market moves (i.e. price move) and the strength of the moves (i.e. gaps on the way up/down).
Again, I'm not quite sure how this will be or could be used, but it is super interesting to note that the structure can be visualized this way.
This indicator counts anytime 2 bars do NOT have overlapping bodies, either up or down and keeps a running total. I don't quite know how to use it yet, but have noticed it does a really good job of highlighting divergence between market moves (i.e. price move) and the strength of the moves (i.e. gaps on the way up/down).
Again, I'm not quite sure how this will be or could be used, but it is super interesting to note that the structure can be visualized this way.
Ruby:
#DECLARATIONS
declare lower;
#USER INPUTS
input plotThickness = 2;
input colorBars = {default Off, By_Inst_Trend, By_Gap_Count};
input allowDojis = no;
input barsBack = 1000;
input skipBarsLevel = 2;
input showChannel = no;
input showCloud = yes;
input showLastPeaks = no;
input channelLength = 50;
input alpha = 0.07; # 0.07 is default
input smoothLength = 3;
input colorPctMin = 3;
#GLOBAL COLOR DEFINITIONS
DefineGlobalColor("Faded Green", CreateColor(75, 155, 75)); #original 0, 155, 0 / 4B9B4B
DefineGlobalColor("Faded Red", CreateColor(224, 117, 117)); #original 255, 105, 105 / E07575
DefineGlobalColor("Green", CreateColor(75, 155, 75)); #original 0, 155, 0 / 4B9B4B
DefineGlobalColor("Red", CreateColor(224, 117, 117)); #original 255, 105, 105 / E07575
DefineGlobalColor("Gray", CreateColor(181, 181, 181)); #original 181, 181, 181
#DEFINITIONS AND CALCULATIONS
## Body Gaps Calculations
def isUp = close > open;
def isDown = close < open;
def isDoji = close == open;
def isLastBar = !IsNaN(close) and IsNaN(close[-1]);
def bodyHigh = Max(open, close);
def bodyLow = Min(open, close);
def isUpGap = bodyLow >= bodyHigh[1] and (isUp or (allowDojis and isDoji));
def isDownGap = bodyHigh <= bodyLow[1] and (isDown or (allowDojis and isDoji));
def gapCount = if isUpGap then gapCount[1] + 1 else if isDownGap then gapCount[1] - 1 else gapCount[1];
def lastBN = if isLastBar[-1] then BarNumber() + 1 else lastBN[1];
def lastBNValue = if isNaN(close[-barsBack]) then lastBN[-barsBack - 1] else Double.NaN;
def barColor = if gapCount > gapCount[1] then 1 else if gapCount < gapCount[1] then -1 else barColor[1];
def colorMethod;
switch(colorBars){
case Off:
colorMethod = 0;
case By_Inst_Trend:
colorMethod = 1;
case By_Gap_Count:
colorMethod = 2;
};
def lastLevel = if isLastBar then gapCount else lastLevel[1];
def lastLevelValue = if isNaN(gapCount[-barsBack]) then lastLevel[-barsBack] else Double.NaN;
def levelLine =
if IsNaN(close) or BarNumber() % skipBarsLevel <> 0
then Double.NaN
else lastLevelValue
;
def isHighPeak = gapCount > lastLevelValue and gapCount[1] < gapCount;
def trailHighPeaks = if isHighPeak then gapCount else trailHighPeaks[1];
def lastHighPeakOffset = if isLastBar[-1] then GetMaxValueOffset(isHighPeak, barsBack) + 1 else lastHighPeakOffset[1];
def highPeakBarOffset = if isNaN(close[-barsBack]) then lastHighPeakOffset[-barsBack - 1] else Double.NaN;
def isLastHighPeak = BarNumber() == lastBNValue - highPeakBarOffset;
def countHigh = BarNumber() >= lastBNValue - highPeakBarOffset;
def lastHighPeakValue = if !countHigh then Double.NaN else if isLastHighPeak then gapCount else lastHighPeakValue[1];
def isLowPeak = gapCount < lastLevelValue and gapCount[1] > gapCount;
def trailLowPeaks = if isLowPeak then gapCount else trailLowPeaks[1];
def lastLowPeakOffset = if isLastBar[-1] then GetMaxValueOffset(isLowPeak, barsBack) + 1 else lastLowPeakOffset[1];
def lowPeakBarOffset = if isNaN(close[-barsBack]) then lastLowPeakOffset[-barsBack - 1] else Double.NaN;
def isLastLowPeak = BarNumber() == lastBNValue - lowPeakBarOffset;
def countLow = BarNumber() >= lastBNValue - lowPeakBarOffset;
def lastLowPeakValue = if !countLow then Double.NaN else if isLastLowPeak then gapCount else lastLowPeakValue[1];
## Ehlers Instantaneous Trend Calculations
def alpha2 = Power(alpha, 2);
def it =
Compoundvalue( 6,
( alpha - ( ( alpha2 ) / 4.0 ) )
* gapCount + 0.5 * alpha2 * gapCount[1] -
( alpha - 0.75 * alpha2 ) * gapCount[2] +
2 * ( 1 - alpha ) *
( if IsNaN( it[1] ) then ( ( gapCount + 2 * gapCount[1] + gapCount[2] ) / 4.0 ) else it[1] ) -
( 1 - alpha ) * ( 1 - alpha ) *
( if IsNaN( it[2] ) then ( ( gapCount + 2 * gapCount[1] + gapCount[2] ) / 4.0 ) else it[2] )
, (gapCount + 2 * gapCount[1] + gapCount[2] ) / 4
);
def lag = 2.0 * it - if IsNaN(it[2]) then 0 else it[2];
def itSmooth = ExpAverage(it, smoothLength);
def lagSmooth = ExpAverage(lag, smoothLength);
#PLOTS
plot GapCountPlot = gapCount;
plot LastLevelLine = levelLine;
plot InstTrend = itSmooth;
plot LastH = Highest(gapCount, channelLength) + 1;
plot LastL = Lowest(gapCount, channelLength) - 1;
plot LastHighPeak = if IsNaN(close) then Double.NaN else lastHighPeakValue;
plot LastLowPeak = if IsNaN(close) then Double.NaN else lastLowPeakValue;
#BAR COLORING
AssignPriceColor(
if colorMethod == 0 then
Color.CURRENT
else if colorMethod == 1 then
if gapCount >= itSmooth then GlobalColor("Green")
else GlobalColor("Red")
else if colorMethod == 2 then
if barColor == 1 then GlobalColor("Green")
else if barColor == -1 then GlobalColor("Red")
else GlobalColor("Gray")
else Color.CURRENT
);
#CLOUDS
AddCloud(if showCloud then GapCountPlot else Double.NaN, InstTrend, GlobalColor("Faded Green"), GlobalColor("Faded Red"));
#FORMATTING
GapCountPlot.AssignValueColor(if isLastBar then Color.YELLOW else if barColor == 1 then GlobalColor("Green") else if barColor == -1 then GlobalColor("Red") else GlobalColor("Gray"));
GapCountPlot.SetLineWeight(plotThickness);
GapCountPlot.HideBubble();
GapCountPlot.HideTitle();
LastLevelLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LastLevelLine.AssignValueColor(GlobalColor("Gray"));
LastLevelLine.HideTitle();
LastLevelLine.HideBubble();
InstTrend.AssignValueColor(
if it > it[1] then GlobalColor("Green")
else if it < it[1] then GlobalColor("Red")
else GlobalColor("Gray")
);
InstTrend.HideTitle();
InstTrend.HideBubble();
InstTrend.SetLineWeight(1);
InstTrend.AssignValueColor(
if it > it[1] then GlobalColor("Green")
else if it < it[1] then GlobalColor("Red")
else GlobalColor("Gray")
);
InstTrend.HideTitle();
InstTrend.HideBubble();
InstTrend.SetLineWeight(1);
LastH.AssignValueColor(GlobalColor("Red"));
LastH.SetHiding(!showChannel);
LastH.HideTitle();
LastH.HideBubble();
LastL.AssignValueColor(GlobalColor("Green"));
LastL.SetHiding(!showChannel);
LastL.HideTitle();
LastL.HideBubble();
LastHighPeak.AssignValueColor(GlobalColor("Red"));
LastHighPeak.SetPaintingStrategy(PaintingStrategy.DASHES);
LastHighPeak.SetHiding(!showLastPeaks);
LastHighPeak.HideTitle();
LastHighPeak.HideBubble();
LastLowPeak.AssignValueColor(GlobalColor("Green"));
LastLowPeak.SetPaintingStrategy(PaintingStrategy.DASHES);
LastLowPeak.SetHiding(!showLastPeaks);
LastLowPeak.HideTitle();
LastLowPeak.HideBubble();
Last edited: