 # Code problem with DrummondChannel indicator

#### aceboogie_11

##### Member
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 - HMA);
def x = HMA + AbsValue(HMA - l);
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 Your code doesn't work. There's no timePerProfile.

#### 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. #### aceboogie_11

##### Member
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.

• BenTen

#### 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 - HMA);
def x = HMA + AbsValue(HMA - l);
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 then Hull.Color("Up") else Hull.Color("Down"));

#### aceboogie_11

##### Member
Ill try the code, but thank you and ill get back to you if it works!

#### generic

##### Active member
@aceboogie_11 I didn't put the changes into the code above but if you change them yourself you'll see what I mean.

#### aceboogie_11

##### Member
what would the code for that look like? Im still new to coding.

#### generic

##### Active member
@aceboogie_11 Change the price in HMA and StDev to c so it uses the close of the high agg but this will change the channels which is why I didn't change it myself.

#### aceboogie_11

##### Member
I put that in and it seemed to be repainting when i was trying it out in on demand. But again my on demand is acting up