Please, help with Fractal indicator.

Posted By: Maruska

Please, help with Fractal indicator. - 01/07/13 11:39

I'm a c++ programmer but I have some difficults to understand indicators relations with MT4 equivalents.
For example in MT4 I can calculate the last high fractal with this function:

UpFractal = iFractals(Symbol(), tf, MODE_UPPER, 3);

in zorro the function is:

FractalHigh(var* Data, int TimePeriod)

I have tried this:

UpFractal = FractalHigh(series(price()),5)

but I don't understand the correlation with the two functions; in the FractalHigh function what TimePeriod means?

Thanks in advance and
congratulations with the excellent work with zorro.
Posted By: jcl

Re: Please, help with Fractal indicator. - 01/07/13 11:45

I am not sure if iFractals is really the Fractal indicator, as MT4 often calculates indicators differently. The Fractal indicator needs a time period, which is just the number of bars from which the fractal is taken. The fact that this is missing in the MT4 version is suspicious. So please check what iFractals is doing at all and which time period it uses.

The "3" shift parameter in the iFractal example is the same as adding a "+2" to a series, like this:

UpFractal = FractalHigh(series(price())+2,5);

The source code of FractalHigh can be found in the indicators.c file.
Posted By: Maruska

Re: Please, help with Fractal indicator. - 01/07/13 12:08

Thanks for the fast reply, but my doubts remain.

I wrote a script like this for just to print out last up or down fractal:

function run()
{
BarPeriod = 5;

printf("\nUP = %.5f - DW = %.5f", FractalHigh(series(price())+2,5), FractalLow(series(price())+2,5));
}

but it is not working.

What is the correct way in zorro to get the last up or down fractal?
Posted By: jcl

Re: Please, help with Fractal indicator. - 01/07/13 12:12

Your script looks correct to me.

I would use priceHigh for FractalHigh and priceLow for FractalLow, though. Shifting the Fractal by 2 bars probably also makes not much sense for signal generation.
Posted By: TankWolf

Re: Please, help with Fractal indicator. - 01/07/13 12:47

Just out of curiosity what sort of trading signals or strategies can be produced from using fractals? Haven't seen a lot about them in my trading experience.
Posted By: Maruska

Re: Please, help with Fractal indicator. - 01/07/13 13:19

I'm just trying to implement a Bill Williams strategy based on Alligator and Fractals.
I have tested it in the past with MT4, but since I have never been satisfied to mt4 backtest and I have just found this great product, I am trying it to zorro.
Posted By: Maruska

Re: Please, help with Fractal indicator. - 01/07/13 13:20

I have found that what zorro print out with my previos script differ from the fractal printed out from the Trading Station software. This is normal?
Posted By: SFF

Re: Please, help with Fractal indicator. - 01/07/13 13:21

Let me know if you find any difference between MT4 and Zorro Testing.
Posted By: jcl

Re: Please, help with Fractal indicator. - 01/07/13 13:55

Even with precisely the same indicators, there can be great differences between brokers and their platforms. The first obvious reason is that the price history is broker dependent, which can greatly affect the signals when using short time frames below 60 minutes. The second reason is that your 5 minute bars, even when based on the same price ticks, might start at a different time offset.

For testing this, compare the price charts and print also the highs and lows of the 5 bars belonging to the fractals, on both platforms. Then you can most likely see where the differences come from.
Posted By: Maruska

Re: Please, help with Fractal indicator. - 01/07/13 14:06

I have tryed this experiment:

function run()
{
BarPeriod = 5;

printf("\n\nOpen = %.5f", priceOpen(1));
printf("\n\nClose = %.5f", priceClose(1));
printf("\n\nHigh = %.5f", priceHigh(1));
printf("\n\nLow = %.5f", priceLow(1));
}

and then I have start the Trade.

Zorro prints out these values for the last candle:

Open = 1.30517
Close = 1.30603
High = 1.30616
Low = 1.30609

but on the Trading Station for the same real account (that to witch zorro is connected), the last candle shows these values:

Open = 1.30579
Close = 1.30592
High = 1.30645
Low = 1.30569

Why zorro reads different price value from the same Broker and same account?
This leaves me a little dubious.
Maybe I missed something?
Posted By: jcl

Re: Please, help with Fractal indicator. - 01/07/13 14:18

(1) is not the last candle. (0) is the last candle.

Look at the price when the candle ends. The candles must end at exactly the same time on both platforms and the Close price must be exactly the same.
Posted By: TankWolf

Re: Please, help with Fractal indicator. - 01/07/13 14:22

I think your problem is your actually checking 2 bars back, use priceOpen(0), priceClose(0) etc etc....to check the last candle.
Posted By: Maruska

Re: Please, help with Fractal indicator. - 01/07/13 14:31

Ok, this means zorro do not consider current candle. These are the differences with mt4 that lead me into a traps. I worked about 10 years with mt3/mt4.

however, I get almost the same differencies about what zorro reads and what Trading Station tells:

function run()
{
BarPeriod = 30;

printf("\n\nOpen = %.5f", priceOpen(0));
printf("\n\nClose = %.5f", priceClose(0));
printf("\n\nHigh = %.5f", priceHigh(0));
printf("\n\nLow = %.5f", priceLow(0));
}

Zorro:

Open = 1.30668
Close = 1.30649
High = 1.30675
Low = 1.30633

Trading Station:

Open = 1.30592
Close = 1.30627
High = 1.30651
Low = 1.30550

Sorry, but I don't understand why these are differencies!!!
Posted By: Maruska

Re: Please, help with Fractal indicator. - 01/07/13 15:04

does anyone have any idea about?
Posted By: jcl

Re: Please, help with Fractal indicator. - 01/07/13 15:10

For excluding a different time offset, can you do the same test with M1 candles?
Posted By: Maruska

Re: Please, help with Fractal indicator. - 01/07/13 15:17

Test with the M1 candle:

function run()
{
BarPeriod = 1;

printf("\n\nOpen = %.5f", priceOpen(0));
printf("\n\nClose = %.5f", priceClose(0));
printf("\n\nHigh = %.5f", priceHigh(0));
printf("\n\nLow = %.5f", priceLow(0));
}

Zorro:

Open = 1.30761
Close = 1.30774
High = 1.30794
Low = 1.30761

Trading Station:

Open = 1.30743
Close = 1.30755
High = 1.30774
Low = 1.30742
Posted By: jcl

Re: Please, help with Fractal indicator. - 01/07/13 15:36

Ok, I will now look into this myself. I don't have the Trading Station installed here, but I'll set it up and check what's happening.
Posted By: Maruska

Re: Please, help with Fractal indicator. - 01/07/13 15:42

I have tested it also on a demo account with the same results.
Posted By: jcl

Re: Please, help with Fractal indicator. - 01/07/13 16:42

Ok, I've just tested it and can not confirm the problem. I installed Trading Station and opened a m1 chart. The last full candle that I see - before the partial candle that is just building - has the same OHLC values that were printed by Zorro.

Maybe you were looking at the Bid instead of the Ask prices?

Do you have a difference between the price in Zorro's server window, before the blinking asterisk, and the current price in Trading Station?

Posted By: Maruska

Re: Please, help with Fractal indicator. - 01/08/13 12:26

You are right, I realized my mistake. Sorry, but I never traded with Trading Station before and MetaTrader is more user friendly but I have a feeling that zorro is more powerful and effective.

Thank you very much for your support.
Posted By: Maruska

Re: Please, help with Fractal indicator. - 01/08/13 12:29

I also found the correct way to get the last breakout fractal:

var FracalUP = FractalHigh(series(priceHigh()),5);
var FractalDW = FractalLow(series(priceLow()),5);

To access fractals back history:

vars FractalUP = series(FractalHigh(series(priceHigh()),5));
vars FractalDW = series(FractalLow(series(priceLow()),5));

and then FractalUP[n] and FractalDW[n]
Posted By: Maruska

Re: Please, help with Fractal indicator. - 01/09/13 08:59

Ok, I am trying to test my strategy with zorro but it is not too easy.
Thare are a lot of settings to be considered: TICKS, PARAMETERS, FACTORS, NumWFOCycles, NumBarCycles, NumOptCycles, LookBack and so on; even slightly changing these values ​​the results are completely different.

Have you a template from which to run a reliable back test?
Posted By: TankWolf

Re: Please, help with Fractal indicator. - 01/09/13 09:25

TICKS only needs to be used if you are entering with trade management functions. PARAMETERS is required if you have optimised variables in your script. FACTORS is used when calculating optimal margin. Most backtests should use NumWFOCycles anywhere from 6-12 and NumBarCycles can help generate more trades if not many signals are generated with your strategy for more reliable results. LookBack is needed in most cases especially when using indicators, and should be set at double your longest timeperiod used to generate your indicators. I dont believe there really can be a template cause which Modes to set depends on the script and strategy you are using.
Posted By: jcl

Re: Please, help with Fractal indicator. - 01/09/13 11:28

The best way to learn trade system development is learning by doing. Knowing many indicators is not very important, but knowing how to test a system is important. System development is empirical, so testing is everything.

First try to understand what the parameters are doing, from their description in the manual. Some of them are for special cases only, but most - especially those that are also used in the tutorials - are essential for properly testing a system. You'll find them, under different names, in any serious automated trade software.

If you are not sure what a certain parameters does and how it affects the system, experiment with it and check the performance sheet. If then there are still open questions, ask them here.
Posted By: Maruska

Re: Please, help with Fractal indicator. - 01/09/13 20:31

Just a question for now.

If I utilize a stop in my script, I must use the TICKS for testing? Otherwise zorro check the stoploss only on every bar close, right?
Posted By: jcl

Re: Please, help with Fractal indicator. - 01/10/13 10:41

Not necessarily. Even without TICKS the stops are realistic, they use an intra-bar price curve approximation.

TICKS is more precise however, and is recommended when the trades are very short, f.i when many trades open and close within the same bar. TICKS should also be used when you use a tick based function for trade exit.
Posted By: SFF

Re: Please, help with Fractal indicator. - 01/10/13 11:14

I made a ever-increasing profit curve with no-tick based test but when I test it with a tick mode the strategy quick-changed to a loss strategy.

What is a character of those strategy?
in both test modes, The strategy needs to be profitable to ensure robustness?
Posted By: jcl

Re: Please, help with Fractal indicator. - 01/10/13 11:23

No, the TICKS result always overrides the result without TICKS. So that strategy was indeed losing and the profit was possibly an artifact of inaccurate entry/stop approximations.

A robust strategy must show profits under all normal circumstances and test modes. It happens frequently that a test generates profit, but loses when you change some parameter a little. Such a system is not profitable.
Posted By: Maruska

Re: Please, help with Fractal indicator. - 01/17/13 10:26

Can I read the current market price (Ask & Bid) with zorro?
Posted By: jcl

Re: Please, help with Fractal indicator. - 01/17/13 11:41

var Ask = priceClose();
var Bid = Ask-Spread;

http://manual.zorro-trader.com/price.htm
Posted By: Maruska

Re: Please, help with Fractal indicator. - 01/17/13 11:54

I read the manual, but priceClose() means priceClose(0) and it's the close price of the the last closed canlde, right?
Posted By: jcl

Re: Please, help with Fractal indicator. - 01/17/13 12:13

priceClose(0) is always the last received price quote. When the last candle has just closed, as is normally the case, it's also the price at which the candle has just closed.
Posted By: Maruska

Re: Please, help with Fractal indicator. - 01/17/13 21:44

Ok, thanks.
I begin to understand more about zorro's functioning.

Another question:
If I have more than one order opened how Can I close only one particolar order?

I read on the manual the function "exitTrade (TRADE* trade, var price)" but I don't know how to retriev "trade" variable.

I have some like this:

for(open_trades)
if(strstr(TradeAsset,Asset) && TradeIsOpen)
if(TradeIsLong && ((Bid - priceClose(0)) > (PipsProfit*PIP)))
exitLong();
else if(TradeIsShort && ((priceClose(0) - Ask) > (PipsProfit*PIP)))
exitShort();

but I want to close only the order that matches the condition.

Thanks
Posted By: jcl

Re: Please, help with Fractal indicator. - 01/18/13 07:43

Your code above is correct for closing only the order that matches the condition, but it runs only once per bar. You might want to do that in a trade function, for closing the trade as soon as the condition is met.

For closing a particular order, you can retrieve the TRADE* pointer from the enter command:


TRADE* my_order = enterLong();
...
exitTrade(my_order,0);
Posted By: Maruska

Re: Please, help with Fractal indicator. - 01/18/13 10:16

I have tested it in real time in a demo account and when the condition is met, it close all long orders (or short orders).

What do you mean about "trade function"?

If I have a lot of orders opened and I don't have set the variable "TRADE* my_order" for each order; is there a way to retriev it for the order I am checking?
Posted By: jcl

Re: Please, help with Fractal indicator. - 01/19/13 10:21

A trade function is for fine control of trade entry and exit - for details, check out enterLong/Short in the manual. You normally use a trade function, and not a for(open_trades) loop, for exiting a trade under a trade-specific condition. The advantage is that a trade function can react on any tick.

The pointer of the current trade in the for(open_trades) loop is g->tr, so for closing only a particular order, use exitTrade(g->tr,0).
© 2024 lite-C Forums