HiLoActivator

David45

Active member
2019 Donor
Does anyone know how to make the following changes to this indicator?

1. Paint the candlesticks the same color as the lines above and below the candlesticks

2. Have an option to change the moving average type (simple, exponential, weighted, wilders, hull)

https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/G-L/HiLoActivator

input length = 3;

def maHigh = Average(high, length);
def maLow = Average(low, length);
def state = {default init, short, long};
if (close > maHigh) {
state = state.long;
} else if (close < maLow) {
state = state.short;
} else {
state = state[1];
}

plot BuyStop = if state == state.short or state != state[1] then maHigh else Double.NaN;
plot SellStop = if state == state.long or state != state[1] then maLow else Double.NaN;

BuyStop.SetDefaultColor(GetColor(0));
SellStop.SetDefaultColor(GetColor(1));
 
Solution
Code:
input length = 3;
input AvgType = AverageType.SIMPLE;

def maHigh = MovingAverage(AvgType,high, length);
def maLow = MovingAverage(AvgType,low, length);
def state = {default init, short, long};

if (close > maHigh) {
state = state.long;
} else if (close < maLow) {
state = state.short;
} else {
state = state[1];
}

plot BuyStop = if state == state.short or state != state[1] then maHigh else Double.NaN;
plot SellStop = if state == state.long or state != state[1] then maLow else Double.NaN;

BuyStop.SetDefaultColor(GetColor(0));
SellStop.SetDefaultColor(GetColor(1));

AssignPriceColor(if State == State.Long then SellStop.takevalueColor() else BuyStop.takevalueColor());
Code:
input length = 3;
input AvgType = AverageType.SIMPLE;

def maHigh = MovingAverage(AvgType,high, length);
def maLow = MovingAverage(AvgType,low, length);
def state = {default init, short, long};

if (close > maHigh) {
state = state.long;
} else if (close < maLow) {
state = state.short;
} else {
state = state[1];
}

plot BuyStop = if state == state.short or state != state[1] then maHigh else Double.NaN;
plot SellStop = if state == state.long or state != state[1] then maLow else Double.NaN;

BuyStop.SetDefaultColor(GetColor(0));
SellStop.SetDefaultColor(GetColor(1));

AssignPriceColor(if State == State.Long then SellStop.takevalueColor() else BuyStop.takevalueColor());
 
Solution

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

Code:
input length = 3;
input AvgType = AverageType.SIMPLE;

def maHigh = MovingAverage(AvgType,high, length);
def maLow = MovingAverage(AvgType,low, length);
def state = {default init, short, long};

if (close > maHigh) {
state = state.long;
} else if (close < maLow) {
state = state.short;
} else {
state = state[1];
}

plot BuyStop = if state == state.short or state != state[1] then maHigh else Double.NaN;
plot SellStop = if state == state.long or state != state[1] then maLow else Double.NaN;

BuyStop.SetDefaultColor(GetColor(0));
SellStop.SetDefaultColor(GetColor(1));

AssignPriceColor(if State == State.Long then SellStop.takevalueColor() else BuyStop.takevalueColor());
Okay so I had a crazy idea. Instead of using (simple, exponential, weighted, wilders, or hull) is there a way to use the McGinley Dynamic Moving Average with this indictor instead?

Here is the simplified code for the McGinely Dymanic Moving Average as seen in Post #1 here:
https://usethinkscript.com/threads/mcginley-dynamic-indicator-for-thinkorswim.338/

input periods = 10;

rec _md = CompoundValue( 1, _md[1] + (( close - _md[1] ) / ( periods * Power( close / _md[1], 4 ) ) ), close );

plot MD = _md;
 
Code:
input periods  = 3;
def maHigh = CompoundValue( 1, maHigh[1] + (( high - maHigh[1] ) / ( periods * Power( high / maHigh[1], 4 ) ) ), high );
def maLow = CompoundValue( 1, maLow[1] + (( low - maLow[1] ) / ( periods * Power( low / maLow[1], 4 ) ) ), low );
def state = {default init, short, long};

if (close > maHigh) {
state = state.long;
} else if (close < maLow) {
state = state.short;
} else {
state = state[1];
}

plot BuyStop = if state == state.short or state != state[1] then maHigh else Double.NaN;
plot SellStop = if state == state.long or state != state[1] then maLow else Double.NaN;

BuyStop.SetDefaultColor(GetColor(0));
SellStop.SetDefaultColor(GetColor(1));

AssignPriceColor(if State == State.Long then SellStop.takevalueColor() else BuyStop.takevalueColor());
 
Would anyone like to take a stab at creating a Heikin Ashi version of the HiLoActivator indicator? It would be very interesting to see how it would plot vs the standard version in TOS or the McGinley version above which @Joshua so graciously created.
 
Would anyone like to take a stab at creating a Heikin Ashi version of the HiLoActivator indicator? It would be very interesting to see how it would plot vs the standard version in TOS or the McGinley version above which @Joshua so graciously created.

See if this is what you wanted

Capture.jpg
Ruby:
#
# TD Ameritrade IP Company, Inc. (c) 2020-2022
#

input length = 3;

def HAclose   =  (open + high + low + close) / 4;
def HAopen    = CompoundValue( 1, ( HAopen[1] + HAclose[1] ) / 2, HAclose );
def HAhigh    = Max( high, Max( HAopen, HAclose ) );
def HAlow     = Min( low, Min( HAopen, HAclose ) );

def maHigh = Average(HAhigh, length);
def maLow = Average(HAlow, length);
def state = {default init, short, long};
if (HAclose > maHigh) {
    state = state.long;
} else if (HAclose < maLow) {
    state = state.short;
} else {
    state = state[1];
}

plot BuyStop = if state == state.short or state != state[1] then maHigh else Double.NaN;
plot SellStop = if state == state.long or state != state[1] then maLow else Double.NaN;

BuyStop.SetDefaultColor(GetColor(0));
SellStop.SetDefaultColor(GetColor(1));

AssignPriceColor(if State == State.Long then SellStop.takevalueColor() else BuyStop.takevalueColor());

BuyStop.SetDefaultColor(GetColor(0));
SellStop.SetDefaultColor(GetColor(1));
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
115 Online
Create Post

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