Repaints Hull Moving Average Turning Points and Concavity (2nd Derivatives)

Repaints
Status
Not open for further replies.
@mashume, thank your for this script and all the help you've provided. I would like to know if there's anyway to make this work in a tick setting. It seems possible but since the code is written to aggregate period, Tick chart is not supported.
I haven't really looked into that. Perhaps some day when I have an abundance of time on my hands. Which hasn't been recently
 
So I did some backtesting on this with different Fibonacci lengths, timeframes, and including MACD as another entry/exit timing signal, and here are some early results. I was looking for Win Rates that were 65% or better, I am still looking for other confirmation indicators to make better entries. Any suggestions would be appreciated and I can provide more backtesting results… in due time.

TLDR:
Intraday Setup: My chosen setup is Setup #2 on the 5 min chart with the Original code and with the MACD (8,21,5) as entry confirmation. The Extended Hours are shown but only trade between 0930-1500 EST.
Swing Setup: My chosen setup is Setup #3 on the Daily chart with the Original code and with the MACD (8,21,5) as entry confirmation.


5 Day / 5 Min: My Chosen Intraday Setup is Setup #2
Setup #1: I have Extended Hours plotted but only took trades from 0930-1500 EST. I decided to end trading at 1500 so as not to have a position open that goes into the aftermarket hours. With this setup, I would go with the 34 HMA returning the best P/L and Win Rate.

bGMsESXqtIEsbsL8Z8p2De41IWLa8qSF-R3cpDdcwEUPO-gwrNa7egGtRkU1aRXBms8FIHBZMhIcnxhRZ6b06EUx40zHX_A0lmzEenoYS08cqCY3Nlscr2K38m3jfGlPKD_2Ag4e


Setup #2 (Chosen Intraday Setup): I had Extended Hours plotted but only took trades from 0930-1500 EST. I decided to end trading at 1500 so as not to have a position open that goes into the aftermarket hours. With this setup, I also used MACD (8, 21, 5, Exponential, no) to help confirm my entries but used the regular exit points provided by the original script. The entry criteria for this is the “buy” signal from the original code along with the MACD “Value” > “Avg”. The 21 HMA provides the best P/L and Win Rate with the 55 HMA providing the lowest P/L but the 2nd best Win Rate.

ZI616f9KmZ104yRzPTmBXq5jgN6Pr4vKQHqjKFwEMwOR0gEMu_ure3rCajz62lhgHVDx-QxKXLpEdxYae9nXNNrk6RpO97O--TnqVmW0D2cL9SVnBxje6gefLbFUOqKozPN52HH6



5 Year / 1 Day: My Chosen Swing Setup is either Setup #3 or #4
Setup #1: This setup is the original code with no changes. All of the different lengths are close in Win Rate. Nothing really stands out differently other than the 34 HMA and greater ones have almost 0.5% higher average gain. I don’t think this indicator alone is very good for Swing Trading.

OylUE1KEORP-Ntvv2ddnJBk8CPEG8qU8NrSCdpRKQB3XB3CI6cjGmYAoLmcQM2KSJ5N-vTB1Y4j7-bla4VA2L1rdCoZ5eN-OyzwiJKB-ofS8D9LxSMzk0SpYulZO9a-HUprcBQ33


Setup #2: This setup is the original code with a take profit at 5% gain. All of the different lengths are close in Win Rate. I plan on going back and putting in a stop loss at 5% to remove some of those losses in the 21 and 34 HMAs but I don’t think this indicator alone is very good for Swing Trading.

5rYZ25PhTUKzTz_8DJ1PEwJJ8IA_36gp6fdUr6OUsXd7UlfqczuKrCQnGX0RAnozj9c79U7M9k7sCHtpsHn240SOyA3lAUf-Xkq7pVqvBleIzFt53QY4VXVWlxzK6W5ndMRjCGnP


Setup #3: This setup is just like the 5 Day / 5 Min using the MACD as a confirmation to the entry point. As you can see the 21 HMA has the 2nd lowest P/L but the greatest Win Rate at 77% with only an average of 4 trades per year. Not the greatest P/L but that’s a decent Win Rate. An interesting thing to note is that the 89 and 144 HMAs provide almost 6x the profits with a 64% win rate with an average of 6.5 trades per year.

VnRTi1L61o5Cl_9YV4NNxnMoTbnYsIQTeqTJaX6fT5YtN63Qo3MSPBTUExSyp4OK5SxIo4E_-RwQCUMG4WBsTtfogn3P-Dqljzd2VTcby98aA42kU9YXYEY7ZBM9yur3Y4H-YNDs


Setup #4: This setup is just like the 5 Day / 5 Min using the MACD as a confirmation to the entry point with a take profit at 5%. As you can see the 21 HMA has the 2nd lowest P/L but the greatest Win Rate at 77% with only an average of 4 trades per year. Not the greatest P/L but that’s a decent Win Rate. An interesting thing to note is that the 89 and 144 HMAs provide almost 4-5x the profits with a 64% win rate with an average of 6.5 trades per year.

KLppEkTSPDUKrIhDixUxnIfrR-DlYDd2DfVkX-2Nxp5ziVLdvL4c-XN__Xl0EOIinAJuYbZ-AP95RN0i478aJgUqiBNh8SLqpjembkgHgN7cgXrtLrIL9JiBFlvuZwYeoy4t8fsX



360 Day / 1 Hour: My Chosen Swing Setup is ???
Setup #1: This setup is the original code with no changes. I didn’t exclude Pre-Market/Post-Market hours trading in this data set. All of the different lengths are close in Win Rate aside from the 144 HMA. I don’t think this indicator alone is very good for Swing Trading.

nkhDUOX74zLJd-DXCPBD3vmc1qYyTd0Fm_4cmCcYTdJ51Oi0yv12RF3FE-lpiiCpCltd0QdqDqdP8hbNURmzqDMwR4-T9DixAEeLWPt1HZcf363FIJzM9okQgTFviG28ylLZyUnY


Setup #2: This setup is the original code with a take profit at 5% gain. I didn’t exclude Pre-Market/Post-Market hours trading in this data set. All of the different lengths are close in Win Rate aside from the 144 HMA. I don’t think this indicator alone is very good for Swing Trading.

eNQapNNTuCcR9n9Gluv7r24eWFKNZcPQgNNecYzDZtKes-nhyP_U_0IRoWFcvzOaO0rmn9GQhhkjDyh8b8MY-FxvJIhyVIlr5BaBq1SE1Fu-w9cqc6MKjnximBBHlkPp46Q8nER0


Setup #3: This setup is just like the 5 Day / 5 Min using the MACD as a confirmation to the entry point. The 21 and 34 HMAs tie on Win Rate with 71% but the 21 HMA has a better Total P/L.

p3nr5oKivvWi-cnDb_Tn4n8SY0QNdIDourg46En_vBPu80oH-ZjPe3S8aTsYVAeZ36jcpzmav8p5Zb3LyIrl0I29EeQEovk0SyTw2487U6kT0lDPmZRM3JctMbonsZtc4KaO9de8
 
@diazlaz - Here is the actual code for what I'm using, I believe it is the variation that @greentonic posted (#421) with the ability to change between the different moving averages, paint candles, and the plotting on ToS Mobile. I removed the painting function as I have a different study I use to paint my candles and added my own things to have all the functions in one study.

One thing to note is that this study has a major difference when it comes to this version and Version #4 that @mashume has posted in post #1. The "plot sell" and "plot buy" for some reason have different signals. Version #4 has "plot sell = if turning_point and concavity == -1 then high else double.nan;" while my version has "plot sell = if turning_point and concavity == 1 then high else double.nan;". I'm not sure why this is but when I reverse them to match Version #4 obviously the signals switch and everything ends up as a loss.

You can see in the code where I have tried the 5% take profit and MACD for confirmation. This is my current intraday setup (MA_Length = 21, MACD = 8, 21, 5, and 5% profit). The 5% never seemed to trigger on intraday testing but I have it on anyway just to see it plotted on the chart. EDIT: Today was my first day trading with this setup and I actually decided to use 55 as the MA_Length, not 21.

Also, load this as a strategy that way you can see the buy/sell signals plotted in real-time.

Code:
#
# Multiple Moving Average Concavity and Turning Points
#  or
# The Second Derivative of the A Moving Average
#
# via useThinkScript
# request from chillc15
# Added Arnaud Legoux MA and other Moving Averages
#
# Author: Seth Urion (Mahsume)
# Version: 2020-02-22 V2
#
# This code is licensed (as applicable) under the GPL v3
#
# ----------------------

declare upper;

input Price = HL2;
input MA_Length = 21;
input lookback = 2;

input MovingAverage = {default "HMA", "EMA", "SMA", "WMA", "ALMA"};

script ALMA {
# Attributed to Miket
# https://tos.mx/9mznij
# https://usethinkscript.com/threads/alma-arnaud-legoux-ma-indicator-for-thinkorswim.174/
    input Data = close;
    input Window = 9;
    input Sigma = 6;
    input Offset = 0.85;

    def m = (Offset * (Window - 1));
    def s = Window / Sigma;

    def SumVectorData = fold y = 0 to Window with WS do WS + Exp(-(Sqr(y - m)) / (2 * Sqr(s))) * GetValue(Data, (Window - 1) - y);
    def SumVector = fold z = 0 to Window with CW do CW + Exp(-(Sqr(z - m)) / (2 * Sqr(s)));

    plot ALMA = SumVectorData / SumVector;
}

plot MA;
switch (MovingAverage) {
case EMA:
    MA = MovAvgExponential(price, length = MA_Length);
case SMA:
    MA = SimpleMovingAvg(price, length = MA_Length);
case WMA:
    MA = WMA(price, length = MA_Length);
case ALMA:
    MA = ALMA(Data = price, window = MA_Length);
default:
    MA = HullMovingAvg(price = price, length = MA_Length);
}


def delta = MA[1] - MA[lookback + 1];
def delta_per_bar = delta / lookback;

def next_bar = MA[1] + delta_per_bar;

def concavity = if MA > next_bar then 1 else -1;

plot turning_point = if concavity[-1] != concavity then MA else Double.NaN;

MA.AssignValueColor(color = if concavity == -1 then
    if MA > MA[1] then Color.DARK_ORANGE else Color.RED else
    if MA < MA[1] then Color.DARK_GREEN else Color.GREEN);

MA.SetLineWeight(2);

turning_point.SetLineWeight(2);
turning_point.SetPaintingStrategy(paintingStrategy = PaintingStrategy.POINTS);
turning_point.SetDefaultColor(Color.WHITE);

plot MA_Max = if MA[-1] < MA and MA > MA[1] then MA else Double.NaN;
MA_Max.SetDefaultColor(Color.BLUE);
MA_Max.SetPaintingStrategy(PaintingStrategy.SQUARES);
MA_Max.SetLineWeight(4);

plot MA_Min = if MA[-1] > MA and MA < MA[1] then MA else Double.NaN;
MA_Min.SetDefaultColor(Color.GRAY);
MA_Min.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
MA_Min.SetLineWeight(4);

plot sell = if turning_point and concavity == 1 then high else Double.NaN;
sell.SetDefaultColor(Color.DARK_ORANGE);
sell.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
sell.SetLineWeight(3);

plot buy = if turning_point and concavity == -1 then low else Double.NaN;
buy.SetDefaultColor(Color.CYAN);
buy.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
buy.SetLineWeight(3);

def divergence = MA - next_bar;

AddLabel(yes, Concat("DIVERGENCE: " , divergence), color = if concavity < 0 then if divergence[1] > divergence then Color.RED else Color.PINK else if divergence[1] < divergence then Color.GREEN else Color.YELLOW);
AddLabel(yes, "MA Length: " + MA_Length, color = Color.CYAN);

#####################
#
## 5% PROFIT INPUT ##
#
#####################
input percentGainGoal = 5;
def percentChange = 100 * (high - EntryPrice()) / EntryPrice();
def exitGood = percentChange >= percentGainGoal;


#####################
#
## MACD (8, 21, 5, EXPONENTIAL, NO) ##
#
#####################
input MACD_fastLength = 8;
input MACD_slowLength = 21;
input MACD_Length = 5;
def averageType = AverageType.EXPONENTIAL;
def showBreakoutSignals = no;

def Value = MovingAverage(averageType, close, MACD_fastLength) - MovingAverage(averageType, close, MACD_slowLength);
def Avg = MovingAverage(averageType, Value, MACD_Length);


#####################
#
## ORIGINAL ORDERS ##
#
#####################
#AddOrder(OrderType.BUY_TO_OPEN, buy, tickcolor = Color.CYAN, arrowcolor = Color.CYAN, name = "Buy", tradeSize = 1);
#AddOrder(OrderType.SELL_TO_CLOSE, sell, name = "Sell", tradeSize = 1);


##############
#
## 5% ORDER ##
#
##############
#addOrder(OrderType.SELL_TO_CLOSE, exitGood, name = "Sell 5%", tradeSize = 1);


####################
#
## ORIGINAL WITH MACD CONFIRM ORDER ##
#
####################
AddOrder(OrderType.BUY_TO_OPEN, buy and value > avg, tickcolor = Color.CYAN, arrowcolor = Color.CYAN, name = "Buy", tradeSize = 1);
AddOrder(OrderType.SELL_TO_CLOSE, sell, name = "Sell", tradeSize = 1);


####################
#
## ORIGINAL BUY AND MA_MIN WITH MACD CONFIRM ORDER ##
#
####################
#AddOrder(OrderType.BUY_TO_OPEN, buy and value > avg or MA_Min and value > avg, tickcolor = Color.CYAN, arrowcolor = Color.CYAN, name = "Buy", tradeSize = 1);
#AddOrder(OrderType.SELL_TO_CLOSE, sell, name = "Sell", tradeSize = 1);


###################
#
# ALERTS
#
###################

Alert(condition = buy, text = "Buy", "alert type" = Alert.BAR, sound = Sound.Bell);

Alert(condition = sell, text = "Sell", "alert type" = Alert.BAR, sound = Sound.Chimes);

###################
#
# 2020-05-01
#
# MOBILE TOS SUPPORT
#
# Each color of the HMA needs to be a separate plot as ToS Mobile
# lacks the ability to assign colors the way ToS Desktop does.
# I recommend a plain colored HMA behind the line
# Set the line color of the HMA above to gray or some neutral
#
# CCD_D -> ConCave Down and Decreasing
# CCD_I -> ConCave Down and Increasing
# CCU_D -> ConCave Up and Decreasing
# CCU_I -> ConCave Up and Increasing
#
###################
plot CCD_D = if concavity == -1 and MA < MA[1] then MA else double.nan;
CCD_D.SetDefaultColor(Color.RED);
CCD_D.SetLineWeight(2);

plot CCD_I = if concavity == -1 and MA >= MA[1] then MA else double.nan;
CCD_I.SetDefaultColor(Color.DARK_ORANGE);
CCD_I.SetLineWeight(2);

plot CCU_D = if concavity == 1 and MA <= MA[1] then MA else double.nan;
CCU_D.SetDefaultColor(COLOR.DARK_GREEN);
CCU_D.SetLineWeight(2);

plot CCU_I = if concavity == 1 and MA > MA[1] then MA else double.nan;
CCU_I.SetDefaultColor(COLOR.GREEN);
CCU_I.SetLineWeight(2);

ToS Strategy Link:
http://tos.mx/oYrHt3C
 
Last edited:
@Summies88 nice work.. have you backtest with ALMA? could be a good initial optimization to start.
I have not backtested anything other than the 13, 21, 34, 55, 89, & 144 HMAs on the 5D/5m, 5Yr/Daily, and 360Day/1h. I only stumbled across this Friday night and that's all I was able to do over the busy weekend that I had. I want to also look at the major SMA/EMAs (20, 50, 100, 200) and I can look into the ALMA which I have never looked at before.
 
@Summies88 nice work.. have you backtest with ALMA? could be a good initial optimization to start.
I was able to do some backtesting using the 13, 21, 34, 55, 89, 144, 20, 50, 100, & 200 ALMAs last night along with adding the 20, 50, 100, & 200 HMAs on the 5 Year / Daily chart.

Again, anything below a 65% win rate, I made red because it's not an indicator length that I would use. On the ALMA charts, Blue represents my choice of MA Length while on the HMA chart Blue is MA Lengths that I find interesting, namely the P/L total compared to the other lengths.

5 Year / Daily HMA w/ MACD (8,21,5) confirmation:
qbZ6WmiJo3cSUXWBi0CfPL_EgaDquB-EL1oRO_B0H6Ek8XKUvPBCKK34qgWQqlaB83FcS4BA1zzrcMRSbPLSZNs94Xdql-Cv6tJtOHDiqmL1hAK_iP555WJmXXS-xlGHsku84kcE


5 Year / Daily HMA w/ MACD (8,21,5) confirmation:
MLV-CoooHIHjJn0rd0JDPVz_Wvnm-aOqDRU8-CmvNOxv4uEri1fGKlIIVop3d2u4Vp3QeY1ZdpXP4kAgALS3bQ50Asu52hqYBJeIWEOezg5nFOVE2QBY1oiEGfXn9Qs2h3JBmQBB


5 Year / Daily ALMA:
KYfu_tG3JD-3-uutnqGoQdc6boJDs-BWW9f-A5XxIUGHz_XlhgyFYyWzotCTsikkYNuTmDyI04n_fjka4y8HNYt4mXuB3brd8dUZu6P5dEpBvHw66nptsLuVmxKTcU7AD7R2gSe3


I found that there are some articles that show that trading the 20 ALMA along with the 5 & 10 EMA help find entries and exits, however I didn’t have the time to coding that setup so I will look into that sometime this week, hopefully.
 
@Summies88 This looks very good. Do you have a scan for UP & Down arrows and also the Buy & Sell signals? Thanks
@Zoomer Below is the code that I use for my watchlist scans. This particular one was setup for the 5 min chart. The only difference between my intraday scan and my swing scan is that "5m" or "D" box and obviously I change what the length of my study is to match the length I want to scan for. For my intraday scan, I have one setup for 21 HMA and 55 HMA, and for my swings, I have the 20 HMA as my primary and the 89 & 144 HMA as my alternates right now

I am also looking at seeing how some of the longer-term MA lengths might play out with options. But that will require manual backtesting and that's not always the most reliable. Early assessment on $SPY using the 20 HMA on the Daily chart is that for the highest loss it would have been about a 15-25% for options and for the highest win trade it was about 50-115% profit depending on the options. But way more factors are required to figure what would be the best option chain, strike price, and so on.

"SCAN_Swing_TurningPoint_MACD" is what I named the study that mashume provided and the "MACD" is just the original MACD study in ToS.

Code:
SCAN_Swing_TurningPoint_MACD()."buy" is true within 2 bars and MACD("fast length" = 8, "slow length" = 21, "macd length" = 5)."Value" is greater than MACD("fast length" = 8, "slow length" = 21, "macd length" = 5)."Avg" within 2 bars
 
@mansor Being that I am just the one that added an extra indicator to it to provide a better entrance, that's all that I can really talk about.

For your first question, I noticed that there were a lot of signals when using the indicator by itself. So I looked into adding another simple indicator for using it as a confirmation of entry. Below are the results that I have for a 5M1D backtest of the 20HMA alone next to the 20HMA with MACD confirmation. These are on SPY from May-Oct 2020, the first trade being signaled on 7 May for the 20HMA and on 3 Jun for the 20HMA with MACD.

Over 5 months, 13 trades were made with the original code with a 62% win rate, however, when using the MACD it's a 100% win rate on 3 trades. I understand that a total of 16 trades isn't enough to actually base any data off of, which is why I did my backtesting on a 5Y/Daily chart to see how it faired over the years.

n8EeT9lEapBk1Z-EH2fHSVg9LYKClS411pCrjhLa4OcBUvsLEA1Os09Xwj80vXsjCluxRyLvkpYO9Ygzwg7myhL3sX7hUfh6FUd5xbTSuydzrGDrlLTDe6SHzIsDRnsyVqzfAKMm


For Question 2, Again, if you are getting too many signals you can either increase your MA length or use another indicator that you like to help gauge your entries and only make them once all of our buy signals match up. It just comes down to figuring out what signals you like best for making your entries and sticking to that. That's why I have my code as a strategy and not a study that way once the "buy" and my MACD confirmation are lined up it will plot a buy signal for me, making my entries dummy-proof.

Don't get me wrong, when you wait for the MACD for confirmation you do miss out on some trades. Below is the $SPY and you can see that the last signal with MACD was on 21 Jul. Even though the Original code gave more buy signals since then, but a couple were just false breakouts which ended in losses because you would have entered the day after the cyan arrow and exited after the orange arrows.

70oCQkSUVFwrmd37z3AzQE_qs6-zHEoSr6O6W_0pmHXOlfL9q-SB828uMeYuAfHS7JJKCkShBk6K1khM6zHiyqJ-_WyCuej_cxzFQ-kvIwUeAEOIW6MdZkvkJlzsIOE4DttPnalX
 
@mansor Being that I am just the one that added an extra indicator to it to provide a better entrance, that's all that I can really talk about.

For your first question, I noticed that there were a lot of signals when using the indicator by itself. So I looked into adding another simple indicator for using it as a confirmation of entry. Below are the results that I have for a 5M1D backtest of the 20HMA alone next to the 20HMA with MACD confirmation. These are on SPY from May-Oct 2020, the first trade being signaled on 7 May for the 20HMA and on 3 Jun for the 20HMA with MACD.

Over 5 months, 13 trades were made with the original code with a 62% win rate, however, when using the MACD it's a 100% win rate on 3 trades. I understand that a total of 16 trades isn't enough to actually base any data off of, which is why I did my backtesting on a 5Y/Daily chart to see how it faired over the years.

n8EeT9lEapBk1Z-EH2fHSVg9LYKClS411pCrjhLa4OcBUvsLEA1Os09Xwj80vXsjCluxRyLvkpYO9Ygzwg7myhL3sX7hUfh6FUd5xbTSuydzrGDrlLTDe6SHzIsDRnsyVqzfAKMm


For Question 2, Again, if you are getting too many signals you can either increase your MA length or use another indicator that you like to help gauge your entries and only make them once all of our buy signals match up. It just comes down to figuring out what signals you like best for making your entries and sticking to that. That's why I have my code as a strategy and not a study that way once the "buy" and my MACD confirmation are lined up it will plot a buy signal for me, making my entries dummy-proof.

Don't get me wrong, when you wait for the MACD for confirmation you do miss out on some trades. Below is the $SPY and you can see that the last signal with MACD was on 21 Jul. Even though the Original code gave more buy signals since then, but a couple were just false breakouts which ended in losses because you would have entered the day after the cyan arrow and exited after the orange arrows.

70oCQkSUVFwrmd37z3AzQE_qs6-zHEoSr6O6W_0pmHXOlfL9q-SB828uMeYuAfHS7JJKCkShBk6K1khM6zHiyqJ-_WyCuej_cxzFQ-kvIwUeAEOIW6MdZkvkJlzsIOE4DttPnalX
Great job could you post a link and share this set-up with us?
 
@TraderKevin I thought that I had my buy signals setup to buy at market open the day following the buy signal because I thought the buy signal was plotted based on the HL2 of the candle and not needing the next candle for the signal. I haven't had the time to actually see if that was correct or not. Thank you for the updated code, I will use this to continue my backtesting.
 
Last edited:
@TraderKevin I thought that I had my buy signals setup to buy at market open the day following the buy signal because I thought the buy signal was plotted based on the HL2 of the candle and not needing the next candle for the signal. I haven't had the time to actually see if that was correct or not. Thank you for the updated code, I will use this to continue my backtesting.
Using HL2 and waiting until midway through candle creation will allow you to guess that the candle won't make a move that changes the buy/sell signal, but based on my experience, that guess will be wrong as often as it's right. Half the time, then, you'll find yourself in trades that had no signal, and the price will have moved against you substantially already by the time the candle closes (since moving against you is what causes the signal to disappear). Even then you wouldn't be entering at the candle's open price like your strategy indicates, but somewhere worse (since it would have to be to create the signal in the first place).

In general, if results look too good to be true, they almost always are. When creating a strategy and backtesting it, your first step after creating it is to figure out everything that could possibly be wrong with the strategy that makes it look better than it actually is. In my experience, there are always many and they are difficult to find. Also keep in mind that TOS's backtesting doesn't account for transaction costs or slippage, which will both have a much larger effect than you might realize.
 
Hi there forum members,
I created the following backtest strategy and only the bearish signals are showing on the chart. I need help in the code so that the bullish signals will also show. Thanks.

Code:
input price = CLOSE;
input HMA_Length = 8;
input lookback = 2;

def HMA = HullMovingAvg(price = price, length = HMA_Length);

def delta = HMA[1] - HMA[lookback + 1];
def delta_per_bar = delta / lookback;

def next_bar = HMA[1] + delta_per_bar;

def concavity = if HMA > next_bar then 1 else -1;

def MA_Max = if HMA[-1] < HMA and HMA > HMA[1] then HMA else Double.NaN;
def MA_Min = if HMA[-1] > HMA and HMA < HMA[1] then HMA else Double.Nan;

def bullishsignal = if MA_Min then 1 else 0;
def bearishsignal = if MA_max then 1 else 0;

def exitbullishtrade = if ma_max then 1 else 0;
def exitbearishtrade = if ma_min then 1 else 0;

addOrder(OrderType.BUY_To_OPEN,bullishsignal,CLOSE,100, name = "ConcavityBUY");
addOrder(OrderType.SELL_To_CLOSE,exitbullishtrade,open,100, name = "ConcavityClose");

addOrder(OrderType.SELL_To_OPEN,bearishsignal,close,100, name = "ConcavitySell");
addOrder(OrderType.BUY_To_CLOSE,exitbearishtrade,open,100, name = "ConcavityClose");
 
Last edited by a moderator:
Status
Not open for further replies.

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