Australian (ASX) Stock Market Forum

Dump it Here

I 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)
 
I 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)
I did that a while back, let me check
 
What's a good way to recreate the ASX price increments?

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 ) );
}
 
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 ) );
}
Very similar to what i sent to GB.so must be working.thanks
 
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?
 
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?

See the AmiBroker documentation on calling functions:
 
See the AmiBroker documentation on calling functions:
Thanks, I've read that but couldn't make sense of it.


Price = MA(C,10);

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 ) );
}

Filter = V*C>500000;
Addcolumn(RoundTickBuy(Price),"rounded price");
 
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);
 
With all due respect, you really need to learn basic AmiBroker Formula Language (or any language, for that matter) programming.

The example code provided has 2 levels of nesting, which are hard(er) to understand - but if you don't understand nesting or how statements like If or IIf work at all then you can't understand any of the code.

Consider an if-else version instead to make your life easier, from an understanding perspective. See both of these links:


 
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);
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.
I am not sure 109% what you try to do reading at code snippet.
I assume it just dispay the MA value of all share agreeing with your filter..but then do you need to set your buy conditions?or display all pages of ma price..
Either i misunderstand or as Richard mentioned,you need to pkay with some example code to better understand AB coding.do not take that negatively,and feel free to DM me,sadly got huge family meeting this week end so no quick reply expected.
 
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.
 
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.
Dave, you've done it. Thank you, that's all I needed.

Thanks to everyone else too. But consider - some people will never be able to hit a golf ball, no matter how much instruction or training they undertake. It's simply not in them. Well, when it comes to coding, that's me. It's not in me, and I have no desire whatsoever to learn it (beyond the basics, I mean). When I go on the AB forum, that's usually what I'm met with - "Learn to code!". I already have someone I pay for major projects. For little things like figuring out how to round some numbers, really all I'm after is the answer. I'd already tried to do it myself - in fact wasted many hours! Why do that when an expert can whip up the answer in under a minute? I share a lot of high quality information for free (on a different forum, unrelated to trading), and it's nice when someone reciprocates. Cheers.
 
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 ) );
}
No worries.

I actually really like @Sir Burr answer too and i think it would suit better for a lot of cases. Now that you have something working you should try implementing that one.
 
Selling as a trader
There are always three sides to an argument & trading is no different. The recent falls in the market have currently shaped the opinion of everyone. Tough market conditions are based on emotions & how you react shapes the trader you "have become" or "will become".

Skate.
 
A trading plan trumps a trading strategy
Should I sell or hold on a bit longer? well, that question depends on your risk tolerance but for me, that question is answered by my trading plan. One of my trading rules is "when in doubt, pull out". That means when trading doesn't sit well, or you are uncertain about how the markets will play out it pays to be cautious.

Why?

Because of my experience, there are some who are trading with capital they can't afford to lose.

Skate.
 
Pulling out gives you time to think
I'm not talking about those who can’t stomach losing & go on to make a habit of selling quickly (overriding their strategy) at the first sign of a market change. Those traders have a low-risk tolerance & normally risk-averse. I'm talking about those traders who have serious doubts about the current market trading conditions. As capital preservation is the name of the game, I'm suggesting, when in doubt "pull out", & give yourself time to think.

On the flip side
If you don't hit the sell button when you receive a sell signal you will quickly turn a trade into a long-term investment. In the next post, I'll talk about "investments" rather than "trading".

Skate.
 
Reposted without permission
The capture below is from Mark Minervini's Twitter feed displaying how it can go horribly wrong buying the dip. The problem with this strategy is that you never know where the bottom is.

How much lower can it go?
Who knows. There are some investors who think there are companies that are impervious to a major decline thus they perceive they are buying big names at "bargain" prices.

Mark.jpg

Skate.
 
Top