#//@emohil
#strategy("Hull MA_X + Ichimoku Kinko Hyo Strategy", shorttitle="Hi",
# Converted by Sam4Cok@Samer800 - 01/2023 - Request from useThinkScript.com member
# tradingnumbers - added strategy
input LongShortLebel = yes;
input CloseLebel = yes;
input HullLength = 12; # "Double HullMA"
input TenkanSenPeriods = 9; # "Tenkan Sen Periods"
input KijunSenPeriods = 24; # "Kijun Sen Periods"
input SenkouSpanBPeriods = 51; # "Senkou Span B Periods"
input displacement = 24; # "Displacement"
input ShowHullLines = no;
input ShowTenkanSen = yes;
input ShowKijunSen = yes;
input ShowChikouSpan = no;
input ShowCloud = yes;
def na = Double.NaN;
def last = isNaN(Close);
def n1 = HullMovingAvg(close, HullLength);
def n2 = HullMovingAvg(close, HullLength)[1];
def b = n1 > n2;
#donchian(len) =>
script donchian {
input len = 24;
def ll = Lowest(low, len);
def hh = Highest(high, len);
def donchian = (hh + ll) / 2;
plot return = donchian;
}
def TenkanSen = donchian(TenkanSenPeriods);
def KijunSen = donchian(KijunSenPeriods);
def SenkouSpanA = (TenkanSen + KijunSen) / 2;
def SenkouSpanB = donchian(SenkouSpanBPeriods);
def SenkouSpanH = Max(SenkouSpanA[displacement - 1], SenkouSpanB[displacement - 1]);
def SenkouSpanL = Min(SenkouSpanA[displacement - 1], SenkouSpanB[displacement - 1]);
def ChikouSpan = close[displacement - 1];
def cross = crosses(n1, n2);
plot Hullfast = if last or !ShowHullLines then na else n1;
plot Hullslow = if last or !ShowHullLines then na else n2;
Hullfast.AssignValueColor(if b then Color.DARK_GREEN else Color.RED);
Hullslow.AssignValueColor(if b then Color.DARK_GREEN else Color.RED);
plot crossUp = if !ShowHullLines then na else if cross and b then (n1+n2)/2 else na;
crossUp.SetPaintingStrategy(PaintingStrategy.POINTS);
crossUp.SetDefaultColor(Color.CYAN);
crossUp.SetLineWeight(4);
plot crossDn = if !ShowHullLines then na else if cross and !b then (n1+n2)/2 else na;
crossDn.SetPaintingStrategy(PaintingStrategy.POINTS);
crossDn.SetDefaultColor(Color.MAGENTA);
crossDn.SetLineWeight(4);
plot TenkanSenLine = if !ShowTenkanSen then na else TenkanSen; # "Tenkan Sen"
TenkanSenLine.SetLineWeight(2);
TenkanSenLine.SetDefaultColor(Color.BLUE);
plot KijunSenLine = if !ShowKijunSen then na else KijunSen; # "Kijun Sen"
KijunSenLine.SetLineWeight(2);
KijunSenLine.SetDefaultColor(CreateColor(136,0,0));
plot ChikouSpanLine = if !ShowChikouSpan then na else close[-displacement]; # "Chikou Span"
ChikouSpanLine.SetDefaultColor(Color.GRAY);
def SpanA = SenkouSpanA[displacement]; # "Senkou Span A"
def SpanB = SenkouSpanB[displacement]; # "Senkou Span B"
AddCloud(if !ShowCloud then na else SpanA, SpanB, Color.DARK_GREEN, Color.DARK_RED);
def longCon = n1>n2 and close>n2 and close>ChikouSpan and close>SenkouSpanH and (TenkanSen>=KijunSen or close>KijunSen);
def shortCon = n1<n2 and close<n2 and close<ChikouSpan and close<SenkouSpanL and (TenkanSen<=KijunSen or close<KijunSen);
def closelong = n1<n2 and (close<n2 or TenkanSen<KijunSen or close<TenkanSen or close<KijunSen or close<SenkouSpanH or close<ChikouSpan);
def closeshort = n1>n2 and (close>n2 or TenkanSen>KijunSen or close>TenkanSen or close>KijunSen or close>SenkouSpanL or close>ChikouSpan);
def dirB; def dirS;
if longCon {
dirB = yes;
dirS = no;
} else
if shortCon {
dirB = no;
dirS = yes;
} else {
dirB = dirB[1];
dirS = dirS[1];
}
def closeB; def closeS;
if closelong and dirB {
closeB = yes;
closeS = no;
} else
if closeshort and dirS {
closeB = no;
closeS = yes;
} else {
closeB = closeB[1];
closeS = closeS[1];
}
AddChartBubble(LongShortLebel and dirB and !dirB[1] and longCon, low, "Long", Color.GREEN, no);
AddChartBubble(LongShortLebel and dirS and !dirS[1] and shortCon, high, "Short", Color.RED, yes);
AddChartBubble(CloseLebel and closeB and !closeB[1] and closelong, high, "Close", Color.DARK_GREEN, yes);
AddChartBubble(CloseLebel and closeS and !closeS[1] and closeshort, low, "Close", Color.DARK_RED, no);
addOrder(OrderType.BUY_TO_OPEN, dirB and !dirB[1] and longCon);
addOrder(OrderType.SELL_TO_CLOSE, closeB and !closeB[1] and closelong);
addOrder(OrderType.SELL_TO_OPEN, dirS and !dirS[1] and shortCon);
addOrder(OrderType.BUY_TO_CLOSE, closeS and !closeS[1] and closeshort);
#----END CODE--