How to make spread by point ( spread = buyprice - 0.5)

hi all guy!!
i just learn about amibroker half year!!i am doing backettest in xauusd market!!
how can i make the spread in amibroker
in mt4 bid - ask = spread
but in amibroker CommissionMode have 3 style
0 - use portfolio manager commission table
1 - percent of trade
2 - $ per trade
3 - $ per share/contract
all select by money and %
how can i make the spread by point ( buyprice - 0.5) !!!

thx all guy have nice day!!

The link below might help you

1 Like

I don’t understand the question. Are you looking for a way to account for slippage in your backtest?

If so, then create an amount you think will be correct and add or subtract it in your code something like this

BuyPrice = BuyPrice + Slippage;
SellPrice = SellPrice - Slippage;
CoverPrice = CoverPrice + Slippage;
ShortPrice = ShortPrice - Slippage;

Or something similar depending on your trading system, you may want to define buyprice as open + slippage and sellprice as close - slippage, etc. etc.

You mention that you are fairly new to AmiBroker so you may not have this excellent tutorial on currency trading prepared and generously shared by user fxshrat,

1 Like

@portfoliobuilder, that is not correct because it will not work that way.

Also MT4 shows Bid prices in its historical feed. So if you want to use some artificial spread value you would need to add it to buyprice and coverprice only. Bid data is used for Sell and Short.

In addition since you may exceed bar’s price range by adding some artificial value you have to set price bound checking to false.

SetOption("PriceBoundChecking", False);

spread = 0.5;

BuyPrice = ...;
SellPrice = ...;
ShortPrice = ...;
CovePrice = ...;

 // add spread to MT4 bid price if buying or covering
BuyPrice += spread;
CoverPrice += spread;

On the other hand if you have separate historical bid and ask price data then you may import bid data to “XXXXXX_bid” symbol and ask data to “XXXXXX_ask” symbol and in your formula you may use Foreign() function. For example:

SetTradeDelays( 1, 1, 1, 1 );

Ask_Open = Foreign( "XXXXXX_ask", "O" );

BuyPrice = Ask_Open;
SellPrice = Open;
ShortPrice = Open;
CovePrice = Ask_Open;

Or if you have historical spread data then you could store it to AUX field of a symbol via hybrid import method
And adding Aux array to Buyprice and Coverprice

SetOption("PriceBoundChecking", False);

BuyPrice = ...;
SellPrice = ...;
ShortPrice = ...;
CovePrice = ...;

 // add historical spread stored in Aux1 field to MT4 bid price if buying or covering
BuyPrice += Aux1;
CoverPrice += Aux1;


BTW, I have updated the PDF document of the link you’ve posted… I have removed all OLE codes since they may be poison in wrong hands.


Thanks for the input fxshrat. I’m not sure if I correctly understood the OP but you’ve given him some great info!

thx you all brother !!
i did it with the correct backtest datebase!!
in the other hand
i use 2 % of my capital
how can i increase 0.2 percent in monthly when the winner Avg.profit is the double size of the loser avg.profit,the Maximum of my positionsize is 5%,
i don’t have anyidea about this kind of afl!!
can the alf make this??