- Joined
- 8 June 2008
- Posts
- 13,131
- Reactions
- 19,321
Finally, this is not the ultimate solution: we pass an order for $2k for example but if the price is lower on open than at the close plus 3%, we will get less sharesAnd you should then ensure your backtests sell/buy will be executed..
let's add future looking code here so that we will get a match between backtest and our execution:
//check that in the next session day,
//the low will be lower or equal than our buy limit
//this is forward looking and used in backtests to ensure our real world order would be able to be executed
Buy =Buy AND (Ref(L, 1)<GetASXPrice(C*1.03));
and similar for the sell against the H of the day:
Sell = Sell AND (Ref(H, 1)>GetASXPrice(C*0.97));
Hope it helps
First line:
without open margin check: we buy sell at open regardless of price
second line we only sell if within limit..well worse but not that bad, a sell at all cost is NOT that critical
third line: we ONLY buy within the 3% range: serious decrease
The initial function code i givetgive you what price you can use to get that 3% extra as asx has rules for incrementsIn the dump it here thread I posted the logic I'd use to ensure amibroker bought at the same price we do.
Entry price for the purpose of determining the Qty of shares to buy = Close rounded up to 2 decimal places + 3%.
Qty shares to buy = your desired position size / Entry price as calculated above.
I think that part is pretty straightforward unless I've overlooked something. Not sure about the sell since you need to chase it if not filled at open. I appreciate your code, but don't understand it just yet as it uses functions I'm not familiar with. I'll have to look into it more.
Depending on what your system looks for, possibly the best trades are the ones that gap up and never look back? That seems to be what your results are suggesting.
The problem is that we simply can't buy at open price if it gaps our limit order (except for the cases where they come back). So the question becomes how far can you afford to chase price before you become less profitable than line 3?
For info noticed a bug in my code to determine nearest asx price, will fix and post tonight.i misunderstood the AB round() functionThe initial function code i givetgive you what price you can use to get that 3% extra as asx has rules for increments
0.1c under 10c
0.5c until 2$
1c after
So this part is required and yes, we could compute the number of shares based on $ amount, brokerage and max price allowed based on the function.result
It is doable.
For info noticed a bug in my code to determine nearest asx price, will fix and post tonight.i misunderstood the AB round() function
My problem was compounded as i was passing such a ceil as an argument, but i would like 0.0439 to be passed as 0.044, 0.0433 as 0.043@qldfrog rounding is a bitch & lacks precision, personally I use the "ceil & floor' functions in my strategies for such reasons.
http://www.amibroker.com/guide/afl/ceil.html
http://www.amibroker.com/guide/afl/floor.html
Skate.
There is always a decision made as to whether you want to round up, down but at least you are in control
I understand the cell and floor but neither take into account the fact that shares below 10 cents can have increments in 0.1 cent@qldfrog for simplicity without looping I use the array "ceil function" & the "floor function" because I'm after rounding up to the max when it comes to a buy offer & the reverse when I place a sell offer in the pre-auction.
An example of rounding
I'll use Woolworths as an example to buy one "chupa chup" lolly with cash.
Normal price $1.03 (buy this with cash & the price rounds down to $1.00)
On "SPECIAL" buy price is $0.97 (buy this with cash & the price rounds up to $1.00)
# The stupidity of rounding - the cash price for one "chupa chup" lolly costs exactly the same at its normal price or the advertised special price which is $1.00
Amibroker logic
BuyOffer = I use the "ceil function" to round prices up to the max
SellOffer = I use the "floor function" to round prices down to the lowest value
Why do I use the "ceil function" to round prices up
Because I want the Buy Offer to add the "full +3% premium" to the last closing price rounded up to 2 decimal places (rounding to 3 decimal places serves no purpose) = ceil function rounds 0.011 up to 0.02
(the standard mathematical rounding function of 0.011 rounds to 0.01)
Why do I use the "floor function" to round prices down
Because I want the Sell Offer to add the "full -3% premium" to the last closing price rounded down to 2 decimal places (rounding to 3 decimal places serves no purpose) = floor function rounds 0.029 down to 0.02 (the standard mathematical rounding functions of 0.029 rounds to 0.03)
Skate.
I understand the cell and floor but neither take into account the fact that shares below 10 cents can have increments in 0.1 cent
more elegant than my code indeed if this works to your preferencesfunction 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?