#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © MarkoP010 2023
#//Indicator plots user selectable Moving Average lines and a colored trend band between the MA lines. The trend bands can be turned off individually if required.
#//Trend pivot indicators are shown by selected risk level either when there is MA crossover with price (Leading MA Offset1 on Highest risk level, Lagging MA on Low risk level) or three bands with the same color at the same time (on Lowest risk level, Leading MA Offset1 crossover with Lagging MA). Pivot indicators can be turned off if required.
#//The Offset option shifts the selected MA with the set number of steps to the right. That is where the Magic happens and the Dragon roars!
#indicator("Flying Dragon Trend Indicator", shorttitle="Flying Dragon Trend Indicator", overlay=true)
# converted by Sam4Cok@Samer800 - 05/2023
#MA(source, length, type) =>
script MA {
input source = close;
input length = 20;
input type = "EMA";
def swma = source[3] * 1 / 6 + source[2] * 2 / 6 + source[1] * 2 / 6 + source[0] * 1 / 6;
def VWMA = Average(source * volume, length) / Average(volume, length);
def ma =
if type == "EMA" then ExpAverage(source, length) else
if type == "HMA" then HullMovingAvg(source, length) else
if type == "RMA" then WildersAverage(source, length) else
if type == "SMA" then Average(source, length) else
if type == "SWMA" then swma else
if type == "VWMA" then VWMA else
if type == "WMA" then WMA(source, length) else Double.NaN;
plot out = ma;
}
#//Indicator options
input riskLevel = {"Highest", "High", default "Medium", "Low", "Lowest"};# "Risk Level"
input indicatorsOn = yes; # "Indicators"
#//Inputs
input ma1Type = {"EMA", default "HMA", "RMA", "SMA", "SWMA", "VWMA", "WMA"}; # "Leading Moving Average 1"
input ma1Source = close;
input ma1Length = 35; # "Leading Moving Average 1"
input ma4Type = {"EMA", "HMA", "RMA", default "SMA", "SWMA", "VWMA", "WMA"}; # "Lagging Moving Average 4"
input ma4Source = close; # "Lagging Moving Average"
input ma4Length = 22; # "Lagging Moving Average"
input ma1Offset = 0; # "Offset1 Steps"
input ma2Offset = 4; # "Offset2 Steps"
input ma3Offset = 6; # "Offset3 Steps"
input ma4Offset = 2; # "Offset Steps"
input useBand1 = yes; # "Band 1"
input useBand2 = yes; # "Band 2"
input useBand3 = yes; # "Band 3"
def na = Double.NaN;
def last = isNaN(close);
def rHighest = riskLevel==riskLevel."Highest";
def rHigh = riskLevel==riskLevel."High";
def rMedium = riskLevel==riskLevel."Medium";
def rLow = riskLevel==riskLevel."Low";
def rLowest = riskLevel==riskLevel."Lowest";
def ma1 = MA(ma1Source, ma1Length, ma1Type)[ma1Offset];
def ma2 = ma1[ma2Offset];
def ma3 = ma1[ma3Offset];
def ma4 = MA(ma4Source, ma4Length, ma4Type)[ma4Offset];
def band1clr = ma1 > ma2;
def band2clr = ma1 > ma3;
def band3clr = ma1 > ma4;
#//Graphs
plot piirto1 = if last then na else ma1; # "MA1"
plot piirto2 = if last or useBand1 then na else ma2; # "MA2"
plot piirto3 = if last or useBand2 then na else ma3; # "MA3"
plot piirto4 = if last or useBand3 then na else ma4; # "MA4"
piirto1.SetLineWeight(2);
piirto1.AssignValueColor(if band3clr then Color.GREEN else Color.RED);#Color.MAGENTA);
piirto2.SetDefaultColor(Color.DARK_GREEN);
piirto3.SetDefaultColor(Color.VIOLET);
piirto4.SetDefaultColor(Color.PLUM);
AddCloud(if !useBand1 or last then na else ma1, ma2, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(if !useBand2 or last then na else ma1, ma3, Color.DARK_GREEN, Color.DARK_RED, yes);
AddCloud(if !useBand3 or last then na else ma1, ma4, Color.DARK_GREEN, Color.DARK_RED, yes);
#//Indicator plot conditions
def longCondition = if rHighest then ma1Source > ma1 else
if rHigh then ma1Source > ma2 else
if rMedium then ma1Source > ma3 else
if rLow then ma4Source > ma4 else
if rLowest then ma1 > ma4 else na;
def shortCondition = if rHighest then ma1Source < ma1 else
if rHigh then ma1Source < ma2 else
if rMedium then ma1Source < ma3 else
if rLow then ma4Source < ma4 else
if rLowest then ma1 < ma4 else na;
def pivotUp = if longCondition and shortCondition[1] and indicatorsOn then low else na;
def pivotDown = if shortCondition and longCondition[1] and indicatorsOn then high else na;
plot pUp = pivotUp; # "Up"
plot pDn = pivotDown; # "Down"
pUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
pDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
pUp.SetDefaultColor(Color.CYAN);
pDn.SetDefaultColor(Color.MAGENTA);
#--- END of CODE