ApeX Predator
Well-known member
Nothing fancy, yet another MovingAverages, goal is to have flexibility. Following are the features of this custom script.
1) Allows a selection of MA of preference. ( SMA, EMA, HMA, Wilder and Weighted)
2) Depends on the MA Selection you may want to chance the price too.
3) Allows user to select MA plot between Chart frame or higher Frame, if selected Higher, one can select which higher frame too.
4) While, things like Volume and IV are selection, those are not meant for price area plots, Won't works as a upper chart indicator, so please stick with price selections that are relevant.
5) All arrow plots are not direction entry/exit alerts but the cross over direction,
6) Arrow Colors are co-ordinated to the MA plot color they are crossing.
1) Allows a selection of MA of preference. ( SMA, EMA, HMA, Wilder and Weighted)
2) Depends on the MA Selection you may want to chance the price too.
3) Allows user to select MA plot between Chart frame or higher Frame, if selected Higher, one can select which higher frame too.
4) While, things like Volume and IV are selection, those are not meant for price area plots, Won't works as a upper chart indicator, so please stick with price selections that are relevant.
5) All arrow plots are not direction entry/exit alerts but the cross over direction,
6) Arrow Colors are co-ordinated to the MA plot color they are crossing.
Ruby:
#CustomMA
#Author SuryaKiranC
#Version 1.0
# Goal is to create most flexible MovingAverage Indicaor for user to customize.
# Displace is set by default to 1, to avoid repainting. If you prefer current candle set displaced = 0
# For those who prefer smaller MA timeperiod length0 is defined but turned off by default.
# If you are using SMA Golden and Death Crosses are 50 Crossing 100 and 200, Yes according to few definition 50 Crossing 100 Golden/Death
# Arrow Colours are coordinated with the Lowest Configured Moving average Higer once. Not Directional.
input length0 = 9;
input ShowLenght0 = No;
input length1 = 21;
input length2 = 50;
input length3 = 100;
input length4 = 200;
input Displace = 0;
input price = FundamentalType.Close;
input AggregationType = {Chart, default Higher};
input HigherAggregation = AggregationPeriod.DAY;
input AverageType = AverageType.SIMPLE;
input HideArrows = No;
input ShowLabels = Yes;
def ap;
switch (AggregationType){
case Chart:
ap = GetAggregationPeriod();
case Higher:
ap = HigherAggregation;
}
DefineGlobalColor("MA0",Color.WHITE);
DefineGlobalColor("MA1",Color.GREEN);
DefineGlobalColor("MA2",Color.YELLOW);
DefineGlobalColor("MA3",Color.CYAN);
DefineGlobalColor("MA4",Color.PINK);
DefineGlobalColor("Labels",Color.WHITE);
def ma0 = MovingAverage(averageType,Fundamental(price,period = aP),length0);
def ma1 = MovingAverage(averageType,Fundamental(price,period = aP),length1);
def ma2 = MovingAverage(averageType,Fundamental(price,period = aP),length2);
def ma3 = MovingAverage(averageType,Fundamental(price,period = aP),length3);
def ma4 = MovingAverage(averageType,Fundamental(price,period = aP),length4);
def Cross0A1 = if ma0[-Displace] crosses above ma1[-Displace] then low else Double.NaN;
def Cross0B1 = if ma0[-Displace] crosses below ma1[-Displace] then high else Double.NaN;
def Cross1A2 = if ma1[-Displace] crosses above ma2[-Displace] then low else Double.NaN;
def Cross1B2 = if ma1[-Displace] crosses below ma2[-Displace] then high else Double.NaN;
def Cross2A3 = if ma2[-Displace] crosses above ma3[-Displace] then low else Double.NaN;
def Cross2B3 = if ma2[-Displace] crosses below ma3[-Displace] then high else Double.NaN;
def Cross2A4 = if ma2[-Displace] crosses above ma4[-Displace] then low else Double.NaN;
def Cross2B4 = if ma2[-Displace] crosses below ma4[-Displace] then high else Double.NaN;
AddLabel(ShowLabels,"AggrType: "+ AggregationType,GlobalColor("Labels"));
AddLabel(ShowLabels,"MA Type: "+if averageType == 0 then "S" else if averageType == 1 then "E" else if averageType == 2 then "WE" else if averageType == 3 then "WI" else "HU",GlobalColor("Labels"));
AddLabel(if AggregationType == AggregationType.Higher then 1 else 0, "HA :"+
if HigherAggregation == AggregationPeriod.MONTH then "M"
else if HigherAggregation == AggregationPeriod.WEEK then "W"
else if HigherAggregation == AggregationPeriod.FOUR_DAYS then "4D"
else if HigherAggregation == AggregationPeriod.THREE_DAYS then "3D"
else if HigherAggregation == AggregationPeriod.TWO_DAYS then "2D"
else if HigherAggregation == AggregationPeriod.DAY then "D"
else if HigherAggregation == AggregationPeriod.FOUR_HOURS then "4H"
else if HigherAggregation == AggregationPeriod.TWO_HOURS then "2H"
else if HigherAggregation == AggregationPeriod.HOUR then "60m"
else if HigherAggregation == AggregationPeriod.THIRTY_MIN then "30m"
else if HigherAggregation == AggregationPeriod.TWENTY_MIN then "20m"
else if HigherAggregation == AggregationPeriod.FIFTEEN_MIN then "15m"
else if HigherAggregation == AggregationPeriod.TEN_MIN then "10m"
else if HigherAggregation == AggregationPeriod.FIVE_MIN then "5m"
else if HigherAggregation == AggregationPeriod.FOUR_MIN then "4m"
else if HigherAggregation == AggregationPeriod.THREE_MIN then "3m"
else if HigherAggregation == AggregationPeriod.TWO_MIN then "2m"
else if HigherAggregation == AggregationPeriod.MIN then "1m"
else "",GlobalColor("Labels"));
AddLabel(ShowLenght0 and ShowLabels,"MA"+length0+": "+round(ma0,2)+" ",GlobalColor("MA0"));
AddLabel (ShowLabels,"MA"+length1+": "+round(ma1,2)+" ",GlobalColor("MA1"));
AddLabel (ShowLabels,"MA"+length2+": "+round(ma2,2)+" ",GlobalColor("MA2"));
AddLabel (ShowLabels,"MA"+length3+": "+round(ma3,2)+" ",GlobalColor("MA3"));
AddLabel (ShowLabels,"MA"+length4+": "+round(ma4,2)+" ",GlobalColor("MA4"));
plot m0 = ma0;
plot m1 = ma1;
plot m2 = ma2;
plot m3 = ma3;
plot m4 = ma4;
plot Arrow0A1 = Cross0A1;
plot Arrow0B1 = Cross0B1;
plot Arrow1A2 = Cross1A2;
plot Arrow1B2 = Cross1B2;
plot Arrow2A3 = Cross2A3;
plot Arrow2B3 = Cross2B3;
plot Arrow2A4 = Cross2A4;
plot Arrow2B4 = Cross2B4;
m0.SetDefaultColor(GlobalColor("MA0"));
m0.SetStyle(Curve.FIRM);
m0.SetHiding(!ShowLenght0);
m1.SetDefaultColor(GlobalColor("MA1"));
m1.SetStyle(Curve.FIRM);
m2.SetDefaultColor(GlobalColor("MA2"));
m2.SetStyle(Curve.FIRM);
m3.SetDefaultColor(GlobalColor("MA3"));
m3.SetStyle(Curve.FIRM);
m4.SetDefaultColor(GlobalColor("MA4"));
m4.SetStyle(Curve.FIRM);
Arrow0A1.SetDefaultColor(GlobalColor("MA1"));
Arrow0A1.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
Arrow0A1.SetLineWeight(3);
Arrow0A1.SetHiding(HideArrows or !ShowLenght0);
Arrow0B1.SetDefaultColor(GlobalColor("MA1"));
Arrow0B1.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
Arrow0B1.SetLineWeight(3);
Arrow0B1.SetHiding(HideArrows or !ShowLenght0);
Arrow1A2.SetDefaultColor(GlobalColor("MA2"));
Arrow1A2.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
Arrow1A2.SetLineWeight(3);
Arrow1A2.SetHiding(HideArrows);
Arrow1B2.SetDefaultColor(GlobalColor("MA2"));
Arrow1B2.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
Arrow1B2.SetLineWeight(3);
Arrow1B2.SetHiding(HideArrows);
Arrow2A3.SetDefaultColor(GlobalColor("MA3"));
Arrow2A3.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
Arrow2A3.SetLineWeight(3);
Arrow2A3.SetHiding(HideArrows);
Arrow2B3.SetDefaultColor(GlobalColor("MA3"));
Arrow2B3.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
Arrow2B3.SetLineWeight(3);
Arrow2B3.SetHiding(HideArrows);
Arrow2A4.SetDefaultColor(GlobalColor("MA4"));
Arrow2A4.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
Arrow2A4.SetLineWeight(3);
Arrow2A4.SetHiding(HideArrows);
Arrow2B4.SetDefaultColor(GlobalColor("MA4"));
Arrow2B4.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
Arrow2B4.SetLineWeight(3);
Arrow2B4.SetHiding(HideArrows);
Last edited: