DPO Mobo for ThinkorSwim

petergluis

Active member
ThinkorSwim provides FW_DPO_MoBo with the code. Here is my code for ThinkorSwim.

Ruby:
#https://www.tradingview.com/script/s2yv2eub-Mobo-Bands/
declare lower;
def price  = hl2;
def colorNormLength = 3;
def dpoLength       = 13;
def moboDisplace    = 0;
def moboLength    = 10;
input aggregationPeriod = AggregationPeriod.DAY;
def numDevDn  = -0.8;
def numDevUp  = 0.8;
script nz {
    input data = 0;
    def ret_val = if IsNaN(data) then 0 else data;
    plot return = ret_val;
}
def coloredMobo     = yes;
def coloredFill     =  yes;
def breakArrows     = yes;
def moboShowMid     = yes;


#def DPO = price - Average(price[DPO_length / 2 + 1], DPO_length);
def xsma = Average(price[dpoLength / 2 + 1], dpoLength);
#def xsma = sma(price, dpoLength);
def DPO = price - xsma;


def Midline = Average(DPO, moboLength);

def sDev = StDev(DPO, moboLength);

def LowerBand = Midline + numDevDn * sDev;
def UpperBand = Midline + numDevUp * sDev;

plot line_dpo = DPO;
line_dpo.AssignValueColor(if  line_dpo>  line_dpo[1] then Color.cyan else Color.red);
line_dpo.SetLineWeight(5);
plot Line_mid = Midline;
Line_mid.AssignValueColor(if MidLine < dpo then Color.green else Color.magenta);
Line_mid.SetLineWeight(3);

plot Upper = UpperBand;
Upper.SetDefaultColor(GetColor(7));
plot Lower = LowerBand;
lower.SetDefaultColor(GetColor(7));
plot line_0 = 0;
line_0.SetDefaultColor(GetColor(9));
def Signal1 = DPO > UpperBand and DPO[1] < UpperBand[1];
def Signal2 = DPO < LowerBand and DPO[1] > LowerBand[1];


def wasUp = if Signal1 then 1 else if Signal2 then 0 else nz(wasUp[1]);
def wasDn = if Signal2 then 1 else if Signal1 then 0 else nz(wasDn[1]);

plot plotshape1 = if Signal1 and wasDn[1] then UpperBand else Double.NaN;
plotshape1.SetDefaultColor(GetColor(1));
plot plotshape2 = if Signal2 and wasUp[1] then LowerBand else Double.NaN;
plotshape2.SetDefaultColor(GetColor(1));

AddCloud(Upper, Lower, Color.blue);
 

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
334 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