#//𝒦𝑒𝒶𝓃𝓊_𝑅𝒾𝒯𝓏 PowerOfStocks_5EMA Code Start - Keanu_RiTz//
#// This source code is subject to the terms of the Mozilla Public License 2.0 at ht
#// © Keanu_ritz
#indicator(title='PowerOfStocks_5EMA_-_𝒦𝑒𝒶𝓃𝓊_𝑅𝒾𝒯𝓏', overlay=true)
# Converted by Sam4Cok@Samer800 - 10 / 2023
input MovAvgType = AverageType.EXPONENTIAL;
input source = close;
input movAvgLength = 5;
input EnableExtraStoplossShownBelow = no; # "Enable the Extra SL shown below"
input NumberOfPointsBelowLowOrAboveHigh = 5; # 'Value to set SL number of points below-low or above-high'
input RiskToRewardRatio = 3; # 'Risk to Reward Ratio'
input ShowSellSignals = yes; # 'Show Sell Signals'
input ShowBuySignals = no; # 'Show Buy Signals'
input tradeWithExtraCondition = no;
def na = Double.NaN;
def last = isNaN(Close);
def Eusl = EnableExtraStoplossShownBelow;
def usl = NumberOfPointsBelowLowOrAboveHigh;
def BSWCon = tradeWithExtraCondition;
def RiRe = RiskToRewardRatio;
def ema5 = MovingAverage(MovAvgType, source, movAvgLength);
plot pema5 = ema5;#, '5 Ema'
pema5.SetDefaultColor(Color.CYAN);
def shortC;
def ssl;
def star;
def lsl;
def ltar;
def ltarhitC;
def longC;
def sslhitC;
def starhitC;
def lslhitC;
def sellat;
def lssl;
def starl;
def lstar;
def lsell;
def lssllbl;
def lstarlbl;
def lselllbl;
def ShortWC = low[1] > ema5[1] and low[1] > low and shortC[1] == 0 and close < close[1];
def ShortWOC = low[1] > ema5[1] and low[1] > low and shortC[1] == 0;
def Short = if BSWCon then ShortWC else ShortWOC;
def sslhit = high > ssl[1] and shortC[1] > 0 and sslhitC[1] == 0;
def starhit = low < star[1] and shortC[1] > 0 and starhitC[1] == 0;
def LongWC = high[1] < ema5[1] and high[1] < high and longC[1] == 0 and close > close[1];
def LongWOC = high[1] < ema5[1] and high[1] < high and longC[1] == 0;
def Long = if BSWCon then LongWC else LongWOC;
def lslhit = low < lsl[1] and longC[1] > 0 and lslhitC[1] == 0;
def ltarhit = high > ltar[1] and longC[1] > 0 and ltarhitC[1] == 0;
if Short and ShowSellSignals {
shortC = shortC[1] + 1;
sslhitC = 0;
starhitC = 0;
if Eusl {
ssl = high[1] + usl;
starl = if BSWCon then ((high[1] - source) + usl) * RiRe else ((high[1] - low[1]) + usl) * RiRe;
} else {
ssl = high[1];
starl = if BSWCon then (high[1] - source) * RiRe else (high[1] - low[1]) * RiRe;
}
star = if BSWCon then source - starl else low[1] - starl;
sellat = if BSWCon then source else low[1];
lssl = ssl;
lstar = star;
lsell = sellat;
lssllbl = ssl;
lstarlbl = star;
lselllbl = sellat;
} else {
ssl = ssl[1];
starl = starl[1];
star = star[1];
sellat = sellat[1];
lssl = lssl[1];
lstar = lstar[1];
lsell = lsell[1];
lssllbl = na;
lstarlbl = na;
lselllbl = na;
if sslhit == no and starhit == no and shortC[1] > 0 {
shortC = shortC[1];
sslhitC = 0;
starhitC = 0;
} else {
if sslhit {
shortC = 0;
sslhitC = sslhitC[1] + 1;
starhitC = starhitC[1];
} else
if starhit {
shortC = 0;
starhitC = starhitC[1] + 1;
sslhitC = sslhitC[1];
} else {
shortC = shortC[1];
starhitC = starhitC[1];
sslhitC = sslhitC[1];
}
}
}
def ltarl;def buyat;def llsl;def lltar;def lbuy;
def llsllbl;def lltarlbl;def lbuylbl;
if Long and ShowBuySignals {
longC = longC[1] + 1;
lslhitC = 0;
ltarhitC = 0;
if Eusl {
lsl = low[1] - usl;
ltarl = if BSWCon then ((source - low[1]) + usl) * RiRe else ((high[1] - low[1]) + usl) * RiRe;
} else {
lsl = low[1];
ltarl = if BSWCon then (source - low[1]) * RiRe else (high[1] - low[1]) * RiRe;
}
ltar = if BSWCon then source + ltarl else high[1] + ltarl;
buyat = if BSWCon then source else high[1];
llsl = lsl;
lltar = ltar;
lbuy = buyat;
llsllbl = lsl;
lltarlbl = ltar;
lbuylbl = buyat;
} else {
lsl = lsl[1];
ltarl = ltarl[1];
ltar = ltar[1];
buyat = buyat[1];
llsl = llsl[1];
lltar = lltar[1];
lbuy = lbuy[1];
llsllbl = na;
lltarlbl = na;
lbuylbl = na;
if lslhit == no and ltarhit == no and longC[1] > 0 {
longC = longC[1];
lslhitC = 0;
ltarhitC = 0;
} else {
if lslhit {
longC = 0;
lslhitC = lslhitC[1] + 1;
ltarhitC = ltarhitC[1];
} else
if ltarhit {
longC = 0;
ltarhitC = ltarhitC[1] + 1;
lslhitC = lslhitC[1];
} else {
longC = longC[1];
ltarhitC = ltarhitC[1];
lslhitC = lslhitC[1];
}
}}
AddChartBubble(lbuylbl, low, "B", Color.GREEN, no);
AddChartBubble(lselllbl, high, "S", Color.RED);
plot lssl1 = if !last and lssl then lssl else na;
plot lstar1 = if !last and lstar then lstar else na;
plot lsell1 = if !last and lsell then lsell else na;
plot llsl1 = if !last and llsl then llsl else na;
plot lltar1 = if !last and lltar then lltar else na;
plot lbuy1 = if !last and lbuy then lbuy else na;
lssl1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
lstar1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
lsell1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
llsl1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
lltar1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
lbuy1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
lssl1.SetDefaultColor(Color.DARK_RED);
lstar1.SetDefaultColor(Color.DARK_GREEN);
lsell1.SetDefaultColor(Color.GRAY);
llsl1.SetDefaultColor(Color.DARK_RED);
lltar1.SetDefaultColor(Color.DARK_GREEN);
lbuy1.SetDefaultColor(Color.GRAY);
#-- END of CODE