Looking For Input For HMA Strategy

METAL

Active member
Plus
I really think this is going to be a good strategy. I need to still add Labels so it will work with Macro Recorder. That isn't necessary though. I would like every ones feedback and criticism. Try it out. I will attempt to add labels. I also may add a couple of filters. Not sure if I will need them because with my testing so far, as long as you lengthen the Fast HMA, you can cut out most of the pullbacks and chop.

Latest Code:
HMA_V2 https://tos.mx/s900BxW

Code:
#Metal's-HMA-Strat-V1
#Credit @dap711 for providing the base code here https://usethinkscript.com/threads/moving-average-master-strategy-for-thinkorswim.13975/post-118000

input price = close;
input fastLength = 20;
input fastDisplace = 0;
input slowLength = 50;
input slowDisplace = 0;

plot Fast_HMA = MovingAverage(AverageType.HULL, price, fastLength)[-fastDisplace];
plot Slow_HMA = MovingAverage(AverageType.HULL, price, slowLength)[-slowDisplace];

Fast_HMA.DefineColor("Up", GetColor(1));
Fast_HMA.DefineColor("Down", GetColor(0));
Fast_HMA.AssignValueColor(if Fast_HMA > Fast_HMA[1] then Fast_HMA.Color("Up") else Fast_HMA.Color("Down"));

Slow_HMA.DefineColor("Up", GetColor(1));
Slow_HMA.DefineColor("Down", GetColor(0));
Slow_HMA.AssignValueColor(if Slow_HMA > Slow_HMA[1] then Slow_HMA.Color("Up") else Slow_HMA.Color("Down"));

plot BuySignal = if (Slow_HMA[1] <= Slow_HMA[2] and Slow_HMA > Slow_HMA[1]) then Slow_HMA else Double.NaN;
BuySignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BuySignal.AssignValueColor(Color.GREEN);
BuySignal.SetLineWeight(3);

plot SellSignal = if (Slow_HMA[1] >= Slow_HMA[2] and Slow_HMA < Slow_HMA[1]) then Slow_HMA else Double.NaN;
SellSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
SellSignal.AssignValueColor(Color.RED);
SellSignal.SetLineWeight(3);

plot BuyExit = if (Fast_HMA[1] >= Fast_HMA[2] and Fast_HMA < Fast_HMA[1]) then Fast_HMA else Double.NaN;
BuyExit.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
BuyExit.AssignValueColor(Color.YELLOW);
BuyExit.SetLineWeight(3);

plot SellExit = if (Fast_HMA[1] <= Fast_HMA[2] and Fast_HMA > Fast_HMA[1]) then Fast_HMA else Double.NaN;
SellExit.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
SellExit.AssignValueColor(Color.YELLOW);
SellExit.SetLineWeight(3);

AddOrder(OrderType.BUY_TO_OPEN, BuySignal, open[-1], 100, Color.GREEN, Color.GREEN);
AddOrder(OrderType.SELL_TO_CLOSE, SellSignal, open[-1], 100, Color.RED, Color.RED);
AddOrder(OrderType.SELL_TO_OPEN, BuyExit, open[-1], 100, Color.YELLOW, Color.YELLOW);
AddOrder(OrderType.BUY_TO_CLOSE, SellExit, open[-1], 100, Color.YELLOW, Color.YELLOW);
 
Last edited:
  • Love
Reactions: IPA
You must edit your ADDLabel statements. That is the code that determines label color and determines whether it "stays" or goes.
Make sure your conditional statements within your AddLabel are referencing the previous closed bar, not the current bar, not the next bar: the previous closed bar syntax ==[1].

read more:
https://usethinkscript.com/threads/indicators-that-we-are-using-in-our-algos.11585/#post-100422
Yes. I know that about the repaint, but do not know how to reference the opening of the next bar. I will look at your link. Hopefully that will shed some light on it.
 
Last edited by a moderator:
I am hitting a brick wall here. I can get the labels to color properly but, I cannot get them to stay white. (I may just use them this way if I have to)
1) Do I need this to be a strategy in order for the labels to work so that they only trigger once the candle closes or at open of the next candle?
2) I also cannot get the "Exit" labels to combine into one so that the close/exit label triggers with either buyexit or sellexit.
3) I need to eliminate false triggers but using the openorders function but cannot get it to work. I think I need it to be a strategy for this to work.

This is the one that kinda works but not when the exits are combined:
AddLabel(showLabels, " BUY ", if BuySignal then Color.CYAN else Color.white);
AddLabel(showLabels, " SELL ", if SellSignal then Color.MAGENTA else Color.white);
AddLabel(showLabels, " EXIT (BUY) ", if BuyExitSignal then Color.CYAN else Color.white);
AddLabel(showLabels, " EXIT (SELL) ", if SellExitSignal then Color.MAGENTA else Color.white);

Exits combined and with open order function:
def OpenOrders = GetQuantity();
AddLabel(yes, " BUY ", if BuySignal[1] and OpenOrders < 1 then Color.CYAN else Color.white);
AddLabel(yes, " SELL ", if SellSignal[1] and OpenOrders > -1 then Color.MAGENTA else Color.white);
AddLabel(yes, " Close ", if (SellExitSignal[1] and OpenOrders > 0) or (BuyExitSignal[1] and OpenOrders > 0) then Color.YELLOW else Color.white);

Chat GPT gave me the middle finger 😝
It could just be the order you have the lines of code in.
 
@mashume, I noticed that you are pretty good at coding. Would you be interested in helping me complete this strategy? I finally got the labels to work but, I think it may have to be change based on what others have said.
What I am looking to accomplish is:
1) I would like the the labels to signal after the close of the buy/sell plots to confirm direction. (Right now, if a buy/sell signal flasehes but doesn't stay, the label will trigger)
2) I would like to add a filter option to keep from taking trades during chop (If possible).
3) I would like to keep a label from triggering with another buy/sell if there is a order present. similar to this strat: ( https://usethinkscript.com/threads/...le-strategy-for-thinkorswim.14072/post-117569)
4 Not sure if I need to use the add order function or not.
I have tried countless times with many failures. Here is the latest code:

#Metal's-HMA-Strat-V1
#Credit @dap711 for providing the base code here https://usethinkscript.com/threads/moving-average-master-strategy-for-thinkorswim.13975/post-118000

input price = close;
input fastLength = 27;
input fastDisplace = 0;
input slowLength = 39;
input slowDisplace = 0;

plot Fast_HMA = MovingAverage(AverageType.HULL, price, fastLength)[-fastDisplace];
plot Slow_HMA = MovingAverage(AverageType.HULL, price, slowLength)[-slowDisplace];

#=========FAST LINE===========
Fast_HMA.DefineColor("Up", GetColor(1));
Fast_HMA.DefineColor("Down", GetColor(0));
Fast_HMA.AssignValueColor(if Fast_HMA > Fast_HMA[1] then Fast_HMA.Color("Up") else Fast_HMA.Color("Down"));

#=========SLOW LINE===========
Slow_HMA.DefineColor("Up", GetColor(1));
Slow_HMA.DefineColor("Down", GetColor(0));
Slow_HMA.AssignValueColor(if Slow_HMA > Slow_HMA[1] then Slow_HMA.Color("Up") else Slow_HMA.Color("Down"));

#=========PLOTS===========
plot BuySignal = if (Slow_HMA[1] <= Slow_HMA[2] and Slow_HMA > Slow_HMA[1]) then Slow_HMA else Double.NaN;
BuySignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BuySignal.AssignValueColor(Color.CYAN);
BuySignal.SetLineWeight(3);

plot SellSignal = if (Slow_HMA[1] >= Slow_HMA[2] and Slow_HMA < Slow_HMA[1]) then Slow_HMA else Double.NaN;
SellSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
SellSignal.AssignValueColor(Color.Magenta);
SellSignal.SetLineWeight(3);

plot BuyExit = if (Fast_HMA[1] >= Fast_HMA[2] and Fast_HMA < Fast_HMA[1]) then Fast_HMA else Double.NaN;
BuyExit.SetPaintingStrategy(PaintingStrategy.POINTS);
BuyExit.AssignValueColor(Color.CYAN);
BuyExit.SetLineWeight(5);

plot SellExit = if (Fast_HMA[1] <= Fast_HMA[2] and Fast_HMA > Fast_HMA[1]) then Fast_HMA else Double.NaN;
SellExit.SetPaintingStrategy(PaintingStrategy.SQUARES);
SellExit.AssignValueColor(Color.MAGENTA);
SellExit.SetLineWeight(5);

#=========ORDERS===========
#AddOrder(OrderType.BUY_TO_OPEN, BuySignal, open[-1], 1, Color.GREEN, Color.GREEN);
#AddOrder(OrderType.SELL_TO_CLOSE, SellSignal, open[-1], 1, Color.RED, Color.RED);
#AddOrder(OrderType.SELL_TO_OPEN, BuyExit, open[-1], 1, Color.YELLOW, Color.YELLOW);
#AddOrder(OrderType.BUY_TO_CLOSE, SellExit, open[-1], 1, Color.YELLOW, Color.YELLOW);

#=========LABELS===========
def OpenOrders = GetQuantity();
AddLabel(yes, " BUY ", if (Slow_HMA[1] <= Slow_HMA[2] and Slow_HMA > Slow_HMA[1]) then CreateColor(153, 255, 153) else Color.White);
AddLabel(yes, " SELL ", if (Slow_HMA[1] >= Slow_HMA[2] and Slow_HMA < Slow_HMA[1]) then CreateColor(255, 102, 102) else Color.White);
AddLabel(yes, " CLOSE ", if (Fast_HMA[1] >= Fast_HMA[2] and Fast_HMA < Fast_HMA[1]) or (Fast_HMA[1] <= Fast_HMA[2] and Fast_HMA > Fast_HMA[1]) then Color.Yellow else Color.White);
#=========END CODE===========
 
Need Help with Watchlist Background color. I can get the Buysignal to work but the sellsignal "Dark_Red" will not.
I have another attempt at the very bottom but they did not work.


Code:
#Metal's-HMA-Strat-V1
#Credit @dap711 for providing the base code here https://usethinkscript.com/threads/moving-average-master-strategy-for-thinkorswim.13975/post-118000

input price = close;
input fastLength = 29;
input fastDisplace = 0;
input slowLength = 41;
input slowDisplace = 0;

plot Fast_HMA = MovingAverage(AverageType.HULL, price, fastLength)[-fastDisplace];
plot Slow_HMA = MovingAverage(AverageType.HULL, price, slowLength)[-slowDisplace];

#=========FAST LINE===========
Fast_HMA.DefineColor("Up", GetColor(1));
Fast_HMA.DefineColor("Down", GetColor(0));
Fast_HMA.AssignValueColor(if Fast_HMA > Fast_HMA[1] then Fast_HMA.Color("Up") else Fast_HMA.Color("Down"));

#=========SLOW LINE===========
Slow_HMA.DefineColor("Up", GetColor(1));
Slow_HMA.DefineColor("Down", GetColor(0));
Slow_HMA.AssignValueColor(if Slow_HMA > Slow_HMA[1] then Slow_HMA.Color("Up") else Slow_HMA.Color("Down"));

#=========PLOTS===========
plot BuySignal = if (Slow_HMA[1] <= Slow_HMA[2] and Slow_HMA > Slow_HMA[1]) then Slow_HMA else Double.NaN;
BuySignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BuySignal.AssignValueColor(Color.CYAN);
BuySignal.SetLineWeight(3);

plot SellSignal = if (Slow_HMA[1] >= Slow_HMA[2] and Slow_HMA < Slow_HMA[1]) then Slow_HMA else Double.NaN;
SellSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
SellSignal.AssignValueColor(Color.Magenta);
SellSignal.SetLineWeight(3);

plot BuyExit = if (Fast_HMA[1] >= Fast_HMA[2] and Fast_HMA < Fast_HMA[1]) then Fast_HMA else Double.NaN;
BuyExit.SetPaintingStrategy(PaintingStrategy.POINTS);
BuyExit.AssignValueColor(Color.CYAN);
BuyExit.SetLineWeight(5);

plot SellExit = if (Fast_HMA[1] <= Fast_HMA[2] and Fast_HMA > Fast_HMA[1]) then Fast_HMA else Double.NaN;
SellExit.SetPaintingStrategy(PaintingStrategy.SQUARES);
SellExit.AssignValueColor(Color.MAGENTA);
SellExit.SetLineWeight(5);

AssignbackgroundColor(if BuySignal then color.Dark_Green else if SellSignal then Color.Dark_Red else color.Black);
AddLabel(yes, if (BuySignal) then "UP"
else if (SellSignal) then "Down"
else "  ");

#AssignBackgroundColor(if BuySignal then color.Dark_Green else color.black);
#AssignBackgroundColor(if SellSignal then color.dark_RED else color.black);
 
Need Help with Watchlist Background color. I can get the Buysignal to work but the sellsignal "Dark_Red" will not.
I have another attempt at the very bottom but they did not work.


Code:
#Metal's-HMA-Strat-V1
#Credit @dap711 for providing the base code here https://usethinkscript.com/threads/moving-average-master-strategy-for-thinkorswim.13975/post-118000

input price = close;
input fastLength = 29;
input fastDisplace = 0;
input slowLength = 41;
input slowDisplace = 0;

plot Fast_HMA = MovingAverage(AverageType.HULL, price, fastLength)[-fastDisplace];
plot Slow_HMA = MovingAverage(AverageType.HULL, price, slowLength)[-slowDisplace];

#=========FAST LINE===========
Fast_HMA.DefineColor("Up", GetColor(1));
Fast_HMA.DefineColor("Down", GetColor(0));
Fast_HMA.AssignValueColor(if Fast_HMA > Fast_HMA[1] then Fast_HMA.Color("Up") else Fast_HMA.Color("Down"));

#=========SLOW LINE===========
Slow_HMA.DefineColor("Up", GetColor(1));
Slow_HMA.DefineColor("Down", GetColor(0));
Slow_HMA.AssignValueColor(if Slow_HMA > Slow_HMA[1] then Slow_HMA.Color("Up") else Slow_HMA.Color("Down"));

#=========PLOTS===========
plot BuySignal = if (Slow_HMA[1] <= Slow_HMA[2] and Slow_HMA > Slow_HMA[1]) then Slow_HMA else Double.NaN;
BuySignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BuySignal.AssignValueColor(Color.CYAN);
BuySignal.SetLineWeight(3);

plot SellSignal = if (Slow_HMA[1] >= Slow_HMA[2] and Slow_HMA < Slow_HMA[1]) then Slow_HMA else Double.NaN;
SellSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
SellSignal.AssignValueColor(Color.Magenta);
SellSignal.SetLineWeight(3);

plot BuyExit = if (Fast_HMA[1] >= Fast_HMA[2] and Fast_HMA < Fast_HMA[1]) then Fast_HMA else Double.NaN;
BuyExit.SetPaintingStrategy(PaintingStrategy.POINTS);
BuyExit.AssignValueColor(Color.CYAN);
BuyExit.SetLineWeight(5);

plot SellExit = if (Fast_HMA[1] <= Fast_HMA[2] and Fast_HMA > Fast_HMA[1]) then Fast_HMA else Double.NaN;
SellExit.SetPaintingStrategy(PaintingStrategy.SQUARES);
SellExit.AssignValueColor(Color.MAGENTA);
SellExit.SetLineWeight(5);

AssignbackgroundColor(if BuySignal then color.Dark_Green else if SellSignal then Color.Dark_Red else color.Black);
AddLabel(yes, if (BuySignal) then "UP"
else if (SellSignal) then "Down"
else "  ");

#AssignBackgroundColor(if BuySignal then color.Dark_Green else color.black);
#AssignBackgroundColor(if SellSignal then color.dark_RED else color.black);

Creating boolean (1/0) signals works

Code:
def BS = if (Slow_HMA[1] <= Slow_HMA[2] and Slow_HMA > Slow_HMA[1]) then 1 else 0;
def SS= if (Slow_HMA[1] >= Slow_HMA[2] and Slow_HMA < Slow_HMA[1]) then 1 else 0;
AssignbackgroundColor(if BS then color.Dark_Green else if SS then Color.Dark_Red else color.Black);
AddLabel(yes, if BS then "UP"
else if SS then "DN"
else "  ");
 
Can someone please help me to get this watchlist to only show up or down within 1 bar?
I am using it to scalp 1m. so far it is working pretty well. I wait for the color change confirmation before entry and exit. So there is no way to give this a 1 bar signal and then the color assigned goes gray/black?
 
Last edited by a moderator:
Can someone please help me to get this watchlist to only show up or down within 1 bar?
I am using it to scalp 1m. so far it is working pretty well. I wait for the color change confirmation before entry and exit. So there is no way to give this a 1 bar signal and then the color assigned goes gray/black?
No, it is not possible for the Hull Concavity Script to show up or down within 1 bar given that this script uses future bars.

The whole premise of this indicator and the reason it works so well is that it calculates and confirms its signals using future bars.

This makes an excellent swing indicator, but the lag contraindicates it for scalping or short daytrading.

It is not possible to get a 1 bar signal. Scripts using future bars lag at least 2 bars before signaling.
 
Last edited:
No, it is not possible for the Hull Concavity Script to show up or down within 1 bar given that this script uses future bars.

The whole premise of this indicator and the reason it works so well is that it calculates and confirms its signals using future bars.

This makes an excellent swing indicator, but the lag contraindicates it for scalping or short daytrading.

It is not possible to get a 1 bar signal. Scripts using future bars lag at least 2 bars before signaling.
Merry, Does this code have the Hull Concavity Script?
 
Your script came from the Hull Concavity & Turning Points Indicator by @mashume
You can compare yours to the original if you have questions about what parts you may be missing:
https://usethinkscript.com/threads/hull-turning-points-concavity-for-thinkorswim.7847/#:~:text=they are crossing.-,mod note:,-@mashume's Hull
https://usethinkscript.com/threads/...nd-concavity-2nd-derivatives.1803/#post-16566
No it didn't. I tried using that one. This one was created from scratch. I used ChatGPT. It doesn't have the concavity you are talking about. I think. So does that make this one able to get the request I asked for?
 
Code:
Latest Code I use for trading. Still needs work. Would like to add some filters to weed out some chop. Haven't been successfull though.
#Metal's-HMA-Strat-V1
#Credit @dap711 for providing the base code here https://usethinkscript.com/threads/moving-average-master-strategy-for-thinkorswim.13975/post-118000

input price = close;
input fastLength = 27;
input fastDisplace = 0;
input slowLength = 39;
input slowDisplace = 0;
input showLabels = yes;

#=========Define HMA===========
plot Fast_HMA = MovingAverage(AverageType.HULL, price, fastLength)[-fastDisplace];
plot Slow_HMA = MovingAverage(AverageType.HULL, price, slowLength)[-slowDisplace];

#=========FAST LINE===========
Fast_HMA.DefineColor("Up", GetColor(1));
Fast_HMA.DefineColor("Down", GetColor(0));
Fast_HMA.AssignValueColor(if Fast_HMA > Fast_HMA[1] then Fast_HMA.Color("Up") else Fast_HMA.Color("Down"));
Fast_HMA.SetLineWeight(3);


#=========SLOW LINE===========
Slow_HMA.DefineColor("Up", GetColor(1));
Slow_HMA.DefineColor("Down", GetColor(0));
Slow_HMA.AssignValueColor(if Slow_HMA > Slow_HMA[1] then Slow_HMA.Color("Up") else Slow_HMA.Color("Down"));
Slow_HMA.SetLineWeight(3);

#=========PLOTS===========
def Buy = if (Slow_HMA[1] <= Slow_HMA[2] and Slow_HMA > Slow_HMA[1]) then Slow_HMA else Double.NaN;
plot BuySignal = Buy;
BuySignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BuySignal.AssignValueColor(Color.CYAN);
BuySignal.SetLineWeight(3);

def Sell = if (Slow_HMA[1] >= Slow_HMA[2] and Slow_HMA < Slow_HMA[1]) then Slow_HMA else Double.NaN;
plot SellSignal = Sell;
SellSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
SellSignal.AssignValueColor(Color.Magenta);
SellSignal.SetLineWeight(3);

def BuyExit = if (Fast_HMA[1] >= Fast_HMA[2] and Fast_HMA < Fast_HMA[1]) then Fast_HMA else Double.NaN;
plot BuyExitSignal = BuyExit;
BuyExitSignal.SetPaintingStrategy(PaintingStrategy.POINTS);
BuyExitSignal.AssignValueColor(Color.CYAN);
BuyExitSignal.SetLineWeight(5);

def SellExit = if (Fast_HMA[1] <= Fast_HMA[2] and Fast_HMA > Fast_HMA[1]) then Fast_HMA else Double.NaN;
plot SellExitSignal = SellExit;
SellExitSignal.SetPaintingStrategy(PaintingStrategy.SQUARES);
SellExitSignal.AssignValueColor(Color.MAGENTA);
SellExitSignal.SetLineWeight(5);

#=========LABELS===========
#def OpenOrders = GetQuantity();
#AddLabel(yes, "     BUY     ", if BuySignal[1] and OpenOrders < 1 then Color.CYAN else Color.white);
#AddLabel(yes, "     SELL     ", if SellSignal[1] and OpenOrders > -1 then Color.MAGENTA else Color.white);
#AddLabel(yes, "     Close     ", if (SellExitSignal[1] and OpenOrders > 0) or (BuyExitSignal[1] and OpenOrders > 0) then Color.YELLOW else Color.white);

#AddLabel(showLabels, "     BUY     ", if BuySignal then Color.CYAN else Color.white);
#AddLabel(showLabels, "     SELL     ", if SellSignal then Color.MAGENTA else Color.white);
#AddLabel(showLabels, " EXIT (BUY) ", if BuyExitSignal then Color.CYAN else Color.white);
#AddLabel(showLabels, " EXIT (SELL) ", if SellExitSignal then Color.MAGENTA else Color.white);

#def OpenOrders = GetQuantity();
#AddLabel(yes, "     BUY      ", if (Slow_HMA[1] <= Slow_HMA[2] and Slow_HMA > Slow_HMA[1]) then CreateColor(153, 255, 153) else Color.White);
#AddLabel(yes, "     SELL     ", if (Slow_HMA[1] >= Slow_HMA[2] and Slow_HMA < Slow_HMA[1]) then CreateColor(255, 102, 102) else Color.White);
#AddLabel(yes, "     CLOSE     ", if (Fast_HMA[1] >= Fast_HMA[2] and (Fast_HMA[1] <= Fast_HMA[2] and Fast_HMA > Fast_HMA[1])) then Color.Yellow else Color.White);
#=========Orders===========


#=========END CODE===========
 
Code:
This is the watchlist that I would like to have set to 1 bar then go Gray/Black affter bar closes.
In case it is now possible to accomplish.

#Metal's-HMA-Strat-V1
#Credit @dap711 for providing the base code here https://usethinkscript.com/threads/moving-average-master-strategy-for-thinkorswim.13975/post-118000

input price = close;
input fastLength = 10;
input fastDisplace = 0;
input slowLength = 10;
input slowDisplace = 0;

plot Fast_HMA = MovingAverage(AverageType.HULL, price, fastLength)[-fastDisplace];
plot Slow_HMA = MovingAverage(AverageType.HULL, price, slowLength)[-slowDisplace];

#=========FAST LINE===========
Fast_HMA.DefineColor("Up", GetColor(1));
Fast_HMA.DefineColor("Down", GetColor(0));
Fast_HMA.AssignValueColor(if Fast_HMA > Fast_HMA[1] then Fast_HMA.Color("Up") else Fast_HMA.Color("Down"));

#=========SLOW LINE===========
Slow_HMA.DefineColor("Up", GetColor(1));
Slow_HMA.DefineColor("Down", GetColor(0));
Slow_HMA.AssignValueColor(if Slow_HMA > Slow_HMA[1] then Slow_HMA.Color("Up") else Slow_HMA.Color("Down"));

#=========PLOTS===========
plot BuySignal = if (Slow_HMA[1] <= Slow_HMA[2] and Slow_HMA > Slow_HMA[1]) then Slow_HMA else Double.NaN;
BuySignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BuySignal.AssignValueColor(Color.CYAN);
BuySignal.SetLineWeight(3);

plot SellSignal = if (Slow_HMA[1] >= Slow_HMA[2] and Slow_HMA < Slow_HMA[1]) then Slow_HMA else Double.NaN;
SellSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
SellSignal.AssignValueColor(Color.Magenta);
SellSignal.SetLineWeight(3);

plot BuyExit = if (Fast_HMA[1] >= Fast_HMA[2] and Fast_HMA < Fast_HMA[1]) then Fast_HMA else Double.NaN;
BuyExit.SetPaintingStrategy(PaintingStrategy.POINTS);
BuyExit.AssignValueColor(Color.CYAN);
BuyExit.SetLineWeight(5);

plot SellExit = if (Fast_HMA[1] <= Fast_HMA[2] and Fast_HMA > Fast_HMA[1]) then Fast_HMA else Double.NaN;
SellExit.SetPaintingStrategy(PaintingStrategy.SQUARES);
SellExit.AssignValueColor(Color.MAGENTA);
SellExit.SetLineWeight(5);

def BS = if (Slow_HMA[1] <= Slow_HMA[2] and Slow_HMA > Slow_HMA[1]) then 1 else 0;
def SS= if (Slow_HMA[1] >= Slow_HMA[2] and Slow_HMA < Slow_HMA[1]) then 1 else 0;
AssignbackgroundColor(if BS then color.Dark_Green else if SS then Color.Dark_Red else color.Black);
AddLabel(yes, if BS then "UP"
else if SS then "DN"
else "  ");

#AssignbackgroundColor(if BuySignal then color.Dark_Green else if SellSignal then Color.Dark_Red else color.Black);
#AddLabel(yes, if (BuySignal) then "UP"
#else if (SellSignal) then "Down"
#else "  ");

#AssignBackgroundColor(if BuySignal then color.Dark_Green else color.black);
#AssignBackgroundColor(if SellSignal then color.dark_RED else color.black);
 
Asking for help with this code. I cannot get a few issues to work.
1) I am trying to change the buy signal to happen right at the up/down change. Like @chewie76 has happen when his hull line changes. I can only achieve on bar beyond the color change.
2) I also would like to achieve candle color change at the same time.

Code:
HMA_V3

input fastLength = 27;
input fastDisplace = 0;
input slowLength = 48;
input slowDisplace = 0;
input stop_horz_lines = yes;

def na = Double.NaN;

plot Fast_HMA = MovingAverage(AverageType.HULL, close, fastLength)[-fastDisplace];
plot Slow_HMA = MovingAverage(AverageType.HULL, close, slowLength)[-slowDisplace];

#=========FAST LINE===========
Fast_HMA.DefineColor("Up", GetColor(1));
Fast_HMA.DefineColor("Down", GetColor(0));
Fast_HMA.AssignValueColor(if Fast_HMA > Fast_HMA[1] then Fast_HMA.Color("Up") else Fast_HMA.Color("Down"));

#=========SLOW LINE===========
Slow_HMA.DefineColor("Up", GetColor(1));
Slow_HMA.DefineColor("Down", GetColor(0));
Slow_HMA.AssignValueColor(if Slow_HMA > Slow_HMA[1] then Slow_HMA.Color("Up") else Slow_HMA.Color("Down"));

#=========PLOTS===========
plot BuySignal = if (Slow_HMA[1] <= Slow_HMA[2] and Slow_HMA > Slow_HMA[1]) then Slow_HMA else Double.NaN;
BuySignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BuySignal.AssignValueColor(Color.CYAN);
BuySignal.SetLineWeight(3);

plot SellSignal = if (Slow_HMA[1] >= Slow_HMA[2] and Slow_HMA < Slow_HMA[1]) then Slow_HMA else Double.NaN;
SellSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
SellSignal.AssignValueColor(Color.MAGENTA);
SellSignal.SetLineWeight(3);

plot BuyExit = if (Fast_HMA[1] >= Fast_HMA[2] and Fast_HMA < Fast_HMA[1]) then Fast_HMA else Double.NaN;
BuyExit.SetPaintingStrategy(PaintingStrategy.POINTS);
BuyExit.AssignValueColor(Color.CYAN);
BuyExit.SetLineWeight(5);

plot SellExit = if (Fast_HMA[1] <= Fast_HMA[2] and Fast_HMA > Fast_HMA[1]) then Fast_HMA else Double.NaN;
SellExit.SetPaintingStrategy(PaintingStrategy.SQUARES);
SellExit.AssignValueColor(Color.MAGENTA);
SellExit.SetLineWeight(5);


#=========STOP LOSS LINES===========
def horzline = if IsNaN(BuyExit[1]) and !IsNaN(BuyExit) then BuyExit
 else if IsNaN(SellExit[1]) and !IsNaN(SellExit) then SellExit
 else horzline[1];

plot zhorz = if !stop_horz_lines or IsNaN(close) then na else horzline;
zhorz.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

#=========CANDLE COLOR===========
#AssignPriceColor(if close > Slow_HMA then Color.GREEN else if close < Slow_HMA then Color.RED else Color.CURRENT);
 
Asking for help with this code. I cannot get a few issues to work.
1) I am trying to change the buy signal to happen right at the up/down change. Like @chewie76 has happen when his hull line changes. I can only achieve on bar beyond the color change.
2) I also would like to achieve candle color change at the same time.

Code:
HMA_V3

input fastLength = 27;
input fastDisplace = 0;
input slowLength = 48;
input slowDisplace = 0;
input stop_horz_lines = yes;

def na = Double.NaN;

plot Fast_HMA = MovingAverage(AverageType.HULL, close, fastLength)[-fastDisplace];
plot Slow_HMA = MovingAverage(AverageType.HULL, close, slowLength)[-slowDisplace];

#=========FAST LINE===========
Fast_HMA.DefineColor("Up", GetColor(1));
Fast_HMA.DefineColor("Down", GetColor(0));
Fast_HMA.AssignValueColor(if Fast_HMA > Fast_HMA[1] then Fast_HMA.Color("Up") else Fast_HMA.Color("Down"));

#=========SLOW LINE===========
Slow_HMA.DefineColor("Up", GetColor(1));
Slow_HMA.DefineColor("Down", GetColor(0));
Slow_HMA.AssignValueColor(if Slow_HMA > Slow_HMA[1] then Slow_HMA.Color("Up") else Slow_HMA.Color("Down"));

#=========PLOTS===========
plot BuySignal = if (Slow_HMA[1] <= Slow_HMA[2] and Slow_HMA > Slow_HMA[1]) then Slow_HMA else Double.NaN;
BuySignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BuySignal.AssignValueColor(Color.CYAN);
BuySignal.SetLineWeight(3);

plot SellSignal = if (Slow_HMA[1] >= Slow_HMA[2] and Slow_HMA < Slow_HMA[1]) then Slow_HMA else Double.NaN;
SellSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
SellSignal.AssignValueColor(Color.MAGENTA);
SellSignal.SetLineWeight(3);

plot BuyExit = if (Fast_HMA[1] >= Fast_HMA[2] and Fast_HMA < Fast_HMA[1]) then Fast_HMA else Double.NaN;
BuyExit.SetPaintingStrategy(PaintingStrategy.POINTS);
BuyExit.AssignValueColor(Color.CYAN);
BuyExit.SetLineWeight(5);

plot SellExit = if (Fast_HMA[1] <= Fast_HMA[2] and Fast_HMA > Fast_HMA[1]) then Fast_HMA else Double.NaN;
SellExit.SetPaintingStrategy(PaintingStrategy.SQUARES);
SellExit.AssignValueColor(Color.MAGENTA);
SellExit.SetLineWeight(5);


#=========STOP LOSS LINES===========
def horzline = if IsNaN(BuyExit[1]) and !IsNaN(BuyExit) then BuyExit
 else if IsNaN(SellExit[1]) and !IsNaN(SellExit) then SellExit
 else horzline[1];

plot zhorz = if !stop_horz_lines or IsNaN(close) then na else horzline;
zhorz.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

#=========CANDLE COLOR===========
#AssignPriceColor(if close > Slow_HMA then Color.GREEN else if close < Slow_HMA then Color.RED else Color.CURRENT);
https://usethinkscript.com/threads/looking-for-input-for-hma-strategy.14377/#post-119125
 
Okay. So is Chewy's using "Displace" to achieve this? I did not see that in his code, however, I may have overlooked it.
It's great to see you're interested in discussing one of @chewies's 27 amazing scripts.

To make sure we address your question accurately, could you please let us know which specific script you're referring to?
 
Last edited:

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