- Joined
- 30 June 2007
- Posts
- 7,200
- Reactions
- 1,226
I did that a while back, let me checkI have an AB question, since most of you guys use AB.
What's a good way to recreate the ASX price increments? I've been playing around with PREC() and ROUND() functions but can't quite get it.
Thanks.
- <=.1 (3 decimal places)
- >.1 and <=2, .005 (3 decimal places, but rounded to .005)
- >2 (2 decimal places)
What's a good way to recreate the ASX price increments?
Very similar to what i sent to GB.so must be working.thanksfunction RoundTickBuy( Price )
{
return
IIf( Price < 0.1, ceil( Price * 1000 ) / 1000,
IIf( Price < 2, ceil( Price * 200 ) / 200,
ceil( Price * 100 ) / 100 ) );
}
function RoundTickSell( Price )
{
return
IIf( Price < 0.1, floor( Price * 1000 ) / 1000,
IIf( Price < 2, floor( Price * 200 ) / 200,
floor( Price * 100 ) / 100 ) );
}
Thank you guys, much appreciated. Yes, SirBurr's and Qldfrog's codes are very similar.
I was trying to figure out the follwing with Frog on DM.
Say my Buyprice = MA(C,10), and this is the number I want rounded. How do I call the custom function please?
Thanks, I've read that but couldn't make sense of it.See the AmiBroker documentation on calling functions:
GB, when defining the function the parameter part does not have to have the same name as the variable (s) you use it with.it is confusing.Thanks Richard, but I think the formula must be for something else entirely.
This is where I'm at. It just needs a tweak to get the second level of increments (P>.1 and P<2) rounded to 0.005.
P = MA(C,10);
function RoundTick(P)
{
return
IIf( P < 0.1, prec(P,3),
IIf( P < 2, prec(P,3),
prec(P,2)) );
}
Filter = V*C>200000;
Addcolumn(RoundTick(P),"rounded price",1.3);
function RoundTick(P)
{
return
IIf( P < 0.1, prec(P,3),
IIf( P < 2, round(P/.005)*.005,
prec(P,2)) );
}
Filter = 1 && Status("LastBarInRange");
AddColumn(ma(C,30),"Close",1.6);
AddColumn(RoundTick(ma(C,30)),"RoundTick",1.6);
// Show the rounding errors
AddColumn(C,"Close",1.6);
AddColumn(RoundTick(C),"RoundTick",1.6);
Dave, you've done it. Thank you, that's all I needed.Basically you can just change your P<2 line so you end up with this.
Code:function RoundTick(P) { return IIf( P < 0.1, prec(P,3), IIf( P < 2, round(P/.005)*.005, prec(P,2)) ); } Filter = 1 && Status("LastBarInRange"); AddColumn(ma(C,30),"Close",1.6); AddColumn(RoundTick(ma(C,30)),"RoundTick",1.6); // Show the rounding errors AddColumn(C,"Close",1.6); AddColumn(RoundTick(C),"RoundTick",1.6);
Note .. The prec function introduces rounding errors which you can see in the exploration. Nothing major, so if it works all good otherwise Amibroker forum is your friend https://forum.amibroker.com/t/rounding-of-ma-values-to-tick-size/11773/2.
No worries.function RoundTickBuy( Price )
{
return
IIf( Price < 0.1, ceil( Price * 1000 ) / 1000,
IIf( Price < 2, ceil( Price * 200 ) / 200,
ceil( Price * 100 ) / 100 ) );
}
function RoundTickSell( Price )
{
return
IIf( Price < 0.1, floor( Price * 1000 ) / 1000,
IIf( Price < 2, floor( Price * 200 ) / 200,
floor( Price * 100 ) / 100 ) );
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?