Australian (ASX) Stock Market Forum

Amibroker FAQ

Hi Howard,

I have used the valuewhen function but the output data is disorganized and sometimes incorrect. I am using the following AFL code with the Explore utility:
Code:
Filter=1; 
AddColumn(O,"Open", 1.6); 
AddColumn(H,"High", 1.6); 
AddColumn(L,"Low", 1.6); 
AddColumn(C,"Close", 1.6); 
/*AddColumn(V,"Volume",1.0); 
AddColumn(OI,"Open Interest",1.0); */

AddColumn(TimeFrameGetPrice("H",inDaily,0), "HHV", 1.6);
AddColumn(ValueWhen(TimeFrameGetPrice("H",inDaily,0)==H, DateTime()), "Date/Time", formatDateTime);

The have set the Explore utility on a 5-min periodicity under 'General settings' as I want the result to return which 5 min bar the daily high had occurred on.

This is an example of the output data:
View attachment 61235

From the example above, it seems as though the DateTime() function is waiting for the Explore utility to actually reach the correct bar before it prints the correct data. I am not sure why it is doing this when it should already have the correct data when it compared the High array to the TimeFrameGetPrice array.

How can I fix this?

Cheers

Output value of Valuewhen is constant till a new true conditions appears. Then new constant value steps in based on that new true condition.

Code:
Filter = 1;
AddColumn( O, "Open", 1.6 );
AddColumn( H, "High", 1.6 );
AddColumn( L, "Low", 1.6 );
AddColumn( C, "Close", 1.6 );
/*AddColumn(V,"Volume",1.0);
AddColumn(OI,"Open Interest",1.0); */

DH = TimeFrameGetPrice( "H", inDaily, 0 );

AddColumn( ValueWhen( DH == H, H ), "HHV", 1.6 );
AddColumn( ValueWhen( DH == H, DateTime() ), "Date/Time", formatDateTime );

But if you just wanna have output of datetimes where high of day occurred you don't need to use that code and valuewhen. Simply set Filter = H == DH; as seen in my example.
 
Code:
Filter = 1;
AddColumn( O, "Open", 1.6 );
AddColumn( H, "High", 1.6 );
AddColumn( L, "Low", 1.6 );
AddColumn( C, "Close", 1.6 );
/*AddColumn(V,"Volume",1.0);
AddColumn(OI,"Open Interest",1.0); */

DH = TimeFrameGetPrice( "H", inDaily, 0 );

AddColumn( ValueWhen( DH == H, H ), "HHV", 1.6 );
AddColumn( ValueWhen( DH == H, DateTime() ), "Date/Time", formatDateTime );

Alternative code with different filtering

Code:
DH = TimeFrameGetPrice( "H", inDaily, 0 );
DHcond = H == DH;
Filter = DHcond;

AddColumn( O, "Open", 1.6 );
AddColumn( H, "High", 1.6 );
AddColumn( L, "Low", 1.6 );
AddColumn( C, "Close", 1.6 );
/*AddColumn(V,"Volume",1.0);
AddColumn(OI,"Open Interest",1.0); */

AddColumn( ValueWhen( DHcond, H ), "HHV", 1.6 ); // redundant High column
AddColumn( ValueWhen( DHcond, DateTime() ), "Date/Time", formatDateTime ); // redundant datetime column

Or more simple

Code:
DH = TimeFrameGetPrice( "H", inDaily, 0 );
Filter = H == DH;

AddColumn( O, "Open", 1.6 );
AddColumn( H, "High", 1.6 );
AddColumn( L, "Low", 1.6 );
AddColumn( C, "Close", 1.6 );
/*AddColumn(V,"Volume",1.0);
AddColumn(OI,"Open Interest",1.0); */

AddColumn( H, "HHV", 1.6 ); // redundant High column
AddColumn( DateTime(), "Date/Time", formatDateTime ); // redundant datetime column

Both outputs are equal
 
Alternative code with different filtering

Code:
DH = TimeFrameGetPrice( "H", inDaily, 0 );
DHcond = H == DH;
Filter = DHcond;

AddColumn( O, "Open", 1.6 );
AddColumn( H, "High", 1.6 );
AddColumn( L, "Low", 1.6 );
AddColumn( C, "Close", 1.6 );
/*AddColumn(V,"Volume",1.0);
AddColumn(OI,"Open Interest",1.0); */

AddColumn( ValueWhen( DHcond, H ), "HHV", 1.6 ); // redundant High column
AddColumn( ValueWhen( DHcond, DateTime() ), "Date/Time", formatDateTime ); // redundant datetime column

Or more simple

Code:
DH = TimeFrameGetPrice( "H", inDaily, 0 );
Filter = H == DH;

AddColumn( O, "Open", 1.6 );
AddColumn( H, "High", 1.6 );
AddColumn( L, "Low", 1.6 );
AddColumn( C, "Close", 1.6 );
/*AddColumn(V,"Volume",1.0);
AddColumn(OI,"Open Interest",1.0); */

AddColumn( H, "HHV", 1.6 ); // redundant High column
AddColumn( DateTime(), "Date/Time", formatDateTime ); // redundant datetime column

Both outputs are equal

Arghhhhhhhhhhh trash this is so much more easier!
Thank-you very much. I didn't realise that Filter could be used for this.
 
Arghhhhhhhhhhh trash this is so much more easier!
Thank-you very much. I didn't realise that Filter could be used for this.

That reserved variable is called Filter for a reason. ;)

default setting Filter = 1; simply means Filter = true;

So if you use that Filter setting then no filtering is applied but all possible output based on entire available barcount of a symbol is sent to result list.
 
That reserved variable is called Filter for a reason. ;)

default setting Filter = 1; simply means Filter = true;

So if you use that Filter setting then no filtering is applied but all possible output based on entire available barcount of a symbol is sent to result list.

Another question if possible.

I have just changed my database settings to better reflect the backfilled data. I have changed the 'Daily time-compression uses' radio button to "Day/Night session times as defined above". The data being imported is FX data and the data source defines the day session from 0900-0000 and the evening from 0000-0900 the next day.
The problem now is that AmiBroker is refusing to present the data on the Daily time scale.
I can view data on every other time scale, except for daily.

Please see images below:
new settings.png
Hourly
hourly.jpg
1-min
minutely.jpg
Daily
daily.jpg


Daily chart is the same as 1-min
 
Another question if possible.

I have just changed my database settings to better reflect the backfilled data. I have changed the 'Daily time-compression uses' radio button to "Day/Night session times as defined above". The data being imported is FX data and the data source defines the day session from 0900-0000 and the evening from 0000-0900 the next day.
The problem now is that AmiBroker is refusing to present the data on the Daily time scale.
I can view data on every other time scale, except for daily.

Please see images below:
View attachment 61237
Hourly
View attachment 61238
1-min
View attachment 61239
Daily
View attachment 61240


Daily chart is the same as 1-min

I found a work-around: Just changed the database settings to 'local time' and added in a timezone offset. This is pretty poor though as every other quote in the database is now incorrectly adjusted for time.
 
Another question if possible.

I have just changed my database settings to better reflect the backfilled data. I have changed the 'Daily time-compression uses' radio button to "Day/Night session times as defined above". The data being imported is FX data and the data source defines the day session from 0900-0000 and the evening from 0000-0900 the next day.
The problem now is that AmiBroker is refusing to present the data on the Daily time scale.
I can view data on every other time scale, except for daily.

Please see images below:
View attachment 61237

You settings are wrong because your sessions are overlapping.

You should set like this.
69JsRyd.png

Besides you are using a very old version. 5.40 or something
 

Attachments

  • 69JsRyd.png
    69JsRyd.png
    8.1 KB · Views: 0
You settings are wrong because your sessions are overlapping.

You should set like this.
69JsRyd.png

Besides you are using a very old version. 5.40 or something

Thanks trash. I tried this but when I switch to daily format, the OHLC bars are different to those that are provided by the broker.

A follow-up question to the previous exploration issue:
If I am trying to determine when the daily high and daily low occured within the same exploration, I will need a second date/time column to display that information (only one column at the moment). How do I add an additional date/time column for that output data?

Code:
AddColumn(DateTime(), "date/time", formatDateTime);

The above just gives me the same result as the original column.

Thanks
 

Attachments

  • 69JsRyd.png
    69JsRyd.png
    8.1 KB · Views: 0
Thanks trash. I tried this but when I switch to daily format, the OHLC bars are different to those that are provided by the broker.

A follow-up question to the previous exploration issue:
If I am trying to determine when the daily high and daily low occured within the same exploration, I will need a second date/time column to display that information (only one column at the moment). How do I add an additional date/time column for that output data?

Code:
AddColumn(DateTime(), "date/time", formatDateTime);

The above just gives me the same result as the original column.

Thanks

Your broker probably has future looking bars. Then go to AB support. I'm not from AB.

As for code
Code:
dt = DateTime();

DH = TimeFrameGetPrice( "H", inDaily, 0 );
DL = TimeFrameGetPrice( "L", inDaily, 0 );

DHcond = H == DH;
DLcond = L == DL; 

Filter = DHcond OR DLcond;

SetOption( "Nodefaultcolumns", True );
AddTextColumn( Name(), "Symbol", 1 );
AddColumn( O, "Open", 1.6 );
AddColumn( IIf( DHcond, ValueWhen( DHcond, dt ), Null ), "HHV DT", formatDateTime, colorLightGrey, colorDarkGreen, 120 );
AddColumn( H, "High", 1.6, IIf( DHcond, colorLightGrey, colorDefault), IIf( DHcond, colorDarkGreen, colorDefault) );
AddColumn( IIf( DLcond, ValueWhen( DLcond, dt ), Null ), "LLV DT", formatDateTime, colorLightGrey, colorDarkRed, 120 );
AddColumn( L, "Low", 1.6, IIf( DLcond, colorLightGrey, colorDefault), IIf( DLcond, colorDarkRed, colorDefault) );
AddColumn( C, "Close", 1.6 );
/*AddColumn(V,"Volume",1.0);
AddColumn(OI,"Open Interest",1.0); */

FxHcQNv.png
 

Attachments

  • FxHcQNv.png
    FxHcQNv.png
    16.7 KB · Views: 1
Your broker probably has future looking bars. Then go to AB support. I'm not from AB.

As for code
Code:
dt = DateTime();

DH = TimeFrameGetPrice( "H", inDaily, 0 );
DL = TimeFrameGetPrice( "L", inDaily, 0 );

DHcond = H == DH;
DLcond = L == DL; 

Filter = DHcond OR DLcond;

SetOption( "Nodefaultcolumns", True );
AddTextColumn( Name(), "Symbol", 1 );
AddColumn( O, "Open", 1.6 );
AddColumn( IIf( DHcond, ValueWhen( DHcond, dt ), Null ), "HHV DT", formatDateTime, colorLightGrey, colorDarkGreen, 120 );
AddColumn( H, "High", 1.6, IIf( DHcond, colorLightGrey, colorDefault), IIf( DHcond, colorDarkGreen, colorDefault) );
AddColumn( IIf( DLcond, ValueWhen( DLcond, dt ), Null ), "LLV DT", formatDateTime, colorLightGrey, colorDarkRed, 120 );
AddColumn( L, "Low", 1.6, IIf( DLcond, colorLightGrey, colorDefault), IIf( DLcond, colorDarkRed, colorDefault) );
AddColumn( C, "Close", 1.6 );
/*AddColumn(V,"Volume",1.0);
AddColumn(OI,"Open Interest",1.0); */

FxHcQNv.png

Trash, thank you very much
 

Attachments

  • FxHcQNv.png
    FxHcQNv.png
    16.7 KB · Views: 0

How am I supposed to go about it?

I've tried using loops, but that didn't seem to work for me.

Code:
for( i = 0; i < BarCount; i++ ) 
{ 
     if( priceatbuy == 0 && Buy[ i ] ) 
     priceatbuy = BuyPrice[ i ]; 

     if( priceatbuy > 0 && SellPrice[ i ] > 1.1 * priceatbuy ) 
     { 
       Sell[ i ] = 1; 
       SellPrice[ i ] = 1.1 * priceatbuy; 
       priceatbuy = 0; 
     } 
     else 
       Sell[ i ] = 0; 
}

The priceatbuy or BuyPrice doesn't seem to match up to the price of the actual buying price when backtested.
 
How am I supposed to go about it?

I've tried using loops, but that didn't seem to work for me.

Code:
for( i = 0; i < BarCount; i++ ) 
{ 
     if( priceatbuy == 0 && Buy[ i ] ) 
     priceatbuy = BuyPrice[ i ]; 

     if( priceatbuy > 0 && SellPrice[ i ] > 1.1 * priceatbuy ) 
     { 
       Sell[ i ] = 1; 
       SellPrice[ i ] = 1.1 * priceatbuy; 
       priceatbuy = 0; 
     } 
     else 
       Sell[ i ] = 0; 
}

The priceatbuy or BuyPrice doesn't seem to match up to the price of the actual buying price when backtested.

If something does not match then your code is wrong.
 
Has anyone managed to successfully import minutely FX data into amibroker and get it to correctly compress it into daily bars?
I am having alot of problems with this, and it seems to be a common issue that was discussed on the yahoo message boards (last thread was in 2010). It seems to be related to amibroker's inability to correctly handle DST or inability to correctly define weekends.
I have tried to follow this guide but the compressed data is still incorrect.

If anyone knows of an alternative trading program then I would like to hear it.

Cheers
 
Has anyone managed to successfully import minutely FX data into amibroker and get it to correctly compress it into daily bars?
I am having alot of problems with this, and it seems to be a common issue that was discussed on the yahoo message boards (last thread was in 2010). It seems to be related to amibroker's inability to correctly handle DST or inability to correctly define weekends.
I have tried to follow this guide but the compressed data is still incorrect.

If anyone knows of an alternative trading program then I would like to hear it.

Cheers


There is no issue. You just have not much clue obviously just like the whole time where you were seeing some issue.

But there is one issue I don't understand myself. You are new to the software but are using a very old version that is at minimum 5 to 6 years old! Makes no sense to me. So since you are new to it it's an old version that you haven't got from the official website (old versions not being available there) but possibly got it from some warez website. As for the latter one: besides being old it may contain altered files not to mention malware code.

As for your "issue". Why don't you go to AB support (after installing most recent technology) who have more clue rather than some other Internet noobs having no clue just like youself? Here is some advice by AB before going to their support. http://www.amibroker.com/kb/2014/10/09/efficient-support/
 
Hi All,

I recently upgraded AB and boy am I happy. Finally, a decent editor!! I'm also thrilled with the new static "ranking" functions ---- pretty neat what all can be accomplished. Even on the older laptop, the 64-bit edition simply kicks butt. For the little money involved, I question why I always take so long to purchase the upgrades (standard disclaimer applies....no financial interest on my part).

Quick question: any tricks on how to distinguish between even and odd numbers ---such as in an idx loop?

Later,
RutheezKey
 
Quick question: any tricks on how to distinguish between even and odd numbers ---such as in an idx loop?

Later,
RutheezKey

Code:
i = 10;

Even = (int(i/2) - i/2) == 0;
Odd = NOT Even;
_TRACE( "!CLEAR!" );
_TRACE( StrFormat( "%g is even index (true/false): %g", i, even ) );
_TRACE( StrFormat( "%g is odd index (true/false): %g", i, odd ) );

Code:
i = 10;

Even = (int(i/2)*2/i) == 1;
Odd = NOT Even;
_TRACE( "!CLEAR!" );
_TRACE( StrFormat( "%g is even index (true/false): %g", i, even ) );
_TRACE( StrFormat( "%g is odd index (true/false): %g", i, odd ) );
 
Hi All,

I recently upgraded AB and boy am I happy. Finally, a decent editor!! I'm also thrilled with the new static "ranking" functions ---- pretty neat what all can be accomplished. Even on the older laptop, the 64-bit edition simply kicks butt. For the little money involved, I question why I always take so long to purchase the upgrades (standard disclaimer applies....no financial interest on my part).

Quick question: any tricks on how to distinguish between even and odd numbers ---such as in an idx loop?

Later,
RutheezKey
Hi RutheezKey --

The symbol "%" invokes the AmiBroker "modulo" function. Modulo returns the remainder of an integer division. All even numbers are "zero modulo 2".

If you want to know whether the current value of ijk is odd or even, use the modulo function.

In an assignment statement, it looks like this:

IsEven = Iif(ijk%2==0, True, False);

Or as the test in an If-then-else:

If (ijk%2==0)
// even part
else
// odd part

If you are comfortable with the definitions of False as 0, True as anything other than 0, the statements can be a little shorter and more compact.

But don't sacrifice clarity for efficiency.

--------------------------------------
Run this code as an Explore:

ijk = Month();
IsEven = ijk%2 == 0;
// Only look at data when the month is an even number -- Feb, April, ...
Filter = IsEven;
AddColumn(C,"C",10.0);

------------------------------------
You will get a list of the integer parts of the closing price for days in even months.

Best,
Howard
 
Hi All,

I recently upgraded AB and boy am I happy. Finally, a decent editor!! I'm also thrilled with the new static "ranking" functions ---- pretty neat what all can be accomplished. Even on the older laptop, the 64-bit edition simply kicks butt. For the little money involved, I question why I always take so long to purchase the upgrades (standard disclaimer applies....no financial interest on my part).

Quick question: any tricks on how to distinguish between even and odd numbers ---such as in an idx loop?

Later,
RutheezKey

For an index of a loop:

for (i=0; i<BarCount; i++)
{
if (i%2==0)
// even part
else
// odd part
}

Best,
Howard
 
Top