Floating Point Rounding and ApplyStop

Topics about the AmiBroker platform
trash
Posts: 30
Joined: Fri Mar 30, 2012 9:15 pm
Contact:

Floating Point Rounding and ApplyStop

Postby trash » Tue Dec 11, 2012 4:57 pm

If using Forex or Futures where Ticksize is used a "problem" can occur using AB's Applystop function.
Reason is
Hello,

Please remember that not all decimal fractions can be expressed with 100%
accuracy in any computer - read:
http://www.amibroker.com/kb/2010/07/20/ ... rithmetic/

Best regards

Marcin Gorzynski
Amibroker.com Technical Support


Hello,

Remember that the internal code is written in C++, so floating point
rounding
may occur in different places of the internal code (so that's why
you see differences as compared to AFL-code).

...... I just think it's an impact of floating point arithmetic that you see in the results,
see the link I sent earlier for more understanding.

Best regards

Marcin Gorzynski
Amibroker.com Technical Support


So let's take a random-entry system for Forex e.g. using Ticksize 0.0001 for EURUSD
Here is the code http://pastie.org/private/yxk3npxd7ibpkewmbqm5w
And here is a picture of the AFL editor
Image

And here is a results list using that code
Image

As you can see in the P/L column the exits are not always precise at -10 or +10 pips. That's caused by C++ floating point rounding and tickers using Ticksizes like 0.0001.

A solution to this is using it like this http://pastie.org/private/kt0c2gwfcubx1amhnommg
Pic of the code
Image

The important part can also be written like this

Code: Select all

div = 10000;
TickSize = TickSize / div;
stop = 10 * ( TickSize * div );// 10 pips

if you have entered the ticksize for that ticker in the Symbol Information window of Amibroker.

And here is a new results list using that code (remember the system is using random entries, that's why you see an overall loss there compared to previous result list!)
Image

So as you can see now the P/L column is showing precise exits at set TP and SL of 10 pips.

User avatar
progster
Posts: 948
Joined: Thu Jul 26, 2007 7:20 pm
Contact:

Re: Floating Point Rounding and ApplyStop

Postby progster » Tue Jan 22, 2013 2:19 pm

Nice technique. Thanks for posting.


Return to “AmiBroker Discussion”

Who is online

Users browsing this forum: No registered users and 2 guests