Australian (ASX) Stock Market Forum

Amibroker FAQ

Help with Amibroker Formula

Hi All,

I am new to Amibroker and I am hoping to get some help with a formula. The formula below which I got off the internet outputs data to a text file.
It outputs it to only 2 decimal places but I would like it to output to 5 decimal places so that I can use it for Forex. Can anyone tell me how to do that please?

Thank You

fmkdir( "C:\\OHLC" );
Buy = ( (DateNum() >= 971225) AND (DateNum() <= 1110110) );
for( i = 0; i < BarCount; i++ )
if( Buy )
{
fh = fopen( "C:\\OHLC\\"+Name()+".txt", "a");
if( fh )
{
y = Year();
m = Month();
d = Day();
r = Hour();
e = Minute();

for( i = 0; i < BarCount; i++ )
if( Buy )

{
fputs( Name() + "," , fh );
ds = StrFormat("%02.0f%02.0f%02.0f,",
y[ i ], m[ i ], d[ i ] );
fputs( ds, fh );

ts = StrFormat("%02.0f:%02.0f,",
r[ i ],e[ i ]);
fputs( ts, fh );

qs = StrFormat("%.2f,%.2f,%.2f,%.2f,%.0f\n",
O[ i ],H[ i ],L[ i ],C[ i ],V[ i ] );
fputs( qs, fh );
}
fclose( fh );
}
}
 
Re: Help with Amibroker Formula

Never mind, I worked it out.

Just changed

qs = StrFormat("%.2f,%.2f,%.2f,%.2f,%.0f\n",

to

qs = StrFormat("%1.4f,%1.4f,%1.4f,%1.4f,%.0f\n",

to give 4 decimal places. One step closer to being a programmer!:)
 
I was doing some testing and wondering why profitable trades were losing, then I discovered the exit was set to the close of the bar. Is there anyway to adjust it so entries and exits occur perfectly? Obviously they don't, but for me it would be close enough.
 
Nevermind, setting stops to "exit at intraday price" and using "buyprice/shortprice" seems to do the job.
 
I'm trying to create a number of separate buy conditions, each with their own buyprice. Example:

buy=(close>X AND buyprice=X)
OR (close>Y AND buyprice=Y)
OR (close>Z AND buyprice=Z);

How do I do this? Basic stuff I'm sure, but a seach hasn't found anything yet. The idea is that the buyprice forces the backtesting to fire at a specific price, rather than ohlc. It works fine when I use one instance of buyprice, but not when using multiple instances.
 
Re: Amibroker Help

Amibroker Forum that might be of interest to Amibroker users. Doesn't appear to be a lot of traffic there but you might find the answers to your questions.

Link ...

Amibroker Fan Forum.




.
 
Amibroker Exit after no profit and n bars

Hi,

How do I code into a system the following:

if I haven't made a profit of 5% in 5 days then exit the trade.

Your help would be appreciated.

Thanks
 
One way to achieve that would be using the ApplyStop function. Use one to set a 5% profit target and another to set an N-Bar stop of 5 days. If the profit stop isn't hit within 5 days then the N-Bar stop would close the trade. If you use these as your exit then use:

Sell=0;
 
Thanks for the reply but I think you mis-understood the question.

I don't want to set a profit target. I want to set an N-bar stop but this must be conditional on the trade profit being less than 5% within 5 days.

So, if the trade hits 5% profit within 5 days then ignore the stop and carry on.
If by day 5 the profit is less than 5% then exit the trade.

Is this possible?
 
Thanks for the reply but I think you mis-understood the question.

I don't want to set a profit target. I want to set an N-bar stop but this must be conditional on the trade profit being less than 5% within 5 days.

So, if the trade hits 5% profit within 5 days then ignore the stop and carry on.
If by day 5 the profit is less than 5% then exit the trade.

Is this possible?

I'm sure it is possible but I have no idea on how to code it up. Maybe using a IIF code of some sort.
 
I’m doing some back testing using Amibroker but i’ve run into a problem. In my data when a stock goes into a trading halt for a day it lists the open, high, low, close and volume as 0. My AFL formula reads this as the price dropping to zero and therefore stops me out at 0. This essentially wipes out my portfolio.

What is the best way to get around this?
 
Hello All,

I'm interested in hearing from those that use Tradesim in combination with Amibroker, as opposed to the normal Metastock>TradeSim combo.

What I'm interested in finding out is:

1. How do you create your Amibroker TradeFile and import it into TradeSim?

2. What parameters / variables do you capture within the Tradefile?

Currently, I am only able to capture the following Information about each trade.

- Trade Position ie Long or Short
- Symbol
- Entry Date
- Exit Date
- Initial Stop
- Entry Price
- Exit Price
- Volume

However, I'd now like to capture other metrics within TradeSim such as Volatility, Trade Highest, Trade Lowest, etc and consequently was interested if any others are already doing this.


Many Thanks in advance,
 
How to stop the deletion of older data? My charts stretch back about 8 months, being deleted day by day. The number of bars in the database setting doesn't seem to make a difference, as it's currently set at over a year.
 
Hi all,

I'm new to the forums, to amibroker, and to trading haha

Anyway I'm just playing around trying to figure out how to do some simple things first...

how would I write something like the following:

to explore the following only in daily charts;
when an EMA 15 crosses an EMA 30
and to specify time frame (e.g. only if this happened today, or only if it happened in the last 3 days).

and same thing for MACD for instance (in specified time-frame).

Thanks :bowdown:
 
How to stop the deletion of older data? My charts stretch back about 8 months, being deleted day by day. The number of bars in the database setting doesn't seem to make a difference, as it's currently set at over a year.

To start with, have a look through the doc below, specifically the "data" tab. Do you have the "limit number of saved quotations" box ticked?

http://amibroker.net/guide/w_preferences.html
 
ok, are you using intraday or end of day data? What format?

It sounds like database size is being restricted by one of the database settings if your data is being truncated each day.
 
ok, are you using intraday or end of day data? What format?

It sounds like database size is being restricted by one of the database settings if your data is being truncated each day.

Intraday, but I've set the limits quite high. In the database settings, number of bars is set to 4 years. It was about 2 years earlier today, but still each day is being deleted, so it must be another setting.
 
Intraday, but I've set the limits quite high. In the database settings, number of bars is set to 4 years. It was about 2 years earlier today, but still each day is being deleted, so it must be another setting.

I don't use intraday data so I'm not going to be much help, unless someone else has any suggestions then contacting TJ or Marcin at support with all the relevant details would be the quickest way to sort the issue out. Quite a few of the intraday suppliers (IB in particular) often have bugs in their database plugins that can cause things to go awry.

I'll have a search through my personal AB library tomorrow, but with intraday data it's always difficult to track down problems. Sorry I can't be of more help. Post your solution back here if you do contact support as ASF often turns up in Google searches for Amibroker issues. Cheers
 
Top