Australian (ASX) Stock Market Forum

Amibroker FAQ

Thanks Gringotts Bank, I haven't heard of SAR before, will check it out.

I take it there's no simple way to adjust the stoploss precent on the fly then?


JJZ

Not that I know of, but I'm no expert.

Maybe something like:

a = iif(Barssince(buytrigger)>5,15,10); // if bars since your buy conditions are met is > 5, then 15, otherwise, 10
Applystop(stoptypeloss,stopmodepercent,a);

I haven't tested it.
 
Is there an easy way to adjust a stop based on holding time?

For example, purchase a stock with a 15% stop loss:

ApplyStop( stopTypeLoss, stopModePercent, 15, 2, 0, 0 );

Then after 30 days reduce it to:

ApplyStop( stopTypeLoss, stopModePercent, 10, 2, 0, 0 );

Thanks
JJZ

Hi JJZ --

If the built-in exits do not allow the flexibility you want, you can compute the exit price and set another rule to exit when that price level has been reached or exceeded.

If you will be trading US markets, keep in mind that Stop orders and Good 'Til Canceled orders are being restricted. Check with the broker, exchange, and clearing house where your trades will be executed to learn what orders they accept and how they are handled.

When developing systems that use Stop exits, build in an allowance for slippage. Stop orders always pay the bid-ask spread, or higher, in frictional costs. When trading highly liquid issues, such as SPY, the bid-ask spread will be $0.01 almost all of the time. As liquidity decreases, and as trading anxiety increases, the spread increases. During periods of crisis and when trading illiquid issues, just when that exit is needed to protect equity, the bad fill of a Stop order can be wealth-destroying.

Best,
Howard
 
Hi All,

I have been trying to learn Amibroker code independently without asking dumb questions here however I have never been able to work out how to create counters in loops. Can anyone assist?

An example would be:

Code:
periods = 10;

for (i = 0 ; i < periods ; i++);
{
iif((Ref(Close,-i) > 1), Count++, Count--);
}

Plot( Count, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style")  );

This comes up with "error 29: Variable 'count' used without having been intitialize."

If I add the code
Code:
Count = 0

Then count is always equal to 0 and does not give me the desired outcome which in this case would be to add and plot the number of times the close is above 1 in the past 10 bars.
 
Hi All,

I have been trying to learn Amibroker code independently without asking dumb questions here however I have never been able to work out how to create counters in loops. Can anyone assist?

An example would be:

Code:
periods = 10;

for (i = 0 ; i < periods ; i++);
{
iif((Ref(Close,-i) > 1), Count++, Count--);
}

Plot( Count, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style")  );

This comes up with "error 29: Variable 'count' used without having been intitialize."

If I add the code
Code:
Count = 0

Then count is always equal to 0 and does not give me the desired outcome which in this case would be to add and plot the number of times the close is above 1 in the past 10 bars.


First of all your are doing it wrong. In addition Iif function is used improperly. Read up coding mistakes here https://www.amibroker.com/guide/a_mistakes.html

Last but not least there is no looping required to output your result. Simply use Sum() function - just one line.

Code:
threshold = 1;
periods = 10;

count = Sum( (C > threshold) - (C < threshold), periods );
 
Hi All,

I have been trying to learn Amibroker code independently without asking dumb questions here however I have never been able to work out how to create counters in loops. Can anyone assist?

Hi skcots:

Chapter 3 of my book, "Introduction to AmiBroker," has a set of exercises that work through the various features of AmiBroker that you might use. Later chapters have more detailed information about AmiBroker, hints on programming, and examples of programs.

You can download a free copy from this webpage:
http://www.blueowlpress.com/123-2/introduction-to-amibroker

Best,
Howard
 
I fail to see what a book that basically re-writes stuff that is already written in the AB help is supposed to add to a proper link explaining to the point what is wrong and to a given solution that is better than using loop version.

But I see that it might still not be clear that instead of a loop a single line is doing the same thing.


Code:
periods = 10; 
threshold = 1;

for ( i = 0; i < periods-1 && i < BarCount; i++ )
    cnt[i] = Null;
 
for( i = periods-1; i < BarCount; i++ ) {
    count = 0;
    for( j = 0; j < periods; j++ ) {
        if( C[i-j] > threshold )
	    count++;
        else 
	    count--;
    } 
    cnt[i] = count;
}

Plot( cnt, "Loop (array)", colorYellow, ParamStyle("Style") );
Plot( count, "Loop (last element)", colorYellow, styleDashed );

Plot( Sum( (C > threshold) - (C < threshold), periods ), "Sum() (array)", ColorOrange, ParamStyle("Style") );
Plot( LastValue(Sum( (C > threshold) - (C < threshold), periods )), "Sum() (last element)", ColorOrange, styleDashed  );

//Plot( Sum( (C > threshold), periods ), _DEFAULT_NAME(), ColorGreen, ParamStyle("Style") );
//Plot( Sum( (C < threshold), periods ), _DEFAULT_NAME(), colorRed, ParamStyle("Style") );
 
Hi Trash,

Thanks heaps for the explanation. I completely missed your post this morning when I had a look at this thread.
The 'sum' function is exactly what I need. Also thanks for the example using the loops.
 
Here is a goody. Where do I start in order to create a present time DOM histogram. Further clarity is -- an histogram of the real time market depth in number of shares or contracts. Politeness please. ;)
 
Here is a goody. Where do I start in order to create a present time DOM histogram. Further clarity is -- an histogram of the real time market depth in number of shares or contracts. Politeness please. ;)

Great idea.

Maybe start with GetRTData().

There's a Bid Vs Ask Dashboard in the library.
 
Here is a goody. Where do I start in order to create a present time DOM histogram. Further clarity is -- an histogram of the real time market depth in number of shares or contracts. Politeness please. ;)

Don't reinvent the wheel, take a free trial of Iguana2
 
Great idea.

Maybe start with GetRTData().

There's a Bid Vs Ask Dashboard in the library.
Not market depth as in number of shares or contracts in queue to at least 5 levels.

Don't reinvent the wheel, take a free trial of Iguana2
Yes I think Ami. will need this, that and the other to get the data but I asked the question anyway. I see Ninjacator has one.
 
Does anyone else find it frustrating in AB that the horizontal line drawing tool, draws across the whole chart, when you only want a small line. I know that its easy enough to use the trend line tool but can be a bit fiddly to get it straight.
 
Hey guys need some help with 'param' in amibroker.

Range Period=Param("Range Period" , 100, 20, 200, 1);

Max Range %=Param("Max Range %" , 10, 1, 20, 1);


Am i doing it right? i want Range period default value at 100 days, minimum and maximum value of 20 to 200. Same goes for Max range%, at 10% with range of 1 to 20%.

Also what "step - defines minimum increase of the parameter via slider in the Parameters dialog"? from amibroker online guide.


Cheers for any answers.
 
Hey guys need some help with 'param' in amibroker.

Range Period=Param("Range Period" , 100, 20, 200, 1);

Max Range %=Param("Max Range %" , 10, 1, 20, 1);


Am i doing it right? i want Range period default value at 100 days, minimum and maximum value of 20 to 200. Same goes for Max range%, at 10% with range of 1 to 20%.

Also what "step - defines minimum increase of the parameter via slider in the Parameters dialog"? from amibroker online guide.


Cheers for any answers.

The step is the last number - you have it set as '1'. If you changed it to 0.1, it would step up in 0.1 increments.
On the chart, right click to open param window, then slide to change the step up or down.
 
Amibroker exits

I have been looking for an answer to what is going to be a simple question for those who know Amibroker well.

I am trying to code a simple proof-of-concept backtest with two exits. I am using EOD data, and I'll describe this long-only for simplicity.

So, given that I am in a long position:
The first exit is a stop loss. I want to exit immediately if the low of the day crosses the low of the previous day

The second exit will exit at the close of the third day, assuming the stop loss has not been hit.

I can code these exits separately, but what is tripping me up when I try to combine them is the fact that they have different SellPrice requirements.

This works:
SetTradeDelays(0 ,0 ,0 ,0 ); // no delays, entries and exits trigger today
x = Ref(L,-1 ); // low of prev day for stop loss exit
SellPrice = x;
Sell=Cross(x,Low);

And so does this
SetTradeDelays(0 ,0 ,0 ,0 ); // no delays, entries and exits trigger today
SellPrice = Close;
Sell = BarsSince(Buy)==2;

But how do I get them to work properly together?

Any help appreciated, thanks.
 
Re: Amibroker exits

I have been looking for an answer to what is going to be a simple question for those who know Amibroker well.

I am trying to code a simple proof-of-concept backtest with two exits. I am using EOD data, and I'll describe this long-only for simplicity.

So, given that I am in a long position:
The first exit is a stop loss. I want to exit immediately if the low of the day crosses the low of the previous day

The second exit will exit at the close of the third day, assuming the stop loss has not been hit.

I can code these exits separately, but what is tripping me up when I try to combine them is the fact that they have different SellPrice requirements.

This works:
SetTradeDelays(0 ,0 ,0 ,0 ); // no delays, entries and exits trigger today
x = Ref(L,-1 ); // low of prev day for stop loss exit
SellPrice = x;
Sell=Cross(x,Low);

And so does this
SetTradeDelays(0 ,0 ,0 ,0 ); // no delays, entries and exits trigger today
SellPrice = Close;
Sell = BarsSince(Buy)==2;

But how do I get them to work properly together?

Any help appreciated, thanks.

Untested, but should work ok.

SetStopPrecedence( stopTypeNBar, stopTypeProfit, stopTypeTrailing, stoptypeloss );//good to include
Sellprice = ref(L,-1);
Sell = Sellprice>=L and Sellprice<=H;
Applystop(stoptypenbar,stopmodebars,3);
 
Re: Amibroker exits

Untested, but should work ok.

SetStopPrecedence( stopTypeNBar, stopTypeProfit, stopTypeTrailing, stoptypeloss );//good to include
Sellprice = ref(L,-1);
Sell = Sellprice>=L and Sellprice<=H;
Applystop(stoptypenbar,stopmodebars,3);



Thanks very much for the help, GB.

The NBar stop part is not working correctly. I am getting exits marked as 'n-bar' in the correct places, but the actual exit, the exit price, is the previous low, the same as the stop-loss exits. I'm trying to get the second exit to occur at the close of the third day.
 
Top