This is a mobile optimized page that loads fast, if you want to load the real page, click this text.

Amibroker FAQ

Yes, I have made functions for all kinds of US and UK holidays (incl. Good Friday). But they are part of a plugin.
 

I found this in a search this morning, not sure if it's applicable to your code but may be worth a look.


http://osdir.com/ml/finance.amibroker.ts/2007-04/msg00016.html
 
LastDayofWeek = IIf(DayOfWeek() > Ref(DayOfWeek(),1),1,0);

The code looks ahead to the following day and returns true on the last day. If it's a Friday it evaluates as 5 (Friday) greater than 1 (Monday). If it's a Thursday (ie. no trade on Friday) then it evaluates as 4 (Thursday) greater than 1 (Monday) as there's no 5 (Friday). Hope that makes sense
 
Apologies for my disjointed posts, trying to do too much at once atm!

To sell on the last day of the week would be:

Sell = LastDayofWeek;

This would either be the Friday, or if there's no trade on the Friday, would be the Thursday.
 

It is not a proper way looking into the future. You can not look into the future of price data in realtime.

A proper code is not dependent on looking into the future of DB data. And it can be done so.
 
It is not a proper way looking into the future. You can not look into the future of price data in realtime.

A proper code is not dependent on looking into the future of DB data. And it can be done so.

Correct.

But we aren't attempting to look ahead into future price data. Only available trading days. Exactly the same as if we know Christmas is on a Friday etc.

I'll give this code a crack and see if it works.
 
But we aren't attempting to look ahead into future price data. Only available trading days. Exactly the same as if we know Christmas is on a Friday etc.

Yes you are since Day() is dependent on price data.
On the other hand with proper formula being independent from price data you know the holiday date whenever you want to.

Look I already know the date of Goodfriday of 2016 and following years without having price data yet. Still exploration outputs them. Why? Because formulas are not dependent on arrays.



The functions output datenum values so you can know the day of end of week of Good Friday like this for example:

Code:
EndOfWeekGF = datenum() == GoodFriday() -1;

You don't look into future price data. So such functions work for backtest and realtime.
 

Attachments

  • OBvgB2c.png
    11.4 KB · Views: 0
I haven't tested it so would be interesting to know if it works. If not then there's always the option of collating the Friday holiday dates and/or using a plugin like Trash has illustrated in the post above.

It definitely does work.
 
If not then there's always the option of collating the Friday holiday dates and/or using a plugin like Trash has illustrated in the post above.

There is not a plug-in required to create such holiday functions. It can be coded using AFL also. Multiple roads lead to Rome.
 
With conditionals, if there is a sum, or calculation, is it easier to do this outside of the if function, and then refer to it within the conditional?

For example a = x + y
b = y + z

If( a > b) then

Rather than If (x+y > y+z) then etc.

I ask this because I'm getting problems with this. Especially as I'm trying to optimize some conditions. Will the conditional then accept an optimized value? Or would I have to do that manually?

Cheers.
Chops.
 
Hi Chops --

The compiler for the afl language is pretty good about optimizing expressions. For the example you posted, I doubt that there will be any detectable difference in execution time.

My recommendation is to write code in such a way that code maintenance some time in the future will be as easy as possible for the programmer. Given that, write the expressions, assignments, and functions so that they make the most sense to the person reading the code.

Best,
Howard
 
Thanks Howard.

This is a general question to all. Is there an easy way to analyse percentage movements to optimize buying breakouts and gathering other statistics etc?

For example:

//breakout criteria

pchng = ((O - Ref(C, -1)) / Ref(C,-1)) *100;
PositiveChg = pchng >=0;
PositiveChg = Optimize("PositiveChg",0,0,5,0.2);
Buy = PositiveChg;

I can't seem to get it to optimize PositiveChg before or in the Buy line. Will I have to use another function given I want it to return a numerical value and not just a true or false?

Cheers,
Chops.
 
Thanks Howard.


I can't seem to get it to optimize PositiveChg before or in the Buy line. Will I have to use another function given I want it to return a numerical value and not just a true or false?

Cheers,
Chops.

Buy = .... cannot be a number. The buyline requires a condition.

Try instead:

Buy = ((O - Ref(C, -1)) / Ref(C,-1)) *100 > Optimize("PositiveChg",0,0,5,0.2);

...and lose all the other lines. They are unecessary.
 
I can't seem to get it to optimize PositiveChg before or in the Buy line. Will I have to use another function given I want it to return a numerical value and not just a true or false?

G'day Chops,

This line:
PositiveChg = pchng >=0;
returns either true or false so your currently optimising the wrong variable. I assume you're really wanting to optimise the "pchng" value?
 
Buy = .... cannot be a number. The buyline requires a condition.

Chops code returns true or false for the buy line, not a number.

Try instead:

Buy = ((O - Ref(C, -1)) / Ref(C,-1)) *100 > Optimize("PositiveChg",0,0,5,0.2);

...and lose all the other lines. They are unecessary.

Optimize should be assigned to a variable to make the code more readable.
 
Sweet!

Thanks.

How come we can use ">" in the buy line? I would have thought that would have brought up an error like that.

"Returns either true or false so your currently optimising the wrong variable. I assume you're really wanting to optimise the "pchng" value."

That's right. But I couldn't seem to get that. Slowly getting there again...

Cheers.
 
How come we can use ">" in the buy line? I would have thought that would have brought up an error like that.

">" is a comparison operator and always returns true or false:

https://www.amibroker.com/guide/a_language.html

(scroll down to "operators")

It's neater to assign the conditions and optimisation code to variables then call the variables in the buy line (makes it easier to read and adjust).

"Returns either true or false so your currently optimising the wrong variable. I assume you're really wanting to optimise the "pchng" value."

That's right. But I couldn't seem to get that. Slowly getting there again...



I've been using AB for over 10 years and I'm still slowly getting there too...
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more...