Australian (ASX) Stock Market Forum

Amibroker FAQ

This is another logical issue, not a problem with the Zig Zag indicator. You can't identify any point as a peak or trough until you've had some degree of retracement after it. At that point you can go back and identify the peak or trough, but of course it's too late to buy or sell at that turning point (naturally performance will be good if you do use the peak and trough bars as signals).

For example, if you say a turning point is defined by a 10% retracement, then you can only generate a buy or sell 10% above a trough or below a peak. As long as you only use the bar where the peak or trough is determined, and not the peak or trough bar itself, then you can safely backtest it (mind you, that's not all that easy).

So you can write alternatives to the Zig Zag indicator to do the same thing, but you can't get around the logical issue that a peak or trough can only be known in hindsight after some amount of retracement.

GP

GP,

As always, I appreciate your time in replying.

I totally agree with all your points. I was led to believe that the Zig Zag indicator behaved inconsistantly in backtesting and one of the reasons given was the problem with defining the last reversal point (using future bars). However, as you say this makes perfect sense as to why.

In my situation I just want the ability to identify how many bars have passed since each of the recent reversal points have occurred, so using the Zig Zag is probably the way to go.

Can I ask why you commented that it isn't easy to backtest the Zig Zag indicator? Any insight into potential problems would be most helpful.

Kind Regards,

Chorlton
 
This is not so easy in AFL (and 10-20 steps is a very wide stop). I'm not sure which code of mine you are referring to, as I only remember mentioning countback line code in a plugin (plus the AFL to reference it). If you're perhaps trying to use the AFL without having the plugin, then you will have a problem. The version of AB shouldn't matter.

Which code of mine are you referring to, and what exactly are the syntax errors you are getting?

GP

Hi GP,

Thanks for the reply and the code for 60 day high/low. Greatly appreciated.

The code of yours I was refering to is below
========================================================

Here's some sample code for a very simple system using a 30/60 day EMA crossover to buy and a 20 step countback line trailing stop (intended as a longer-term system). It does the following:

- Creates an auto-resetting trailing stop from the countback line data.
- Creates the buy array from the EMA crossover.
- Creates the sell array using the trailing stop.
- Removes redundant buy & sell signals.
- Masks the stop line data so it will only plot between buys & sells.
- Plots the results.


cback = Param("Countback?", 20, 1, 100, 1);

GraphXSpace = 10;
Plot(Close, "Price", -1, styleCandle);

e30 = EMA(Close, 30);
e60 = EMA(Close, 60);

cblLine = GP_CountBack(cback, True);
Stop = GP_CreateStop(cblLine, Close, Null, Null, "", -1, -1, True);

Buy = Cross(e30, e60);
Sell = Stop < Ref(Stop, -1);

Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);

Stop = IIf(Flip(Buy, Ref(Sell,-1)), Stop, Null);

Plot(e30, "EMA(30)", colorRed, styleLine);
Plot(e60, "EMA(60)", colorGreen, styleLine);
Plot(Stop, "Stop", colorBlue, styleLine | styleThick | styleDots);

PlotShapes(IIf(Buy, shapeUpTriangle, shapeNone), colorBlue, 0, Low, -30);
PlotShapes(IIf(Sell, shapeDownTriangle, shapeNone), colorBlue, 0, Low, 30);

=========================================================

I realise that a 10-20 step trialing stop loss is fairly large. I figured that if I could get the code to work then it would be fairly simple to modify it down to a 3-5 step stop loss (which is what I am really after).

In regards to the syntax errors. When I copied the above into the formula editor and asked it to verify syntax the response was "Variable 'stop' used without being initialized". I have probably put the code in the wrong place or failed to tell it where to begin.

Also, I doubt I have the plugin at this stage so I will look into that.

Once again. Greatly appreciate the assistance.

DanHutch
 
Can I ask why you commented that it isn't easy to backtest the Zig Zag indicator?
I wasn't referring to the Zig Zag indicator, which I've never used and don't know how it works. What I really meant is that doing your own code to determine where the peaks and toughs are based on a certain amount of retracement and then using that information as part of a backtest may not be that easy (depending on exactly what you try to do with the information).

Cheers,
GP
 
"Variable 'stop' used without being initialized".
If you have the code in the order you quoted then you shouldn't get that error, as Stop is initialised by the call to the plugin. However, if you don't have the plugin, then I would expect some error relating to that, but it may also give the error you indicate since the Stop array would then not be initialised by the call to the plugin (since the plugin would not be there).

Cheers,
GP
 
I wasn't referring to the Zig Zag indicator, which I've never used and don't know how it works. What I really meant is that doing your own code to determine where the peaks and toughs are based on a certain amount of retracement and then using that information as part of a backtest may not be that easy (depending on exactly what you try to do with the information).

Cheers,
GP

Thanks GP...
 
If you have the code in the order you quoted then you shouldn't get that error, as Stop is initialised by the call to the plugin. However, if you don't have the plugin, then I would expect some error relating to that, but it may also give the error you indicate since the Stop array would then not be initialised by the call to the plugin (since the plugin would not be there).

Cheers,
GP

Thanks GP,

I found the plugin you refered to and, hey presto, everything worked a treat. I feel like I am moving forward again. :)

Greatly appreciated

Danhutch
 
Hi All,

I am wondering what the simplest way is to implement end-of-day stops for intraday systems testing ?
 
Hello,

I am trying to trade ussually E-mini like mininasdaq... and the AB window causes me always big problem:

It is usually necessary a fixed range of Y axis (for example 50 points on a Mini nasdaq 100), in order to have the candles not very small or not very big... with right dimensions, and this range need to move according to the last quote moviments. So if the last quote is 1965, maybe the range min is 1930 and max 1980... (1980-1930=50 points)so you are always able to see the quotation, and if after that the quote change to 1970, then the window Y axis min becomes 1935 and max 1985 and so on....

that is the meccanism that software like quotetracker do.. and this is very usefull for live trading, specially for derivatives, but amibroker only have custome fixed scaling, which you can not modify. Or the automatic scaling which cause problem...


Is there a solution?



PS. I saw different user in the yahoo group have the same problem.



thanks.
 
Hi ricerca, I'm not sure I follow what the issue is. Why does automatic scaling cause a problem? If you adjust the intraday view to the timeframe you want to trade in (say 5 minutes) and you look only at say 30-50 bars (2.5-4) hours, automatic scaling will be in line with the price movement in that period. Maybe I'm missing something?
 
Hi... long time lurker, first time poster (I finally registered!),

I'm fairly new to AB... My initial reason for moving to AB was the auto trading interface with IB. But before I get to that point I need to sort out my AFL code around money mgmt and do a lot more testing...
I've found so much (useful) sample AFL code on this site and around the www but nothing that relates to fixed fractional position sizing. I'm also struggling a bit with the ApplyStop function and how it actually works.

See simple code below (which fails with syntax errs all over the shop - specifically around my dodgy attempt to calculate positionsize. )...

// Global vars
KGRiskPercent = 0.02; /* set max risk per trade to 2% */
KGStopPercent = 0.10; /* set TRAILING stops at 10% of entry price */
SetOption("MaxOpenPositions", 10); /* Prevent death by trading fees */

// Set position size and trailing stop on buys
SetPositionSize((Equity * KGriskpercent) / (C - (C - KGstoplimit))); /* Calculate position size using fixed fractional sizing */
ApplyStop(stopTypeTrailing, stopModePercent, KGStopLimit, 1, True, 1); /* trailing stop based on defined stop %, auto-stop so exit intraday, stop adjusts to trade price, wait 1 bar before re-entry */

Obviously I need help with the SetPositionSize function.... (specifically - fixed fractional position sizing) - I can't believe there isn't a default AFL function to do this????

And I also have a couple of questions on how the applystop function works...
- Does the trailing stop automagically increment and reset (upwards only!) with current price or do I need to re-calculate?
- Do I need to explicitly issue a sell to execute a stop or does it happen automagically?

I've played with the GP_Stops.dll but I can't say I've found it any simpler....

Can anyone help?

thanks!
 
ok so i've *almost* solved my own problem...

// Global vars
KGRiskPercent = 0.02; /* set max risk per trade to 2% */
KGStopPercent = 10; /* set TRAILING stops at 10% of entry price */
SetOption("MaxOpenPositions", 10); /* Prevent death by trading fees */
Capital = 100000;

// Set position size and trailing stop on buys
PositionSize = ((Capital * KGriskpercent) / (C - (C - (C * (KGStopPercent / 100)))) * C); /* Calculate position size using fixed fractional sizing */
ApplyStop(stopTypeTrailing, stopModePercent, KGStopPercent, 1, True, 1); /* trailing stop based on defined stop %, auto-stop so exit intraday, stop adjusts to trade price, , wait 1 bar before re-entry */

I'm using a static value for capital... is there a way to use the equity function so i have the *current* portfolio value?

And in backtesting I'm still getting a lot of losses > 10%. This may be due to major drops below the gap price? I need to play with this some more but if anyone has any comments I'd like to hear them...

I do realise that while a static stoploss of 10% is a nice 4ss covering strategy it's not really optimal.... baby steps.
 
Hi
I am running some back testing with AB on the SPI and was wondering if anyone could help with coding the following 2 requests

1. I want the first trade of the day to enter on or after 9:50am

2. Any open positions to be closed out at 4:29pm

Any suggestions are appreciated

Dean
 
OK..I have sorted the above queries out.

I am now trying to create a continuous contract for the SPI using e signal feed. Has anybody done this?

Thanks

Dean
 
Where do I store my formula so I can reuse it?

I have developed a small library of my own functions, and I want other functions that I write to be able to use these functions, without having to cut and paste the function definition everywhere I want it to be used. How can I make these definitions visible to other functions, while being in a separate file?
 
Thanks Cap'n Black that helped a lot.

I wonder if anyone on here is able make much use of object oriented programming in Amibroker. I have a little experience in java and would find a similar thing useful, as many of my functions require multiple arrays and values to be output. It would be good to have a particular stock as an object that has properties such turning points, support / resistance levels and other mumbo jumbo that can be modified and returned by the object methods just like in java. I know Amibroker offers a java "flavour" with its COM object, but haven't really seen any examples of how to use it for OOP
 
Amibroker STD or Professional?

I am about to purchase Amibroker but don't really know if I need the professional or standard version. Any help or suggestions would be appreciated.

Some points on my situation
1. I am very new to trading and have an older version of Amibroker that I have used to get my feet wet.
2. Only planning to trade stocks on the ASX
3. Only planning to use EOD data.

Thanks in advance for any opinions

John
 
If you have the IB plugin where you can run the live data from IB through Amibroker do you need professional to run this intraday data or will the standard version still suffice?
 
If you have the IB plugin where you can run the live data from IB through Amibroker do you need professional to run this intraday data or will the standard version still suffice?

You need the professional for that.
 
Top