Australian (ASX) Stock Market Forum

Amibroker FAQ

Code:
[COLOR=#000080]upbar2 = upbar OR ( outsidebar AND Ref( downbar, 1 ) ) ;
downbar2 = downbar OR ( outsidebar AND Ref( upbar, 1 ) );

Poi =  outsidebar AND Ref( insidebar, 1 );
Poo =  outsidebar AND Ref( outsidebar, 1 );
Pooi = Poo AND Ref( insidebar, 2 );
Poio = Poi AND Ref( outsidebar, 2 );
Poii =  Poi AND Ref( insidebar, 2 );
Pooo = Poo AND Ref( outsidebar, 2 );
Poooi = Pooo AND Ref( insidebar, 3 );
Pooio = Pooi AND Ref( outsidebar, 3 );
Poioo = Poio AND Ref( outsidebar, 3 );

upbar3 = upbar2 OR ( Poi AND Ref( downbar, 2 ) );
downbar3 = downbar2 OR ( Poi AND Ref( upbar, 2 ) );
 
upbar4 = upbar3 OR ( Poo  AND Ref( upbar, 2 ) );
downbar4 = downbar3 OR ( Poo  AND Ref( downbar, 2 ) );

upbar5 = upbar4 OR  ( Pooi AND Ref( upbar, 3 ) );
downbar5 = downbar4 OR  ( Pooi  AND Ref( downbar, 3 ) );

upbar6 = upbar5 OR  ( Poio AND Ref( upbar, 3 ) );
downbar6 = downbar5 OR  ( Poio  AND Ref( downbar, 3 ) );

upbar7 = upbar6 OR  ( Poii AND Ref( downbar, 3 ) );
downbar7 = downbar6 OR  ( Poii  AND Ref( upbar, 3 ) );

upbar8 = upbar7 OR  ( Pooo AND Ref( downbar, 3 ) );
downbar8 = downbar7 OR  ( Pooo AND Ref( upbar, 3 ) );

upbar9 = upbar8 OR  ( Poooi AND Ref( downbar, 4 ) );
downbar9 = downbar8 OR  (Poooi  AND Ref( upbar, 4 ) );

upbar10 = upbar9 OR  ( Pooio AND Ref( downbar, 4 ) );
downbar10 = downbar9 OR  (  Pooio AND Ref( upbar, 4 ) );

upbar11 = upbar10 OR  (  Poioo AND Ref( downbar, 4 ) );
downbar11 = downbar10 OR  ( Poioo  AND Ref( upbar, 4 ) );
[/COLOR]


These statements are all looking into the future. Any Ref statement with a positive number is forward looking.
(edit: not sure why my writing is blue now! :) )

 
Can you please tell me why my buy & sell signals arent working on this chart. I want the buy to happen when the fast mma's have all crossed above the slow mma's and the opposite for a sell. I get arrows on the chart but not when they cross over. I was also hoping to use this as part of an exploration.

HTML:
MaxGraph = 12;
/* Grey lines */
Graph0= EMA( Close, 3 );
Graph1= EMA( Close, 5 );
Graph2= EMA( Close, 7 );
Graph3= EMA( Close, 9 );
Graph4= EMA( Close, 11 );
Graph5= EMA( Close, 13 );
Graph0Style = Graph1Style = Graph2Style = Graph3Style =Graph4Style =Graph5Style = 1;
Graph0Color = Graph1Color = Graph2Color = Graph3Color =Graph4Color =Graph5Color = colorLightGrey;

/* Blue lines */
Graph6= EMA( Close, 21 );
Graph7= EMA( Close, 24 );
Graph8= EMA( Close, 27 );
Graph9= EMA( Close, 30 );
Graph10= EMA( Close, 33 );
Graph11 = EMA( Close, 36 );
Graph6Style = Graph7Style = Graph8Style =Graph9Style =Graph10Style = Graph11Style = 1;
Graph6Color = Graph7Color = Graph8Color =Graph9Color =Graph10Color = Graph11Color = colorBlueGrey;


sma=(Graph0-Graph5);
Lma=(Graph6-Graph11);


Buy = sma > Lma;
Sell = lMA > sMA;


PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorBrightGreen);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed);

mma.jpg
 

Attachments

  • mma.jpg
    mma.jpg
    7 KB · Views: 0
I found this code kicking around on the net and I 've modified it to just use a Chandelier stop. It works fine for going long but I can't modify it to go short.

I've tried swapping all the arrows and variables around but can't seem to get it to work. :banghead:

Any help modifying the code to run short would be very much appreciated.

//http://www.amibroker.com/members/traders/06-2009.html

Version(5.20); // requires v5.20
SetBarsRequired(sbrAll);

// get start date
Start = Cross(DateNum(),ParamDate("Start date", "2009-10-30" ) );
Started = Flip( Start, 0 );

StopLevel = Param("Fixed perc %", 14, 0.1, 50, 0.1)/100;
StopATRFactor = Param("ATR multiple", 4, 0.5, 10, 0.1 );
StopATRPeriod = Param("ATR period", 14, 3, 50 );

// Chandelier ATR-based stop
sup = C - StopATRFactor * ATR( StopATRPeriod );
res = C + StopATRFactor * ATR( StopATRPeriod );

// calculate trailing stop line
trailARRAY = Null;
trailstop = 0;
for( i = 1; i < BarCount; i++ )
{
if( Started[ i ] == 0 ) continue;
if( C[ i ] > trailstop AND C[ i - 1 ] > trailstop )
trailstop = Max( trailstop, sup[ i ] );

else
if( C[ i ] < trailstop AND C[ i - 1 ] < trailstop )
trailstop = Min( trailstop, res[ i ] );
else
trailstop = IIf( C[ i ] > trailstop, sup[ i ],res[ i ] );
trailARRAY[ i ] = trailstop;
}

// generate buy/sell signals based on crossover with trail stop line
Buy = Start OR Cross( C, trailArray );
Sell = Cross( trailArray,C );

PlotShapes(Buy*shapeUpArrow,colorGreen,0,trailarray);
PlotShapes(Sell*shapeDownArrow,colorRed,0,trailarray);

//Plot( Close,"Price",colorBlack,styleBar);
//SetBarFillColor( colorYellow );
Plot( trailARRAY,"trailing stop level", colorRed, styleLine );
 

Attachments

  • Sylvain Vervoort - Average True Range Trailing Stops Short.afl
    2.4 KB · Views: 17
Hi

Can anyone please help me. Im trying to optimise this ATR Trailing stop. Im not sure how to get it to work.


Thanks :)

HTML:
multiplier = Optimize("ATR Multiplier", 2.2, 0, 10, 0.1);


Buy = 	Close > Ref( High , -1 )

;


Sell = 0; 




_SECTION_BEGIN("ATR Trailing Stop");


multiplier = Param("ATR Multiplier", 2.2, 0, 10, 0.1);


// ATR Trailing stop - stevo 2006
// When stop line drops exit is triggered.


myATR= multiplier*ATR(10); // calculate ATR
initial=C-myATR; // raw stop - not racheted

stop[ 0 ] = Close[ 0 ];
for( i = 1 ; i < BarCount; i++)
{
 if( Close[ i ] > stop[ i - 1])
{
 temp = Close[ i ] - myATR[ i ];
 if( temp > stop[ i - 1 ] ) stop[ i ] = temp;
 else stop[ i ] = stop[ i - 1 ];
}
 else
 stop[ i ] = initial[ i ];
}



Sell = C < Ref( stop, -1);


Plot( stop, "ATR Stop", colorRed, styleLine);
 
Hi

Can anyone please help me. Im trying to optimise this ATR Trailing stop. Im not sure how to get it to work.


Thanks :)

PHP:
multiplier = Optimize("ATR Multiplier", 2.2, 0, 10, 0.1);
period = Optimize("Period", 10, 5, 100, 5);
myATR = multiplier*ATR(period);
for the period the Average True Range is calculated from.

In the brackets after "Period" the first number is the default number, second number is the minimum, third maximum and fourth is steps.

Hint = change step length to shorten optimisation time.
 
Hi Wysiwyg

Thanks for that. I tried it but Im still having trouble. Im happy with the 10 period setting. What Im trying to optimise is the multiplier and

HTML:
multiplier = Optimize("ATR Multiplier", 2.2, 0, 10, 0.1);
doesnt seem to work. I get the same result on all settings. :confused:
 
Hi Wysiwyg

Thanks for that. I tried it but Im still having trouble. Im happy with the 10 period setting. What Im trying to optimise is the multiplier and

HTML:
multiplier = Optimize("ATR Multiplier", 2.2, 0, 10, 0.1);
doesnt seem to work. I get the same result on all settings. :confused:

Use the optimise multiplier and optimise period together on the same optimisation run
 
Hi Wysiwyg

Thanks for that. I tried it but Im still having trouble. Im happy with the 10 period setting. What Im trying to optimise is the multiplier and

HTML:
multiplier = Optimize("ATR Multiplier", 2.2, 0, 10, 0.1);
doesnt seem to work. I get the same result on all settings. :confused:

OK I worked out what was the problem. I have to remove the line

HTML:
multiplier = Param("ATR Multiplier", 2.2, 0, 10, 0.1);

There is one other problem. How do I convert my initial stop to be a max loss of 2% from the buy price? Its currently
HTML:
initial=C-myATR;
 
Anyone know how to implement two ApplyStop functions in one strategy please?

For example:

PHP:
Buy = Cross(MACD(), Signal());
Sell - 0;
Short = Cross(70, RSI());
Cover = 0;

ApplyStop(stopTypeTrailing, stopModePercent, 0.20, 2); // Trailer for Longs
ApplyStop(stopTypeTrailing, stopModePercent, 0.10, 2); // Trailer for Shorts

There needs to be a function that links the Long trailing stop to the Buy and the Short trailing stop to the Sell. After +10 hours of searching archives I have not found the answer. From what I am experiencing, the ApplyStop function can't be isolated to one variable.
 
There needs to be a function that links the Long trailing stop to the Buy and the Short trailing stop to the Sell.

Very busy atm so haven't been able to add too much to this thread, will look through some posts when I get time and try to help if I can.

Wysiwyg, is this formula from the library any help?

http://www.amibroker.com/library/detail.php?id=1133

(you may need this bit too..)

http://www.amibroker.com/kb/2007/03/24/how-to-plot-a-trailing-stop-in-the-price-chart
 
Sorry to crash the AmiBroker thread with a n00b question.

I'm trying to decide which version of AmiBroker would be right for me.

From poking around there is AmiBroker Standard Edition and AmiBroker Professional edition.

The comparison between the two at http://www.amibroker.com/order.php makes little sense to me.

From the looks of it, the professional edition has real time capabilities provided.

I was of the impression that the standard edition could effectively be used as real time if you had an IB account and made use of the IB Data Plugin available here: http://www.amibroker.com/ib.html

From what I can seen, unless you have an eSignal, etc. data feed, you can just use the standard edition of AmiBroker ands till pump live data into it using the above mentioned IB Data Plugin.

Am I completely missing something here and therefore should I seriously consider the Professional edition?

My intended usage of AmiBroker is for my everyday charting and then slowly but surely system building. It is my intention that I will be using EOD data initially, but if I have the potential to use real time data then I most likely will.

Is there any other AmiBroker add-ons I should also consider? From info provided AmiQuote looks like it just pulls data (eod and fundamentals) from free sources such as Yahoo Finance, etc.

Is the AFL Code Wizard helpful in coding your own AmiBroker code? I have some experience with object orientated programming, however I am by no means a coding genius... I enjoy sunshine to much for that :)

Thanks in advance for the feedback.
 
I'm trying to decide which version of AmiBroker would be right for me.
From poking around there is AmiBroker Standard Edition and AmiBroker Professional edition.
Thanks in advance for the feedback.
I purchased the latter so don't know what the comparison is. In my opinion Ami. is immensely versatile yet can be used with little or no AFL knowledge. Although you will need to learn the language if you want to transfer your ideas into AFL for strategy testing, custom indicators, scanning and exploration etc. I get by with a little help from the more advanced AFL ers such as Cap. Black and Mike on AMI. Yahoo Forum along with the various formulas that are available to owners in the AFL library.

Hi Wysiwyg
Did you ever get that advance decline line working? I contacted Amibroker to get the run down on how to set one up but it sounds really complicated. I have no idea how to use the "add to composite function" . Just wondering how hard it was?
No pennies it is one of the many indicators I haven't used.
 
Is anyone interested in giving me a quote for coding a system. I have purchased a confidential system which I want coded into amibroker, Unfortunatley kaveman is unavailable as he guaranteed confidentialilty. I do not believe it is that hard, just a bit beyond me and I would not expect it to take long.
Thanks Kesso
 
Just built a new PC and am moving over programs any tips on AB.....cannot remember what to do with the software key:mad:.
 
Just built a new PC and am moving over programs any tips on AB.....cannot remember what to do with the software key:mad:.
I lost the key awhile ago and this is what AB told me to do. I have removed the link code obviously and I don't know if it will trigger any memories for you so good luck with it.

INSTRUCTIONS HOW TO APPLY THE KEY FILE:

In order to activate the software please download
and run the software activation wizard from:
http://reg.amibroker.com/ABRegxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

If you are running 64 bit version of AmiBroker on x64 Windows, please use 64-bit activation key from:
http://reg.amibroker.com/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Simply CLICK on the link(s) above, do not re-type manually as it is too easy to make a mistake.

After that, please start AmiBroker and choose Help->About menu to see your name displayed.

IMPORTANT:
Please DO NOT reveal this password and user name to anyone.

No-one from amibroker.com will ever request you to provide these details and any e-mail that is trying to persuade you to reveal this information is hijack attempt.
 
Top