Help with price action indicator

Status
Not open for further replies.

sonnyjitsu

New member
I'm writing a script to display price action signals. I've got most of it written and working, but I noticed that on some candles, both an up arrow and a down arrow will be printed on the same candle. The solution I want to use is to figure out what color the candle is and use the appropriate arrow. So, if it's a green candle, print a green arrow underneath, if it's a red candle print a red arrow above. I have it all working except for that little caveat. Any help would be appreciated.

-Noob.

mod note: Updated script can be found:
https://usethinkscript.com/threads/wicks-tails-price-action-indicator.12375/

thinkscript.png
 
Last edited by a moderator:
I’m noticing a lot of the arrows plotting on the same candle are because of wedges. They are all potentially good signals the next bar determines if the wedge may succeed.
 
I'm writing a script to display price action signals. I've got most of it written and working, but I noticed that on some candles, both an up arrow and a down arrow will be printed on the same candle. The solution I want to use is to figure out what color the candle is and use the appropriate arrow. So, if it's a green candle, print a green arrow underneath, if it's a red candle print a red arrow above. I have it all working except for that little caveat. Any help would be appreciated.

-Noob.

Ruby:
# This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
# sonnyjitsu

input largeSpread = 0.60;
input irregularBody = 0.10;

input EMALength = 50;
input volumeMA = 12;
def lowerTail;
def upperTail;

if close > open {
    upperTail = (high - close);
    lowerTail = (open - low);
} else {
    upperTail = (high - open);
    lowerTail = (close - low);
}

def e1 = ExpAverage(close, EMALength);
def e2 = ExpAverage(e1, EMALength);
def dema = 2 * e1 - e2;

input showMovingAverage = no;
plot DoubleEMA = if showMovingAverage then dema else Double.NaN;

def candleBody = AbsValue(close - open);
def thePlot = close;

def cond1 = volume >= ExpAverage(volume, volumeMA);

def cond2 = (open < dema and (lowerTail > upperTail));
def cond3 = (open > dema and (upperTail > lowerTail));
def cond4 = candleBody > largeSpread and cond1;

plot priceActionIrregularUp = if open < dema and candleBody < irregularBody and cond1 and lowerTail < upperTail then close else Double.NaN;
priceActionIrregularUp.SetDefaultColor(Color.MAGENTA);
priceActionIrregularUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

plot priceActionIrregularDown = if open > dema and candleBody < irregularBody and cond1 and upperTail > lowerTail then close else Double.NaN;
priceActionIrregularDown.SetDefaultColor(Color.MAGENTA);
priceActionIrregularDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

plot priceActionArrowUp = if close > open and cond4 or cond1 and cond2 then close else Double.NaN;
priceActionArrowUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
priceActionArrowUp.SetDefaultColor(Color.GREEN);

plot priceActionArrowDown = if open > close and cond4 or cond1 and cond3 then close else Double.NaN;
priceActionArrowDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
priceActionArrowDown.SetDefaultColor(Color.RED);

thinkscript.png
https://tlc.tdameritrade.com.sg/center/reference/thinkScript/Functions/Look---Feel/TakeValueColor
 

Try replacing those in the code with the only change is placement of parentheses ()

Code:
plot priceActionArrowUp = if close > open and cond4 or cond1 and cond2 then close else Double.NaN;
priceActionArrowUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
priceActionArrowUp.SetDefaultColor(Color.GREEN);

plot priceActionArrowDown = if open > close and cond4 or cond1 and cond3 then close else Double.NaN;
priceActionArrowDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
priceActionArrowDown.SetDefaultColor(Color.RED);

with

Code:
plot priceActionArrowUp = if close > open and (cond4 or cond1 and cond2) then close else Double.NaN;
priceActionArrowUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
priceActionArrowUp.SetDefaultColor(Color.GREEN);

plot priceActionArrowDown = if open > close and (cond4 or  cond1 and cond3) then close else Double.NaN;
priceActionArrowDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
priceActionArrowDown.SetDefaultColor(Color.RED);
 
Here's the solution. The indicator isn't perfect, I have to find a better way of figuring out if we're at the top or bottom of a trend than using a moving average, but here's the updated code.


Ruby:
# This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
# sonnyjitsu

input largeSpread = 0.60;
input irregularBody = 0.10;

input EMALength = 50;
input volumeMA = 12;
def lowerTail;
def upperTail;

if close > open {
    upperTail = (high - close);
    lowerTail = (open - low);
} else {
    upperTail = (high - open);
    lowerTail = (close - low);
}

def e1 = ExpAverage(close, EMALength);
def e2 = ExpAverage(e1, EMALength);
def dema = 2 * e1 - e2;

input showMovingAverage = no;
plot DoubleEMA = if showMovingAverage then dema else Double.NaN;

def candleBody = AbsValue(close - open);
def thePlot = close;

def goodVolume = volume >= ExpAverage(volume, volumeMA);

def cond2 = (open < dema and (lowerTail > upperTail) and goodVolume and lowerTail > candleBody / 3);
def cond3 = (open > dema and (upperTail > lowerTail) and goodVolume and upperTail > candleBody / 3);
def largeBodyGoodVolumeUp = close > open and candleBody > largeSpread and goodVolume;
def largeBodyGoodVolumeDown = close < open and candleBody > largeSpread and goodVolume;

plot priceActionIrregularUp = if open < dema and candleBody < irregularBody and goodVolume and lowerTail < upperTail then close else Double.NaN;
priceActionIrregularUp.SetDefaultColor(Color.MAGENTA);
priceActionIrregularUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

plot priceActionIrregularDown = if open > dema and candleBody < irregularBody and goodVolume and upperTail > lowerTail then close else Double.NaN;
priceActionIrregularDown.SetDefaultColor(Color.MAGENTA);
priceActionIrregularDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

plot priceActionArrowUp = if largeBodyGoodVolumeUp or cond2 and !largeBodyGoodVolumeDown then close else Double.NaN;
priceActionArrowUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
priceActionArrowUp.SetDefaultColor(Color.GREEN);

plot priceActionArrowDown = if largeBodyGoodVolumeDown or cond3 and !largeBodyGoodVolumeUp then close else Double.NaN;
priceActionArrowDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
priceActionArrowDown.SetDefaultColor(Color.RED);
 
Last edited:
Here's the solution. The indicator isn't perfect, I have to find a better way of figuring out if we're at the top or bottom of a trend than using a moving average, but here's the updated code.


Ruby:
# This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
# sonnyjitsu

input largeSpread = 0.60;
input irregularBody = 0.10;

input EMALength = 50;
input volumeMA = 12;
def lowerTail;
def upperTail;

if close > open {
    upperTail = (high - close);
    lowerTail = (open - low);
} else {
    upperTail = (high - open);
    lowerTail = (close - low);
}

def e1 = ExpAverage(close, EMALength);
def e2 = ExpAverage(e1, EMALength);
def dema = 2 * e1 - e2;

input showMovingAverage = no;
plot DoubleEMA = if showMovingAverage then dema else Double.NaN;

def candleBody = AbsValue(close - open);
def thePlot = close;

def goodVolume = volume >= ExpAverage(volume, volumeMA);

def cond2 = (open < dema and (lowerTail > upperTail) and goodVolume);
def cond3 = (open > dema and (upperTail > lowerTail) and goodVolume);
def largeBodyGoodVolumeUp = close > open and candleBody > largeSpread and goodVolume;
def largeBodyGoodVolumeDown = close < open and candleBody > largeSpread and goodVolume;

plot priceActionIrregularUp = if open < dema and candleBody < irregularBody and goodVolume and lowerTail < upperTail then close else Double.NaN;
priceActionIrregularUp.SetDefaultColor(Color.MAGENTA);
priceActionIrregularUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

plot priceActionIrregularDown = if open > dema and candleBody < irregularBody and goodVolume and upperTail > lowerTail then close else Double.NaN;
priceActionIrregularDown.SetDefaultColor(Color.MAGENTA);
priceActionIrregularDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

plot priceActionArrowUp = if largeBodyGoodVolumeUp or cond2 and !largeBodyGoodVolumeDown then close else Double.NaN;
priceActionArrowUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
priceActionArrowUp.SetDefaultColor(Color.GREEN);

plot priceActionArrowDown = if largeBodyGoodVolumeDown or cond3 and !largeBodyGoodVolumeUp then close else Double.NaN;
priceActionArrowDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
priceActionArrowDown.SetDefaultColor(Color.RED);
Unfortunately that’s all relative, on one timeframe can be the top, another middle of the trend, another bottom of the trend. The way I figure out if it’s top or bottom is simply using pivots, certain price points but it all depends on the time frame you’re viewing, it’s an art not a science
 
plot priceActionArrowDown = if open > close and (cond4 or cond1 and cond3) then close else Double.NaN;
Do you know what the order of precedence is for ToS? Is this:
Code:
A:    open > close and ( cond4 or ( cond1 and cond3 ) )
B:    open > close and ( ( cond4 or cond1 ) and cond3 )
C:    something else I hadn't thought of...

-mashume
 
Status
Not open for further replies.

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