Code problem with DrummondChannel indicator

I have been writing a code and I am trying to plot the mid point between two areas and was wondering how i could code for this?

This is a snippet of the code, I want to plot the midpoint between upperband4 and lowerband1

Code:
input price = close;
input displace = 0;
input length = 20;
input Num_Dev_Dn = -1.9;
input Num_Dev_Dn1 = -2.9;
input Num_Dev_Dn2 = -3.9;
input Num_Dev_Dn3 = -4.9;
input Num_Dev_Dn4 = -5.9;
input Num_Dev_up = 1.9;
input Num_Dev_up1 = 2.9;
input Num_Dev_up2 = 3.9;
input Num_Dev_up3 = 4.9;
input Num_Dev_up4 = 5.9;


def sDev = StDev(data = price[-displace], length = length);

#DrummondChannel
def o = open(period = agg);
def h = high(period = agg);
def l = low(period = agg);
def c = close(period = agg);
def HMA = MovingAverage(AverageType.HULL, price, length)[displace];
plot Hull = HMA;


#====1-1Channel====
def y = HMA - AbsValue(h[1] - HMA);
def x = HMA + AbsValue(HMA - l[1]);
plot res = x;
plot sup = y;


plot LowerBand1 = y + Num_Dev_Dn1 * sDev;
plot UpperBand1 = x + Num_Dev_up1 * sDev;
plot LowerBand3 = y + Num_Dev_Dn3 * sDev;
plot UpperBand3 = x + Num_Dev_up3 * sDev;
plot LowerBand4 = y + Num_Dev_Dn4 * sDev;
plot UpperBand4 = x + Num_Dev_up4 * sDev;
 

generic

Active member
@aceboogie_11 Are you talking about the hops in the picture? If you are then its because you're using a higher agg period than your current chart. There's no way to fix this.

wG4qqCK.png
 
i use the daily on the 15min chart but during the day or even on demand the boxes move back and fourth for some reason they arent repainting but they jump from one spot to another
 

generic

Active member
It might also be moving back and forth because the close of the day is constantly changing. Your HMA and StDev are based on close it'll keep changing until the day ends.
 

generic

Active member
@aceboogie_11 It does flicker like you say. Changed the code to remove all the useless stuff and I'm pretty sure the flickers are because of the HMA and StDev calculations because I changed them to use daily close instead of current chart close and the flickers stop.
Code:
declare upper;

input agg = AggregationPeriod.FIFTEEN_MIN;


input price = close;
input length = 20;
input Num_Dev_Dn = -1.9;
input Num_Dev_Dn1 = -2.9;
input Num_Dev_Dn2 = -3.9;
input Num_Dev_Dn3 = -4.9;
input Num_Dev_Dn4 = -5.9;
input Num_Dev_up = 1.9;
input Num_Dev_up1 = 2.9;
input Num_Dev_up2 = 3.9;
input Num_Dev_up3 = 4.9;
input Num_Dev_up4 = 5.9;


def sDev = StDev(data = price, length = length);

#DrummondChannel
def o = open(period = agg);
def h = high(period = agg);
def l = low(period = agg);
def c = close(period = agg);
def HMA = MovingAverage(AverageType.HULL, price, length);
plot Hull = HMA;


#====1-1Channel====
def y = HMA - AbsValue(h[1] - HMA);
def x = HMA + AbsValue(HMA - l[1]);
plot res = x;
plot sup = y;


plot LowerBand1 = y + Num_Dev_Dn1 * sDev;
plot UpperBand1 = x + Num_Dev_up1 * sDev;
plot LowerBand3 = y + Num_Dev_Dn3 * sDev;
plot UpperBand3 = x + Num_Dev_up3 * sDev;
plot LowerBand4 = y + Num_Dev_Dn4 * sDev;
plot UpperBand4 = x + Num_Dev_up4 * sDev;

plot mid = (upperband4 + lowerband4)/2;


LowerBand4.SetDefaultColor(Color.GREEN);
LowerBand1.SetDefaultColor(Color.GREEN);
UpperBand1.SetDefaultColor(Color.RED);
UpperBand4.SetDefaultColor(Color.RED);

Hull.DefineColor("Up", Color.GREEN);
Hull.DefineColor("Down", Color.RED);
Hull.AssignValueColor(if HMA > HMA[1] then Hull.Color("Up") else Hull.Color("Down"));

AddCloud(LowerBand3, LowerBand4, Color.Dark_gray);
AddCloud(LowerBand1, LowerBand3, Color.DARK_gray);
AddCloud(UpperBand4, UpperBand3, Color.Dark_gray);
AddCloud(UpperBand3, UpperBand1, Color.DARK_gray);
 

Similar threads

Top