I didn't test it. check it out.@samer800 , Just a couple of days ago I found out about this indicator in TV and using in my chart for evaluation and was wondering if it could be available in TOS.
#// This source code is subject to the terms of the Mozilla Public License 2.0 at
#// © LOKEN94
#// I made this indicator as a tribute to the late David Paul.
#// He mentioned quite a lot about 89 periods moving average, also the 21 and 55.
#indicator("Tribute to David Paul",shorttitle="MA",overlay=tr)
# converted by Sam4Cok@Samer800 - 09/2023
input IR =2;#,minval=-1,maxval=2,tooltip="If -1, no entries zone will be displayed.
input SDZ = yes;#,title="Show Supply & Demand zone",tooltip="Previous setting need to be set on 2.")
input MA = 4;#,minval=-1,maxval=5,title="Show ma",tooltip="If -1, no MA will be displayed.
input enableTrendColors = no;
def na = Double.NaN;
DefineGlobalColor("up", CreateColor(33,150,243));
DefineGlobalColor("dn", CreateColor(179, 52, 52));#CreateColor(255,82,82));
DefineGlobalColor("dup", CreateColor(19, 92, 151));
DefineGlobalColor("ddn", Color.DARK_RED);#CreateColor(155, 28, 28));
def ma21 = Average(close, 21);
def ma55 = Average(close, 55);
def ma89 = Average(close, 89);
def BULL = ma21 <= close and ma55 <= close and ma89 <= close;
def BEAR = ma21 > close and ma55 > close and ma89 > close;
#float lowest_ma=ma89
def lowest_ma = if ma21 <= ma55 and ma21 <= ma89 then ma21 else
if ma55 <= ma21 and ma55 <= ma89 then ma55 else ma89;
def highest_ma = if ma21 >= ma55 and ma21 >= ma89 then ma21 else
if ma55 >= ma21 and ma55 >= ma89 then ma55 else ma89;
#float IDEAL_LONG_ENTRY=na
def IDEAL_LONG_ENTRY = if BULL and !BULL[1] then low else IDEAL_LONG_ENTRY[1];
#float IDEAL_SHORT_ENTRY=na
def IDEAL_SHORT_ENTRY = if BEAR and !BEAR[1] then high else IDEAL_SHORT_ENTRY[1];
#float REAL_LONG_ENTRY=na
def REAL_LONG_ENTRY = if BULL and !BULL[1] then highest_ma else REAL_LONG_ENTRY[1];
#float REAL_SHORT_ENTRY=na
def REAL_SHORT_ENTRY = if BEAR and !BEAR[1] then lowest_ma else REAL_SHORT_ENTRY[1];
#--
def iLP = if IDEAL_LONG_ENTRY!=IDEAL_LONG_ENTRY[1] then na else Average(IDEAL_LONG_ENTRY, 1);
def iSP = if IDEAL_SHORT_ENTRY!=IDEAL_SHORT_ENTRY[1] then na else Average(IDEAL_SHORT_ENTRY, 1);
def rLP = if REAL_LONG_ENTRY!=REAL_LONG_ENTRY[1] then na else Average(REAL_LONG_ENTRY, 1);
def rSP = if REAL_SHORT_ENTRY!=REAL_SHORT_ENTRY[1] then na else Average(REAL_SHORT_ENTRY, 1);
def ilong = if BULL then iLP else na;#ilong[1];
def ishort = if BEAR then iSP else na;#ishort[1];
def rlong = if BULL then rLP else na;#rlong[1];
def rshort = if BEAR then rSP else na;#rshort[1];
plot botdemand = if IR==1 or IR==2 then ilong else na;#,"Ideal Long entry"
plot topsupply = if IR==1 or IR==2 then ishort else na;#,"Ideal Short entry"
plot topdemand = if IR==0 or IR==2 then rlong else na;#,"Real Long entry"
plot botsupply = if IR==0 or IR==2 then rshort else na;#,"Real Short entry"
botdemand.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
topsupply.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
topdemand.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
botsupply.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
botdemand.SetDefaultColor(GlobalColor("up"));
topsupply.SetDefaultColor(GlobalColor("dn"));
topdemand.SetDefaultColor(GlobalColor("up"));
botsupply.SetDefaultColor(GlobalColor("dn"));
AddCloud(if !SDZ then na else topdemand,botdemand, GlobalColor("up"), GlobalColor("up"));
AddCloud(if !SDZ then na else topsupply,botsupply,GlobalColor("dn"), GlobalColor("dn"));
#//
def ama = (ma21 + ma55 + ma89) / 3;
def AC = if close > ama then 1 else
if close < ama then -1 else AC[1];
#//
def FLAT = if AC==1 and AC[1]!=1 then ama else
if AC==-1 and AC[1]!=-1 then ama else FLAT[1];
#//
#float entries=rlong+rshort
def entries = if IR then ilong + ishort else rlong+rshort;
#//
def flat1_ = Average(FLAT,1);
def FLAT1 = if flat1_!=flat1_[1] then na else flat1_;
def col= if ama<=close then (if ilong==iLP then 2 else 1) else
(if ishort==iSP then -2 else -1);
plot amaLine = if MA==1 or MA==4 or MA==5 then ama else na;#,"AMA",color=ama<=close?color.rgb(0, 25, 45):color.rgb(10, 0, 0))
amaLine.AssignValueColor(if ama<=close then Color.CYAN else Color.MAGENTA);
def FA = FLAT1;# ,color=ama<=close?color.blue:color.red,style=plot.style_linebr,display=display.none,editable=false)
def FHL = hl2;#,display=display.none,editable=false)
AddCloud(if col==2 then FA else na,FHL, GlobalColor("up"), GlobalColor("up"));
AddCloud(if col==1 then FA else na,FHL, GlobalColor("dup"), GlobalColor("dup"));
AddCloud(if col==-2 then FA else na,FHL, GlobalColor("dn"), GlobalColor("dn"));
AddCloud(if col==-1 then FA else na,FHL, GlobalColor("ddn"), GlobalColor("ddn"));
#//
plot sma21 = if MA==0 or MA==4 then ma21 else na;
sma21.AssignValueColor(if ma21<=close then GlobalColor("up") else GlobalColor("dn"));
plot sma55 = if MA==0 or MA==4 or MA==5 then ma55 else na;
sma55.AssignValueColor(if ma55<=close then GlobalColor("up") else GlobalColor("dn"));
plot sma89 = if MA==0 or MA==4 then ma89 else na;
sma89.AssignValueColor(if ma89<=close then GlobalColor("up") else GlobalColor("dn"));
plot hiMa = if (MA==3 and (BULL==1 or ama<=close)) or (MA==2 and (BEAR==1 or ama>=close)) then highest_ma else na;
hiMa.AssignValueColor(if highest_ma<=close then GlobalColor("up") else GlobalColor("dn"));
plot loMa = if (MA==3 and (BEAR==1 or ama>=close)) or (MA==2 and (BULL==1 or ama<=close)) then lowest_ma else na;
loMa.AssignValueColor(if lowest_ma<=close then GlobalColor("up") else GlobalColor("dn"));
#-- Bar Color
def barCol = if ilong==iLP then 1 else
if ishort==iSP then -1 else
if !BULL and !BEAR then 0 else barCol[1];
AssignPriceColor(if !enableTrendColors then Color.CURRENT else
if barCol > 0 then Color.CYAN else
if barCol < 0 then Color.MAGENTA else Color.GRAY);
# -- END of CODE
Impressive !! thanks again for your work. I know Dr David Paul used this MAs technique for swing trading and the fact that allows for a much more flexible environment including custom scanning makes me consider to revisit his techniqueI didn't test it. check it out.
CSS:#// This source code is subject to the terms of the Mozilla Public License 2.0 at #// © LOKEN94 #// I made this indicator as a tribute to the late David Paul. #// He mentioned quite a lot about 89 periods moving average, also the 21 and 55. #indicator("Tribute to David Paul",shorttitle="MA",overlay=tr) # converted by Sam4Cok@Samer800 - 09/2023 input IR =2;#,minval=-1,maxval=2,tooltip="If -1, no entries zone will be displayed. input SDZ = yes;#,title="Show Supply & Demand zone",tooltip="Previous setting need to be set on 2.") input MA = 4;#,minval=-1,maxval=5,title="Show ma",tooltip="If -1, no MA will be displayed. input enableTrendColors = no; def na = Double.NaN; DefineGlobalColor("up", CreateColor(33,150,243)); DefineGlobalColor("dn", CreateColor(179, 52, 52));#CreateColor(255,82,82)); DefineGlobalColor("dup", CreateColor(19, 92, 151)); DefineGlobalColor("ddn", Color.DARK_RED);#CreateColor(155, 28, 28)); def ma21 = Average(close, 21); def ma55 = Average(close, 55); def ma89 = Average(close, 89); def BULL = ma21 <= close and ma55 <= close and ma89 <= close; def BEAR = ma21 > close and ma55 > close and ma89 > close; #float lowest_ma=ma89 def lowest_ma = if ma21 <= ma55 and ma21 <= ma89 then ma21 else if ma55 <= ma21 and ma55 <= ma89 then ma55 else ma89; def highest_ma = if ma21 >= ma55 and ma21 >= ma89 then ma21 else if ma55 >= ma21 and ma55 >= ma89 then ma55 else ma89; #float IDEAL_LONG_ENTRY=na def IDEAL_LONG_ENTRY = if BULL and !BULL[1] then low else IDEAL_LONG_ENTRY[1]; #float IDEAL_SHORT_ENTRY=na def IDEAL_SHORT_ENTRY = if BEAR and !BEAR[1] then high else IDEAL_SHORT_ENTRY[1]; #float REAL_LONG_ENTRY=na def REAL_LONG_ENTRY = if BULL and !BULL[1] then highest_ma else REAL_LONG_ENTRY[1]; #float REAL_SHORT_ENTRY=na def REAL_SHORT_ENTRY = if BEAR and !BEAR[1] then lowest_ma else REAL_SHORT_ENTRY[1]; #-- def iLP = if IDEAL_LONG_ENTRY!=IDEAL_LONG_ENTRY[1] then na else Average(IDEAL_LONG_ENTRY, 1); def iSP = if IDEAL_SHORT_ENTRY!=IDEAL_SHORT_ENTRY[1] then na else Average(IDEAL_SHORT_ENTRY, 1); def rLP = if REAL_LONG_ENTRY!=REAL_LONG_ENTRY[1] then na else Average(REAL_LONG_ENTRY, 1); def rSP = if REAL_SHORT_ENTRY!=REAL_SHORT_ENTRY[1] then na else Average(REAL_SHORT_ENTRY, 1); def ilong = if BULL then iLP else na;#ilong[1]; def ishort = if BEAR then iSP else na;#ishort[1]; def rlong = if BULL then rLP else na;#rlong[1]; def rshort = if BEAR then rSP else na;#rshort[1]; plot botdemand = if IR==1 or IR==2 then ilong else na;#,"Ideal Long entry" plot topsupply = if IR==1 or IR==2 then ishort else na;#,"Ideal Short entry" plot topdemand = if IR==0 or IR==2 then rlong else na;#,"Real Long entry" plot botsupply = if IR==0 or IR==2 then rshort else na;#,"Real Short entry" botdemand.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); topsupply.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); topdemand.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); botsupply.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); botdemand.SetDefaultColor(GlobalColor("up")); topsupply.SetDefaultColor(GlobalColor("dn")); topdemand.SetDefaultColor(GlobalColor("up")); botsupply.SetDefaultColor(GlobalColor("dn")); AddCloud(if !SDZ then na else topdemand,botdemand, GlobalColor("up"), GlobalColor("up")); AddCloud(if !SDZ then na else topsupply,botsupply,GlobalColor("dn"), GlobalColor("dn")); #// def ama = (ma21 + ma55 + ma89) / 3; def AC = if close > ama then 1 else if close < ama then -1 else AC[1]; #// def FLAT = if AC==1 and AC[1]!=1 then ama else if AC==-1 and AC[1]!=-1 then ama else FLAT[1]; #// #float entries=rlong+rshort def entries = if IR then ilong + ishort else rlong+rshort; #// def flat1_ = Average(FLAT,1); def FLAT1 = if flat1_!=flat1_[1] then na else flat1_; def col= if ama<=close then (if ilong==iLP then 2 else 1) else (if ishort==iSP then -2 else -1); plot amaLine = if MA==1 or MA==4 or MA==5 then ama else na;#,"AMA",color=ama<=close?color.rgb(0, 25, 45):color.rgb(10, 0, 0)) amaLine.AssignValueColor(if ama<=close then Color.CYAN else Color.MAGENTA); def FA = FLAT1;# ,color=ama<=close?color.blue:color.red,style=plot.style_linebr,display=display.none,editable=false) def FHL = hl2;#,display=display.none,editable=false) AddCloud(if col==2 then FA else na,FHL, GlobalColor("up"), GlobalColor("up")); AddCloud(if col==1 then FA else na,FHL, GlobalColor("dup"), GlobalColor("dup")); AddCloud(if col==-2 then FA else na,FHL, GlobalColor("dn"), GlobalColor("dn")); AddCloud(if col==-1 then FA else na,FHL, GlobalColor("ddn"), GlobalColor("ddn")); #// plot sma21 = if MA==0 or MA==4 then ma21 else na; sma21.AssignValueColor(if ma21<=close then GlobalColor("up") else GlobalColor("dn")); plot sma55 = if MA==0 or MA==4 or MA==5 then ma55 else na; sma55.AssignValueColor(if ma55<=close then GlobalColor("up") else GlobalColor("dn")); plot sma89 = if MA==0 or MA==4 then ma89 else na; sma89.AssignValueColor(if ma89<=close then GlobalColor("up") else GlobalColor("dn")); plot hiMa = if (MA==3 and (BULL==1 or ama<=close)) or (MA==2 and (BEAR==1 or ama>=close)) then highest_ma else na; hiMa.AssignValueColor(if highest_ma<=close then GlobalColor("up") else GlobalColor("dn")); plot loMa = if (MA==3 and (BEAR==1 or ama>=close)) or (MA==2 and (BULL==1 or ama<=close)) then lowest_ma else na; loMa.AssignValueColor(if lowest_ma<=close then GlobalColor("up") else GlobalColor("dn")); #-- Bar Color def barCol = if ilong==iLP then 1 else if ishort==iSP then -1 else if !BULL and !BEAR then 0 else barCol[1]; AssignPriceColor(if !enableTrendColors then Color.CURRENT else if barCol > 0 then Color.CYAN else if barCol < 0 then Color.MAGENTA else Color.GRAY); # -- END of CODE
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Start a new thread and receive assistance from our community.
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.
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.