♥ 0 |
I’m not sure how to properly title this one. One of the main concerns is not finding from “X” bars ago but looking for bars ahead and putting a trigger. In the attached photo that is labeled Example 1 here is the issue: I’m using WilliamsFractal study and on the first candle highlighted on the left you see the fractal above the yellow candle. Based on my code, I get an alert when the fractal is above the green, red and blue lines and those lines are “stacked”. However based on the WilliamsAlligator study those lines are print 3 bars ahead. It’s stated in the code lipsdisplace -3. So technically when that fractal in question is formed my code says the 3 lines aren’t stacked and doesn’t form an arrow but based on his study it is stacked because it is 3 bars ahead (as show by the white box). So how can I fix this code on my trigger to look bars ahead or that particular study ahead? Here is my current code: input price = hl2; def na = Double.NaN; plot Jaw = MovingAverage(averageType, price[-jawDisplace], jawLength); Jaw.SetDefaultColor(Color.BLUE); def bullfract = WilliamsFractal (); plot LongTrigger = if bullfract then bullfract > Lips and Lips > Teeth and Teeth > Jaw else na; plot ShortTrigger = if bullfract then bullfract < Lips and Lips < Teeth and Teeth < Jaw else na; LongTrigger.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP); ShortTrigger.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN); #Trigger alerts Second part (Example 2) I know we don’t have WilliamsFractal code so I’m not sure if this will work or not. Right now if I wanted to show a short trigger it waits for a fractal to appear at the top of the candle. I’m wanting it to be the bottom fractal at the bottom of the candle. As you can see in the white box on the left this is where the trigger should’ve been hit instead of the right white box as the fractal is at the top. Is there a way w/o knowing the code to distinguish this and fix that short alert? I think my basic coding is getting better. Thanks for all the help.
Marked as spam
|
Private answer
Without even taking a slight glance at the code. Try this and see if it clears things up for you. This plots the close from 3 bars ago:
This plot the close from three bars in the future:
The same exact method applies to every variable you write into the code.
However when referencing bars into the future you should be sure to check if there is a value there before trying to reference it:
Marked as spam
|
|||||
Private answer
New SolutionI took some time to evaluate the code and you really don't have any issue with shifting plots left or right. Or reading plots from x number of bars into the future. The issue has nothing to do with those thing at all. Not to the least degree. How to Reference Plots from Another StudyFor my solution, I am going to show you how to debug your code. If you don't know how to debug your code you have no idea what is going on under the hood. It's like driving blind. Nothing good comes from that. Let's take a look at the code for the WilliamsFractal (this is a candlestick pattern and you will not find this listed under studies). The code for the WilliamsFractal is located under "Patterns". It's the button right next to the "Studies" button at the top of your charts. Here are the two plot statements from WilliamsFractal:
Two things we need to learn here. First is that these plot statements are either
Instead, you need to also include the name of the plot. Like so:
Converting Plots into True/False StatementsNow I will show you the first step in converting these fractal plots into true/false statements:
Remember that I said these plots are either the high/low of the bar OR they are http://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Math---Trig/IsNaN.html Ok? We place the "!" symbol in front of the function because that symbol means "NOT". So we are testing if each plot from WillamsFractal is NOT Next, we convert this to a true false condition by simply checking if the variable named
Now I may have gotten this backwards from your intended direction. I don't know for sure. So you many need to flip those around to get what you intended. But you should have the basic idea at this point. How to Debug Your CodeAs a bonus, I will provide the code I used to troubleshoot this issue. Along with a screenshot showing how this plots on a chart. I'll explain what you see in the lower subgraph.
The Cyan line is the plot from the Marked as spam
|
Please log in to post questions.