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;
 
@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
 
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.
 
@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);
 

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
414 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