How Is Trend Reversal Calculated

Status
Not open for further replies.

JLEE

New member
such as this:
Code:
input usemanualfibskip = no;#Hint usemanualfibskip: Select no to use preprogrammed fibskip amounts. Select no, to use the amount entered at input fibskip.
input fibskip = .50;#Hint fibskip: Set input usemanualfibskip == yes to use this amount versus preprogrammed amounts. Standard is 1.0. This is percentage difference between fib high and low before a new fib grid created.
def showBubblesfibratio = no;
def showFibLabel = no;#Hint showfibLabel: Select yes to show label of current fib level as of last price
def showfiblines = no;
def fib1level = .236;
def fib2level = .382;
def fibMlevel = .500;
def fib3level = .618;
def fib4level = .786;
#Fibs
def datacount2 = (HighestAll(data1) - data1[1]);
def numberfibretracementstoshow = 2;
def fibskipit = if usemanualfibskip == no then if close > 800 then .25 else .5 else fibskip;
def EIfibh = if EISave == priceh and AbsValue(EISave - EISave[1]) > priceh * fibskipit * .01 then priceh else EIfibh[1];
def EIfibl = if EISave == pricel and AbsValue(EISave - EISave[1]) > priceh * fibskipit * .01 then pricel else EIfibl[1];
def range = EIfibh - EIfibl;
def fibH = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibh else Double.NaN;
def fibL = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibl else Double.NaN;
def fibM = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibl + range * fibMlevel else Double.NaN;
def fib1 = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibl + range * fib1level else Double.NaN;
def fib2 = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibl + range * fib2level else Double.NaN;
def fib3 = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibl + range * fib3level else Double.NaN;
def fib4 = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibl + range * fib4level else Double.NaN;

AddLabel(showFibLabel, Concat( "Current Fib Level ", AsPercent((close - EIfibl) / (range))), if close > EIfibl then Color.GREEN else if EIfibh == close then Color.WHITE else Color.RED);

AddChartBubble(showBubblesfibratio and !IsNaN(EI) and BarNumber() != 1, if isUp then priceh * (1 + bubbleoffset) else pricel * (1 - bubbleoffset) , if isUp then AsPercent((priceh - EIfibl) / (range)) else AsPercent((pricel - EIfibl) / range), if isUp and chghigh > 0 then Color.DARK_GREEN else if isUp and chghigh < 0 then Color.DARK_RED else if isUp then Color.DARK_GREEN else if !isUp and chglow > 0 then Color.DARK_GREEN else if !isUp and chglow < 0 then Color.DARK_RED else Color.DARK_RED, isUp);
 
Last edited by a moderator:
Solution
@JLEE @MerryDay Maybe this can help - it removes a lot of unnecessary fluff from the indicator. The EMAs (the 9, 14, and 21) and fib retracements are extra for the indicator and are not shown. For instance, the three EMAs are only used for the color of the reversal bubbles, and the fib code itself is just dead weight, nothing is even plotted from the calculations. There are also a lot of bubbles and labels in the code that are turned off by default in the original indicator. There's a bunch of stuff that isnt being used in the original. I uncovered a few plots and added a bit to make the visuals easier. Not an expert, but hope this helps

Code:
# used to switch between "zigzag based on high/low of price" and "zigzag based on...
again thank you @Pensar for redeveloping the code into a materially more eloquent and understandable structure

@rad14733 also thank you. this is clearer to me (in a murky pond kinda of way)

@rad14733 if i may tease your brain, i am stuck in a logic loop within <def signal> and <def dir> which both reach up into EIL and EIH. but if i read the <def EIL> correctly its simply asking if EI is a real number & has it changed and if so then simply give me the MAL or MAH as the case may be. BUT if this is so then in the <def signal> equation reads:

dir>0 AND MAL > MAL [which is impossible since they are the same number] which then pushes to later in equation to then if dir <0 AND MAH <MAH [which again is not possible] which then just dumps to just showing the last candle signal value. its a loop assuming my method is zigzagMovingAverage from <def priceh> and <def pricel> on lines 24 and 25

but it cannot be a loop because the code works and there are actually output of arrows which depends on there not being a loop obviously. So i am clearly missing something but just cannot get. Any assistance greatly appreciated
 
Last edited:

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

dir>0 AND MAL > MAL [which is impossible since they are the same number] which then pushes to later in equation to then if dir <0 AND MAH <MAH [which again is not possible] which then just dumps to just showing the last candle signal value. its a loop assuming my method is zigzagMovingAverage from <def priceh> and <def pricel> on lines 24 and 25
@JLEE Note that it doesn't matter whether the method is based on the moving averages or not -
  • If the "average" method is selected, then the ZigZag uses the exponential average of the high and low of the past five bars as it's input
  • If the "high_low" method is selected, then the ZigZag uses the the high and low of price as it's input
The same calculations apply regardless which method is selected.
One thing that might help you visualize what each variable is doing is to change the "def" to "plot" instead. If any variable is recursive, though, then you will have to create a new plot for that variable.
 
Status
Not open for further replies.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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