Price Direction Indicators for ThinkorSwim

WbKiki

New member
I tried to make a staircase-esque MA, it didn't quite turn out. This was done using some other price direction indicator I made.
Anyways, here's what I came up with, if you want to help and fix the MA to work on lower time frames, it would be much appreciated.

Upper Indicator - MA
Ruby:
# Price Direction AVG indicator - does not look well on larger time frames

declare upper;

def price = close;
input averagetype = averagetype.exponential;
input length = 15;
def close = movingaverage(averagetype, price, length);
def simp = .975+(.05*((close - Lowest(close, 2)) / (Highest(close, 2) - Lowest(close, 2)))); # This is where the problem lies - could be changed to closer represent price change and not just a percentage
plot main = simp*close;

input weight_length = 15;

def l = lowest(main,weight_length);
def h = highest(main,weight_length);

input avg_weight = 20;

plot avg = (main+((avg_weight/2)*l)+((avg_weight/2)*h))/(avg_weight+1);

plot m = (avg+main)/2;
m.hide();

AddCloud(m,avg,createcolor(102,255,102),createcolor(255,102,102));
AddCloud(main,m, createcolor(0,200,0),createcolor(255,0,0));

Lower Indicator - Price Direction
Ruby:
# Trend Direction Indicator
# Colors explained:
#    Green - the brighter this is, the stronger the uptrend
#    Red - the brighter this is, the stronger the downtrend
#    Cyan - if this appears there is a possibility of a stronger uptrend in the near future

declare lower;

input averagetype = AverageType.EXPONENTIAL;
input length1 = 150;
input length2 = 125;
input length3 = 100;
input length4 = 75;
input length5 = 50;
input displace = 0;
input averagetype2 = averagetype.exponential;
input l2 = 200;
input ColorBars = yes;

def price_avg1 = MovingAverage(averagetype, close, length1);
def price_avg2 = MovingAverage(averagetype, close, length2 * .8);
def price_avg3 = MovingAverage(averagetype, close, length3 * .6);
def price_avg4 = MovingAverage(averagetype, close, length4 * .4);
def price_avg5 = MovingAverage(averagetype, close, length5 * .2);
def st1 = 50 * (price_avg1 - (Lowest(price_avg1))) / (Highest(price_avg1) - Lowest(price_avg1));
def st2 = 50 * (price_avg2 - (Lowest(price_avg2))) / (Highest(price_avg2) - Lowest(price_avg2));
def st3 = 50 * (price_avg3 - (Lowest(price_avg3))) / (Highest(price_avg3) - Lowest(price_avg3));
def st4 = 50 * (price_avg4 - (Lowest(price_avg4))) / (Highest(price_avg4) - Lowest(price_avg4));
def st5 = 50 * (price_avg5 - (Lowest(price_avg5))) / (Highest(price_avg5) - Lowest(price_avg5));

def p1 = (st1 - Sin(st1));
def p2 = (p1 - Sin(p1));
def p3 = (p2 - Sin(p2));
def p4 = (p3 - Sin(p3));
def p5 = (p4 - Sin(p4));
def p6 = (p5 - Sin(p5));
def p7 = (p6 - Sin(p6));
def p8 = (p7 - Sin(p7));
def p9 = (p8 - Sin(p8));

def j1 = (st2 - Sin(st2));
def j2 = (j1 - Sin(j1));
def j3 = (j2 - Sin(j2));
def j4 = (j3 - Sin(j3));
def j5 = (j4 - Sin(j4));
def j6 = (j5 - Sin(j5));
def j7 = (j6 - Sin(j6));
def j8 = (j7 - Sin(j7));
def j9 = (j8 - Sin(j8));

def g1 = (st3 - Sin(st3));
def g2 = (g1 - Sin(g1));
def g3 = (g2 - Sin(g2));
def g4 = (g3 - Sin(g3));
def g5 = (g4 - Sin(g4));
def g6 = (g5 - Sin(g5));
def g7 = (g6 - Sin(g6));
def g8 = (g7 - Sin(g7));
def g9 = (g8 - Sin(g8));

def wm1 = (st4 - Sin(st4));
def wm2 = (wm1 - Sin(wm1));
def wm3 = (wm2 - Sin(wm2));
def wm4 = (wm3 - Sin(wm3));
def wm5 = (wm4 - Sin(wm4));
def wm6 = (wm5 - Sin(wm5));
def wm7 = (wm6 - Sin(wm6));
def wm8 = (wm7 - Sin(wm7));
def wm9 = (wm8 - Sin(wm8));

def pd1 = (st5 - Sin(st5));
def pd2 = (pd1 - Sin(pd1));
def pd3 = (pd2 - Sin(pd2));
def pd4 = (pd3 - Sin(pd3));
def pd5 = (pd4 - Sin(pd4));
def pd6 = (pd5 - Sin(pd5));
def pd7 = (pd6 - Sin(pd6));
def pd8 = (pd7 - Sin(pd7));
def pd9 = (pd8 - Sin(pd8));

plot main1 = (p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9) / 9;
main1.AssignValueColor(Color.RED);
main1.SetLineWeight(1);
plot main2 = (j1 + j2 + j3 + j4 + j5 + j6 + j7 + j8 + j9) / 9;
main2.AssignValueColor(Color.CYAN);
main2.SetLineWeight(1);
plot main3 = (g1 + g2 + g3 + g4 + g5 + g6 + g7 + g8 + g9) / 9;
main3.AssignValueColor(Color.BLACK);
main3.SetLineWeight(1);
plot main4 = (wm1 + wm2 + wm3 + wm4 + wm5 + wm6 + wm7 + wm8 + wm9) / 9;
main4.AssignValueColor(Color.WHITE);
main4.SetLineWeight(1);
plot main5 = (pd1 + pd2 + pd3 + pd4 + pd5 + pd6 + pd7 + pd8 + pd9) / 9;
main5.AssignValueColor(Color.BLUE);
main5.SetLineWeight(1);

plot midline = (highestall(main1)+lowestall(main1))/2;
midline.assignvaluecolor(color.black);

def up1 = main1[1] < main1 or main1==highestall(main1);
def d1 = main1[1] > main1 or main1<=midline;
def up2 = main2[1] < main2 or main2==highestall(main2);
def d2 = main2[1] < main2 or main2<=midline;
def up3 = main3[1] < main3 or main3==highestall(main3);
def d3 = main3[1] > main3 or main3<=midline;
def up4 = main4[1] < main4 or main4==highestall(main4);
def d4 = main4[1] > main4 or main4<=midline;
def up5 = main5[1] < main5 or main5==highestall(main5);
def d5 = main5[1] > main5 or main5<=midline;

def uval = up1 + up2 + up3 + up4 + up5;
def dval = -1*(d1 + d2 + d3 + d4 + d5);
def t = uval+dval;
def tval = t[displace];

Addlabel (yes, tval, color.black);
AddLabel( tval==5, "Strong Up-Trend" , Color.GREEN);
AddLabel(tval==4,"Good Up-Trend", color.light_green);
addlabel(tval==3, "Trending Up", color.yellow);
addlabel(tval==2, "Weak Trend Up", color.blue);
addlabel(tval==1, "Bad Trend Up", color.red);
addlabel(tval==0, "No Trend", color.light_red);
addlabel(tval==-1, "Bad Trend Down", color.red);
addlabel(tval==-2, "Weak Trend Down", color.blue);
addlabel(tval==-3, "Trending Down", color.yellow);
addlabel(tval==-4, "Good Down Trend", color.light_green);
addlabel(tval==-5, "Strong Trend Down", Color.GREEN);

assignpricecolor(if tval==5 and ColorBars then createcolor(0,255,0) else if tval==4 and ColorBars then createcolor(0,220,0) else if tval==3 and ColorBars then createcolor(0,190,0) else if tval==2 and ColorBars then createcolor(0,160,0) else if tval==1 and ColorBars then createcolor(51,100,0) else if tval==0 and movingaverage(averagetype.exponential, close, 9)[5] < close then color.cyan else if tval==0 and ColorBars then color.black else if tval==-1 and ColorBars then createcolor(100,51,0) else if tval==-2 and ColorBars then createcolor(160,0,0) else if tval==-3 and ColorBars then createcolor(190,0,0) else if tval==-4 and ColorBars then createcolor(220,0,0) else if tval==-5 and ColorBars then createcolor(255,0,0) else color.CURRENT);

def PrimaryAverage = movingaverage(averagetype2, (main1+main2+main3+main4+main5)/5, l2);
def PrimaryDerivative = (midline+(50*(primaryaverage[0]-primaryaverage[1])/2));
plot primavg = (primaryaverage+primaryderivative)/2;
primavg.assignvaluecolor(color.black); primavg.setlineweight(1);
plot trail2 = movingaverage(averagetype.exponential, primavg, 100);
plot trail = movingaverage(averagetype.exponential, primavg, 200);
trail.hide();trail2.hide();primavg.hide();midline.hide();
plot quality = tval; quality.hide();

4FuXdzB.png

NErCPPf.png
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
431 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