Hull Moving Average Turning Points EA

If you need an Indicator or Signal developed or translated from other language, please post all Indicator development REQUESTS to this section here.

Moderator: admin

Hull Moving Average Turning Points EA

Postby goshme » Tue Nov 30, 2021 3:33 pm

Looking to have this indicator and strategy converted from thinkscript to mql4
Long when strategy say and sell when opposite signal appears.

Thinkscript indicator code
Code: Select all
#
# Hull Moving Average Concavity and Turning Points
#  or
# The Second Derivative of the Hull Moving Average
#
# Author: Seth Urion (Mashume)
# Version: 2020-05-01 V4
#
# https://usethinkscript.com/threads/hull-moving-average-turning-points-and-concavity-2nd-derivatives.1803/
#

declare upper;

input price = close;
input HMA_Length = 21;
input lookback = 2;
input show_labels = Yes;
input stddev_len = 21;

plot 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;

plot turning_point = if concavity[1] != concavity then HMA else double.nan;

HMA.AssignValueColor(color = if concavity[1] == -1 then
    if HMA > HMA[1] then color.dark_orange else color.red else
    if HMA < HMA[1] then color.dark_green else color.green);

HMA.SetLineWeight(3);

turning_point.SetLineWeight(4);
turning_point.SetPaintingStrategy(paintingStrategy = PaintingStrategy.POINTS);
turning_point.SetDefaultColor(color.white);

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

plot MA_Min = if HMA[-1] > HMA and HMA < HMA[1] then HMA else Double.Nan;
MA_Min.SetDefaultColor(Color.WHITE);
MA_Min.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
MA_Min.SetLineWeight(3);

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(5);

plot buy = if turning_point and concavity == 1 then low else double.nan;
buy.SetDefaultColor(Color.CYAN);
buy.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
buy.SetLineWeight(5);

def divergence = HMA - next_bar;

addLabel(show_labels, concat("DIVERGENCE: " , divergence * 10000), color = if concavity < 0 then if divergence[1] > divergence then Color.dark_RED else color.PINK else if divergence[1] < divergence then color.dark_green else color.dark_orange);

def divergence_stddev = StandardDeviation(price = divergence, length = stddev_len);
addLabel(show_labels, concat("STDDEV: " , divergence_stddev * 10000), color = if absValue(divergence) > absValue(divergence_stddev) then color.blue else color.dark_gray);

# 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 HMA < HMA[1] then HMA else double.nan;
CCD_D.SetDefaultColor(Color.RED);
CCD_D.SetLineWeight(3);

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

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

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

######################################################
# New Code To Add Alerts For When Bar Colors Go From
# Red -> Dark Green -> Green (LONG) And When They Go
# Green -> Orange -> Red (SHORT).
######################################################

# GO back through the bars, find when the last Dark Green section
# started then see if the color before that was Red

Def RedToDarkGreen = fold idx5 = 1 to 100 with p5 = 0 do if !isNaN(GetValue(CCU_D,idx5)) && !isNaN(GetValue(CCD_D,idx5+1)) && p5 == 0 then idx5 else if !isNaN(GetValue(CCU_D,idx5)) && isNaN(GetValue(CCU_D,idx5+1)) && p5 == 0 then Double.NaN else p5;

# GO back through the bars, find when the last Orage section
# started then see if the color before that was Green

Def GreenToOrange = fold idx6= 1 to 100 with p6 = 0 do if !isNaN(GetValue(CCD_I,idx6)) && !isNaN(GetValue(CCU_I,idx6+1)) && p6 == 0 then idx6 else if !isNaN(GetValue(CCD_I,idx6)) && isNaN(GetValue(CCD_I,idx6+1)) && p6 == 0 then Double.NaN else p6;

# Long signal when last bar line color is Green, line color of the bar
# before that was Dark Green and the color before that was Red

Def RedToDarkGreenToGreen = CCU_I[1]&& CCU_D[2] && !isNaN(RedToDarkGreen);
alert(RedToDarkGreenToGreen, "RED TO DARK GREEN TO GREEN - GO LONG", alert.bar, sound.chimes);

# Short signal when last bar line color is Red, line color of the bar
# before that was Red and the color before that was Orange

Def GreenToOrangeToRed = CCD_D[1] && CCD_I[2] && !isNaN(GreenToOrange);
alert(GreenToOrangeToRed, "GREEN TO ORANGE TO RED - GO SHORT", alert.bar, sound.chimes);

######################################################
# END Code To Add Alerts For When Bar Colors Go From
# Red -> Dark Green -> Green (LONG) And When They Go
# Green -> Orange -> Red (SHORT).
######################################################


Thinkscript strategy code
Code: Select all
input price = close;
input HMA_Length = 21;
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 turning_point = if concavity[-1] != concavity then HMA else Double.NaN;

plot buy = if turning_point and concavity == -1 then low else double.nan;
buy.SetDefaultColor(Color.YELLOW);
buy.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
buy.SetLineWeight(5);

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(5);
Attachments
HMA-CONCAVE.JPG
Hull moving average (2).mq4
(13.94 KiB) Downloaded 178 times
goshme
 
Posts: 1
Joined: Tue Nov 30, 2021 12:15 pm

Re: Hull Moving Average Turning Points EA

Postby Apprentice » Thu Dec 02, 2021 9:06 am

Your request is added to the development list.
Development reference 1007.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia


Hull Moving Average Turning Points EA to Lua

Postby Gilles » Tue Apr 05, 2022 2:00 pm

Hi Apprentice,

Please, could you convert it to Lua version ?

Thank you very much.
Gilles.
Gilles
FXCodeBase: Initiate
 
Posts: 158
Joined: Tue Jul 31, 2018 8:28 am
Location: France

Re: Hull Moving Average Turning Points EA

Postby Apprentice » Wed Apr 06, 2022 9:48 am

Your request is added to the development list.
Development reference 208.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia



Return to Indicator and Signal Requests

Who is online

Users browsing this forum: Bing [Bot] and 22 guests