I am new to programming and am hoping for some advice. Currently, I am just getting to know Zorro and lite-C and tried to run the following simple script based on Bill Williams' fractal indicator (it is supposed to open a long(short) trade when price breaks the high(low) fractal:
function run() {
var FH = FractalHigh(series(price()),5); var FL = FractalLow(series(price()), 5);
if (crossOver(series(price()), FH)) enterLong(); else if (crossUnder(series(price()), FL)) enterShort();
}
When I test this, no trades are opened. Can anyone explain why? Is it because I am trying to open a trade when a series crosses a certain price (the current fractal) rather than another series?
The Fractal indicator is either zero when the period has no peak, or it is the peak value. Because the price can not be higher than its own peak in the last 5 bars, it will never cross the fractal. The indicator is not suited for crossing anyway because it's no line, but just points.
Re: Help entering trades
[Re: jcl]
#441351 05/20/1403:2405/20/1403:24
Thanks for clarifying, JCL. I don't think I totally understand though. Williams' fractal indicator isn't necessarily the most recent peak, it is the most recent high with at least two lower candles both before and after. In some cases, this will correspond to the most recent peak, but not all.
Suppose I wanted to buy when price moved through the most recent fractal (as opposed to the most recent peak). Could I do this by passing the value of the most recent fractal to a pending buy order?
I came up with this script to enter pending orders at the most recent high and low fractals, and to only have one open trade at any one time. Is this script correct? Thanks for your patience, I am very new to coding.
function run() {
var FH = FractalHigh(series(price()),5); var FL = FractalLow(series(price()), 5);
Stop = 2*ATR(60); TakeProfit = 2*ATR(60);
if (NumOpenLong < 1) enterLong(0,FH); else if (NumOpenShort < 1) enterShort(0,FL);
No, I think this script is also not correct. Keep in mind that "Fractal" is 0 when there is no peak in the middle. Otherwise it's in fact the most recent peak. With no peak you're entering at 0, which means you enter at market.
I am not sure what you want to do and for what you're using the "Fractal" indicator. If you want to enter a trade at a peak level, use the LL and HH indicators instead. If you're using Fractal for a peak, you must check if it's zero and not enter a trade in that case.
The best way to see how your script trades is just plotting the used indicators in a window and check how they affect the trades.
Re: Help entering trades
[Re: jcl]
#441375 05/20/1412:5805/20/1412:58
Thanks for your response. I'm not really trying to do anything special with the Fractal indicator, just using it to familiarise myself with Zorro and programming in general. I have used Bill Williams' stuff in the past, so thought it made sense to start with something I know.
Attached is a plot as you suggested, zoomed in so that you can see a couple of days in detail. It plots just the upper fractal. It looks to me like the value of the fractal alternates between zero and approximately 1.767. Why would it keep going back to that value, rather than updating as a new upper fractal is formed?
The answer to "why" is always "because it's made this way". I have not invented that indicator, so I guess you must ask Bill Williams.
If you want a line connecting the fractal peaks, you can for instance use a static variable and set it only when Fractal returns nonzero. But for just testing crossover or similar signals, other indicators that really return a line are probably better suited.
Re: Help entering trades
[Re: jcl]
#441387 05/21/1402:5505/21/1402:55
boatman, the underlying series price() varies in the range 1.763 to 1.773. In the chart below that, where you plot your indicator, the y-axis has range 0 to 2.0. There is no way your eye can detect that variation. I bet the peak heights are actually different.
Hint: Try printing the values. printf("\nFH=%f", FH);