ToS Detrended Price Oscillator

stanhi

New member
Hi, I have been trying for hours but have been unable to modify an indicator to get the signal arrows in the same screen with the indicator. When I try to add the arrows the indicator height listing goes from number to percentages. I also want to restrict the down signal arrows to only occur if the indicator turns from going up to down if it turns above the 75% line. And arrow signals from below if it turns up from below the 25% line. I would be satisfied if I couldn do just one side. The difficulty is do to TOS turning the indicator to percentages. I am try to do this for a number of indicators. But if I can see the code for one I should be able to do the others. I have include a sample of what I would like. The sample of the screen showing what is would like is hand drawn and not from any actual code.
Code:
#
# TD Ameritrade IP Company, Inc. (c) 2007-2021
# Detrended Price Oscillator

declare lower;

input colorNormLength = 14;
input length = 14;
input price = close;

plot DPO = price - Average(price[length / 2 + 1], length);
plot ZeroLine = 0;

DPO.DefineColor("Highest", Color.YELLOW);
DPO.DefineColor("Lowest", Color.LIGHT_RED);
DPO.AssignNormGradientColor(colorNormLength, DPO.color("Lowest"), DPO.color("Highest"));
ZeroLine.SetDefaultColor(GetColor(5));
 
Last edited by a moderator:
Hi, I have been trying for hours but have been unable to modify an indicator to get the signal arrows in the same screen with the indicator. When I try to add the arrows the indicator height listing goes from number to percentages. I also want to restrict the down signal arrows to only occur if the indicator turns from going up to down if it turns above the 75% line. And arrow signals from below if it turns up from below the 25% line. I would be satisfied if I couldn do just one side. The difficulty is do to TOS turning the indicator to percentages. I am try to do this for a number of indicators. But if I can see the code for one I should be able to do the others. I have include a sample of what I would like. The sample of the screen showing what is would like is hand drawn and not from any actual code
Here ya go:
SnxyoRc.png

Ruby:
# TD Ameritrade IP Company, Inc. (c) 2007-2021
# Detrended Price Oscillator

declare lower;

input colorNormLength = 14;
input length = 14;
input price = close;

plot DPO = price - Average(price[length / 2 + 1], length);
plot ZeroLine = 0;

DPO.DefineColor("Highest", Color.YELLOW);
DPO.DefineColor("Lowest", Color.LIGHT_RED);
DPO.AssignNormGradientColor(colorNormLength, DPO.color("Lowest"), DPO.color("Highest"));
ZeroLine.SetDefaultColor(GetColor(5));

plot UpArrow = if DPO crosses above -8 then -8 else Double.NaN;
plot DownArrow = if DPO crosses below 8 then 8 else Double.NaN;

UpArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
UpArrow.SetDefaultColor(color.dark_green);
DownArrow.SetDefaultColor(color.dark_red);
# ########################################################
 

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

A little contribution here with some resistance areas. I only change the length to 20, which I like it more

Code:
# TD Ameritrade IP Company, Inc. (c) 2007-2021
# Detrended Price Oscillator

declare lower;

input length = 20;
input price = close;
input ovLevel = 10;
input unLevel = -10;
input resistUpDn = 5;

plot DPO = price - Average(price[length / 2 + 1], length);
DPO.DefineColor("topL", Color.RED);
DPO.DefineColor("botL", Color.GREEN);
DPO.DefineColor("Normal", Color.GRAY);
DPO.AssignValueColor(if DPO > ovLevel then DPO.color("topL") else if DPO < unLevel then DPO.color("botL") else DPO.color("Normal"));
DPO.SetLineWeight(2);
DPO.HideBubble();

plot ZeroLine = 0;
ZeroLine.SetPaintingStrategy(PaintingStrategy.DASHES);
ZeroLine.SetDefaultColor(CreateColor(153,0,153));

plot posL = ovLevel;
posL.SetPaintingStrategy(PaintingStrategy.LINE);
posL.SetStyle(curve.LONG_DASH);
posL.SetDefaultColor(CreateColor(104,26,26));
posL.SetLineWeight(1);

plot negL = unLevel;
negL.SetPaintingStrategy(PaintingStrategy.LINE);
negL.SetStyle(curve.LONG_DASH);
negL.SetDefaultColor(CreateColor(11,83,11));
negL.SetLineWeight(1);

plot resUp = resistUpDn;
plot resDn = -resistUpDn;
resUp.SetDefaultColor(Color.BLUE);
resDn.SetDefaultColor(Color.BLUE);

plot UpArrow = if DPO crosses above unLevel then unLevel else Double.NaN;
UpArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
UpArrow.SetDefaultColor(color.DARK_GREEN);
UpArrow.SetLineWeight(2);

plot DownArrow = if DPO crosses below ovLevel then ovLevel else Double.NaN;
DownArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
DownArrow.SetDefaultColor(color.DARK_RED);
DownArrow.SetLineWeight(2);

 
Last edited:
Here ya go:
SnxyoRc.png

Ruby:
# TD Ameritrade IP Company, Inc. (c) 2007-2021
# Detrended Price Oscillator

declare lower;

input colorNormLength = 14;
input length = 14;
input price = close;

plot DPO = price - Average(price[length / 2 + 1], length);
plot ZeroLine = 0;

DPO.DefineColor("Highest", Color.YELLOW);
DPO.DefineColor("Lowest", Color.LIGHT_RED);
DPO.AssignNormGradientColor(colorNormLength, DPO.color("Lowest"), DPO.color("Highest"));
ZeroLine.SetDefaultColor(GetColor(5));

plot UpArrow = if DPO crosses above -8 then -8 else Double.NaN;
plot DownArrow = if DPO crosses below 8 then 8 else Double.NaN;

UpArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
UpArrow.SetDefaultColor(color.dark_green);
DownArrow.SetDefaultColor(color.dark_red);
# ########################################################
Hi Merryday
I'm trying to create a up/down cloud between the blue line but for some reason only show me the green cloud but not the red cloud every time the DPO crosses that area and I don't understand what I could doing wrong or why not I getting this work, here its the code I add

Code:
def clUp = if DPO > resistUpDn then resistUpDn else if DPO < -resistUpDn then resistUpDn else Double.NaN;
def clDn = if DPO < -resistUpDn then -resistUpDn else if DPO > -resistUpDn then -resistUpDn else Double.NaN;
AddCloud(clUp, clDn, Color.DARK_GREEN, Color.DARK_RED);
 
Hi Merryday
I'm trying to create a up/down cloud between the blue line but for some reason only show me the green cloud but not the red cloud every time the DPO crosses that area and I don't understand what I could doing wrong or why not I getting this work, here its the code I add

Code:
def clUp = if DPO > resistUpDn then resistUpDn else if DPO < -resistUpDn then resistUpDn else Double.NaN;
def clDn = if DPO < -resistUpDn then -resistUpDn else if DPO > -resistUpDn then -resistUpDn else Double.NaN;
AddCloud(clUp, clDn, Color.DARK_GREEN, Color.DARK_RED);

Try this

Capture.jpg
Ruby:
# TD Ameritrade IP Company, Inc. (c) 2007-2021
# Detrended Price Oscillator

declare lower;

input length = 20;
input price = close;
input ovLevel = 10;
input unLevel = -10;
input resistUpDn = 5;

plot DPO = price - Average(price[length / 2 + 1], length);
DPO.DefineColor("topL", Color.RED);
DPO.DefineColor("botL", Color.GREEN);
DPO.DefineColor("Normal", Color.GRAY);
DPO.AssignValueColor(if DPO > ovLevel then DPO.Color("topL") else if DPO < unLevel then DPO.Color("botL") else DPO.Color("Normal"));
DPO.SetLineWeight(2);
DPO.HideBubble();

plot ZeroLine = 0;
ZeroLine.SetPaintingStrategy(PaintingStrategy.DASHES);
ZeroLine.SetDefaultColor(CreateColor(153, 0, 153));

plot posL = ovLevel;
posL.SetPaintingStrategy(PaintingStrategy.LINE);
posL.SetStyle(Curve.LONG_DASH);
posL.SetDefaultColor(CreateColor(104, 26, 26));
posL.SetLineWeight(1);

plot negL = unLevel;
negL.SetPaintingStrategy(PaintingStrategy.LINE);
negL.SetStyle(Curve.LONG_DASH);
negL.SetDefaultColor(CreateColor(11, 83, 11));
negL.SetLineWeight(1);

plot resUp = resistUpDn;
plot resDn = -resistUpDn;
resUp.SetDefaultColor(Color.BLUE);
resDn.SetDefaultColor(Color.BLUE);

plot UpArrow = if DPO crosses above unLevel then unLevel else Double.NaN;
UpArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
UpArrow.SetDefaultColor(Color.DARK_GREEN);
UpArrow.SetLineWeight(2);

plot DownArrow = if DPO crosses below ovLevel then ovLevel else Double.NaN;
DownArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
DownArrow.SetDefaultColor(Color.DARK_RED);
DownArrow.SetLineWeight(2);

#def clUp = if DPO > resistUpDn then resistUpDn else if DPO < -resistUpDn then resistUpDn else Double.NaN;
#def clDn = if DPO < -resistUpDn then -resistUpDn else if DPO > -resistUpDn then -resistUpDn else Double.NaN;
AddCloud(0, resdn, Color.DARK_RED, Color.DARK_RED);
AddCloud(resup, 0, Color.DARK_GREEN, Color.DARK_green);
 
this is the idea that I'm trying to make, when is over 5 create the cloud between 5 an -5 same for when is down but I can't make work with the red one? my code shows me all in green


Your image did not include any chart data but did show where you wanted the colors, so now perhaps this may help. If it is not exactly what you want, perhaps you can make the necessary changes.

Capture.jpg
Ruby:
# TD Ameritrade IP Company, Inc. (c) 2007-2021
# Detrended Price Oscillator

declare lower;

input length = 20;
input price = close;
input ovLevel = 10;
input unLevel = -10;
input resistUpDn = 5;

plot DPO = price - Average(price[length / 2 + 1], length);
DPO.DefineColor("topL", Color.RED);
DPO.DefineColor("botL", Color.GREEN);
DPO.DefineColor("Normal", Color.GRAY);
DPO.AssignValueColor(if DPO > ovLevel then DPO.Color("topL") else if DPO < unLevel then DPO.Color("botL") else DPO.Color("Normal"));
DPO.SetLineWeight(2);
DPO.HideBubble();

plot ZeroLine = 0;
ZeroLine.SetPaintingStrategy(PaintingStrategy.DASHES);
ZeroLine.SetDefaultColor(CreateColor(153, 0, 153));

plot posL = ovLevel;
posL.SetPaintingStrategy(PaintingStrategy.LINE);
posL.SetStyle(Curve.LONG_DASH);
posL.SetDefaultColor(CreateColor(104, 26, 26));
posL.SetLineWeight(1);

plot negL = unLevel;
negL.SetPaintingStrategy(PaintingStrategy.LINE);
negL.SetStyle(Curve.LONG_DASH);
negL.SetDefaultColor(CreateColor(11, 83, 11));
negL.SetLineWeight(1);

plot resUp = resistUpDn;
plot resDn = -resistUpDn;
resUp.SetDefaultColor(Color.BLUE);
resDn.SetDefaultColor(Color.BLUE);

plot UpArrow = if DPO crosses above unLevel then unLevel else Double.NaN;
UpArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
UpArrow.SetDefaultColor(Color.DARK_GREEN);
UpArrow.SetLineWeight(2);

plot DownArrow = if DPO crosses below ovLevel then ovLevel else Double.NaN;
DownArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
DownArrow.SetDefaultColor(Color.DARK_RED);
DownArrow.SetLineWeight(2);


AddCloud(if dpo>resdn then resup else double.nan, resdn, Color.DARK_green, Color.DARK_green);
AddCloud(if dpo<resup then resdn else double.nan, resup, color.DARK_red, Color.DARK_red);
 
Your image did not include any chart data but did show where you wanted the colors, so now perhaps this may help. If it is not exactly what you want, perhaps you can make the necessary changes.
it work better like this for the idea that I was trying to come up because only show the cloud every time the DPO goes over or below the resistant level, thanks as always

Code:
AddCloud(if DPO > resistUpDn then resUp else Double.NAN, resDn, Color.DARK_GREEN, Color.CURRENT);
AddCloud(if DPO < -resistUpDn then resDn else Double.NAN, resUp, Color.CURRENT, Color.DARK_RED);

 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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