Script to plot horizontal line at moving average crossover

J

jmtraderguy

New member
First-time poster, long time lurker.
I am NOT a coder by any means, I have attempted to modify/create a script to plot horizontal dashes or points at moving average crossovers. The original thinkorswim indicator plotted an up arrow at the crossover on the chart. I am wanting to have it display a horizontal dashed line or points instead. This is what I have tried but is not successful. I am sure it is not complete or I am missing something key. Any help would be much appreciated.
Thanks,
Code:
#
input price = close;
input length1 = 15;
input length2 = 30;
input averageType1 = AverageType.SIMPLE;
input averageType2 = AverageType.SIMPLE;
input crossingType = {default above, below};

def avg1 = MovingAverage(averageType1, price, length1);
def avg2 = MovingAverage(averageType2, price, length2);

plot signal = Crosses(avg1, avg2, crossingType == crossingType.above);

signal.DefineColor("Above", GetColor(6));
signal.DefineColor("Below", GetColor(7));
signal.AssignValueColor(if crossingType == crossingType.above then signal.Color("Above") else signal.Color("Below"));

signal.SetPaintingStrategy(if crossingType == crossingType.above
    then PaintingStrategy.DASHES
    else PaintingStrategy.DASHES);

signal.SetPaintingStrategy(PaintingStrategy.DASHES);
#-------------------------------------
 
BenTen

BenTen

Administrative
Staff
VIP
You want to display a point on top/bottom of the candle like this?

 
rad14733

rad14733

Active member
VIP
@BenTen, jmtraderguy wants to plot a line similar to a support/resistance line at the crossover price... At least that's how I'm interpreting his request...
 
J

jmtraderguy

New member
@BenTen @rad14733 is correct. Looking for points, or lines similar to s/r or like the points on the Mobius ECI.
 
T

Trading51

Active member
2019 Donor
@BenTen Ben could you post the dots code or include it with the support/Resis dots as a feature thanks
 
Welkin

Welkin

Active member
VIP
@jmtraderguy try this

Code:
#
input price = close;
input length1 = 15;
input length2 = 30;
input averageType1 = AverageType.SIMPLE;
input averageType2 = AverageType.SIMPLE;
input crossingType = {default above, below};

plot avg1 = MovingAverage(averageType1, price, length1);
plot avg2 = MovingAverage(averageType2, price, length2);
def sigtest;
switch(crossingType){
case above:
sigtest = avg1 crosses above avg2;
case below:
sigtest = avg1 crosses below avg2;
}

def sigline = if sigtest then (avg1+avg2)/2 else if sigtest[1] and !sigtest then (avg1[1]+avg2[1])/2 else sigline[1];
plot signal = sigline;
signal.DefineColor("Above", GetColor(6));
signal.DefineColor("Below", GetColor(7));
signal.AssignValueColor(if crossingType == crossingType.above then signal.Color("Above") else signal.Color("Below"));

signal.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

#-------------------------------------
 
MerryDay

MerryDay

Member
VIP
@Welkin,
I am the head of your fan club. I utilize 90% of what you have published on a daily basis.
Thank you SO much for the time and effort that you put into what you share with us!
 
Welkin

Welkin

Active member
VIP
@Welkin,
I am the head of your fan club. I utilize 90% of what you have published on a daily basis.
Thank you SO much for the time and effort that you put into what you share with us!
Thank you, really appreciate the kind words, and glad you've found use for my scripts!
 
T

Trading51

Active member
2019 Donor
@Welkin Hello thanks for the code on the input "above or B below" could you add both so the line is plotted for both verse only having the option for one, cheers/
 
J

jmtraderguy

New member
@Welkin Thank you so much! This is exactly what I was trying to accomplish. Thank you for your help on this.
 
Welkin

Welkin

Active member
VIP
@Welkin Hello thanks for the code on the input "above or B below" could you add both so the line is plotted for both verse only having the option for one, cheers/
apply the indicator to your chart twice and have one set to above and one to below
 
T

Trading51

Active member
2019 Donor
any way for someone to add an input so we can use just one code for the line for an upward cross and a line for the downward cross right now we can only choose one side could someone help out thanks
 

Similar threads

Top