Back

Slippage

How can i change the default calculated Slippage for forex? currently its 0.01

//Assume slippage is 1/1000th of the price
slippage = lastBar.Price*0.001m;
Update Backtest








I think i got it working:

add "Securities[pair].Model = new MyForexTransactionModel();" in your Initialize() function and override the relevant class :

class MyForexTransactionModel : ForexTransactionModel {
///
/// Get the Slippage approximation for this order:
///

public override decimal GetSlippageApproximation(Security security, Order order)
{
//Return 0 by default
decimal slippage = 0;
//For FOREX, the slippage is the Bid/Ask Spread for Tick, and an approximation for the
switch (security.Resolution)
{
case Resolution.Minute:
case Resolution.Second:
//Get the last data packet:
//TradeBar lastBar = (TradeBar)security.GetLastData();
//Assume slippage is 1/1000th of the price
//slippage = lastBar.Price*0.001m;
slippage = 0.00005m;
break;

case Resolution.Tick:
Tick lastTick = (Tick) security.GetLastData();
switch (order.Direction)
{
case OrderDirection.Buy:
//We're buying, assume slip to Asking Price.
slippage = Math.Abs(order.Price - lastTick.AskPrice);
break;

case OrderDirection.Sell:
//We're selling, assume slip to the bid price.
slippage = Math.Abs(order.Price - lastTick.BidPrice);
break;
}
break;
}
return slippage;
}

}


I simply changed the slippage to fix .5pip
0

Good work -- that is how you do it. You can override them, and set your own models and fill prices.
0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed