Custom Moving Average For ThinkOrSwim

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.
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:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Is there any way to plot an arrow when a moving average close crosses another moving average low? So you would basically have the option to add high, low or close to each individual ma and then plot an arrow on the cross.

Thanks.
 
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.
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 = 1;
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[1],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);
@SuryaKiranC : Thank you. The MA values looks different close of 12/2 from what being published in equity clock. What should I do to get the same values as published by equity clock?

Can you please check

http://equityclock.com/pictures/Stock-Market-Outlook-December-2-2021_B172/image.png
 
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.
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 = 1;
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[1],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);
@SuryaKiranC : Is it possible to draw horizontal prices lines for 20/50/100/150/200 SMA lines as of yesterdays close? I have it as labels but for scalping having them as horizontal price lines makes it much easier.
 
@profitmaya Grab the updated code, I set the displaced to "0" I was fooling around with that idea of keeping that static through out the day, by tracking the the data of closed candle.

-S
 
@profitmaya Grab the updated code, I set the displaced to "0" I was fooling around with that idea of keeping that static through out the day, by tracking the the data of closed candle.

-S
@SuryaKiranC Thank you so much. Is it possible to have them as price levels ( aka horizontal lines ) at the beginning of each day? Instead of displaying it as labels, I want price shown on the labels as horizontal lines at the beginning of each day and do not change for that day.
 
@profitmaya Hope this is what you are looking for.

Ruby:
#CustomMAHorizantal
#Author SuryaKiranC 2021-Dec-03
#Version 1.0
# Goal is to create most flexible MovingAverage Indicaor for user to customize.
#   

declare hide_on_daily;

input anchorTimeEST = 0930;

def atStartTime = if secondsFromTime(anchorTimeEST) >= 0 and secondsFromTime(anchorTimeEST)[1] < 0 or (secondsFromTime(anchorTimeEST) >= 0 and secondsFromTime(anchorTimeEST)[1] >= 0 and getDay() != getDay()[1]) then 1 else 0;

input     length0 = 9;
input ShowLenght0 = No;
input     length1 = 21;
input     length2 = 50;
input     length3 = 100;
input     length4 = 200;
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);

AddLabel(ShowLabels,"AggrType: "+ AggregationType,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(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(ShowLenght0 and ShowLabels,"MA"+length0+": "+round(ma0,2)+if ma0 > ma0[1] then "(R)" else "(F)"+" ",GlobalColor("MA0"));
AddLabel                (ShowLabels,"MA"+length1+": "+round(ma1,2)+if ma1 > ma1[1] then "(R)" else "(F)"+" ",GlobalColor("MA1"));
AddLabel                (ShowLabels,"MA"+length2+": "+round(ma2,2)+if ma2 > ma2[1] then "(R)" else "(F)"+" ",GlobalColor("MA2"));
AddLabel                (ShowLabels,"MA"+length3+": "+round(ma3,2)+if ma3 > ma3[1] then "(R)" else "(F)"+" ",GlobalColor("MA3"));
AddLabel                (ShowLabels,"MA"+length4+": "+round(ma4,2)+if ma4 > ma4[1] then "(R)" else "(F)"+" ",GlobalColor("MA4"));

plot m0 = ma0;
plot m1 = ma1;
plot m2 = ma2;
plot m3 = ma3;   
plot m4 = ma4; 

m0.SetDefaultColor(GlobalColor("MA0"));
m0.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
m0.SetHiding(!ShowLenght0);

m1.SetDefaultColor(GlobalColor("MA1"));
m1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

m2.SetDefaultColor(GlobalColor("MA2"));
m2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

m3.SetDefaultColor(GlobalColor("MA3"));
m3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

m4.SetDefaultColor(GlobalColor("MA4"));
m4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
 
@profitmaya Hope this is what you are looking for.

Ruby:
#CustomMAHorizantal
#Author SuryaKiranC 2021-Dec-03
#Version 1.0
# Goal is to create most flexible MovingAverage Indicaor for user to customize.
#  

declare hide_on_daily;

input anchorTimeEST = 0930;

def atStartTime = if secondsFromTime(anchorTimeEST) >= 0 and secondsFromTime(anchorTimeEST)[1] < 0 or (secondsFromTime(anchorTimeEST) >= 0 and secondsFromTime(anchorTimeEST)[1] >= 0 and getDay() != getDay()[1]) then 1 else 0;

input     length0 = 9;
input ShowLenght0 = No;
input     length1 = 21;
input     length2 = 50;
input     length3 = 100;
input     length4 = 200;
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);

AddLabel(ShowLabels,"AggrType: "+ AggregationType,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(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(ShowLenght0 and ShowLabels,"MA"+length0+": "+round(ma0,2)+if ma0 > ma0[1] then "(R)" else "(F)"+" ",GlobalColor("MA0"));
AddLabel                (ShowLabels,"MA"+length1+": "+round(ma1,2)+if ma1 > ma1[1] then "(R)" else "(F)"+" ",GlobalColor("MA1"));
AddLabel                (ShowLabels,"MA"+length2+": "+round(ma2,2)+if ma2 > ma2[1] then "(R)" else "(F)"+" ",GlobalColor("MA2"));
AddLabel                (ShowLabels,"MA"+length3+": "+round(ma3,2)+if ma3 > ma3[1] then "(R)" else "(F)"+" ",GlobalColor("MA3"));
AddLabel                (ShowLabels,"MA"+length4+": "+round(ma4,2)+if ma4 > ma4[1] then "(R)" else "(F)"+" ",GlobalColor("MA4"));

plot m0 = ma0;
plot m1 = ma1;
plot m2 = ma2;
plot m3 = ma3;  
plot m4 = ma4;

m0.SetDefaultColor(GlobalColor("MA0"));
m0.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
m0.SetHiding(!ShowLenght0);

m1.SetDefaultColor(GlobalColor("MA1"));
m1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

m2.SetDefaultColor(GlobalColor("MA2"));
m2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

m3.SetDefaultColor(GlobalColor("MA3"));
m3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

m4.SetDefaultColor(GlobalColor("MA4"));
m4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
@SuryaKiranC : Thank you so much. Looking for a minor enhancement to add price and a comment on each horizontal like the image below. If that's tough, please ignore.


lZbOWKu.png



Apart from these, Is there any script that I can find to draw prior day high/low/close, prior week high/low/close drawn same as the horizontal lines like above along with a comment and price on top of each line? This helps a lot for me in a day trade as most of the stocks respect these lines.
 
On the Tick chart, if I change the higher aggregation to a shorter than D period, the labels disappear. Why does only the D above on the Tick chart work?
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
292 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

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.

How do I get started?

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.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top