Back

Problem with CalculateOrderQuantity and MarketOrder

I have:

posSize = int(self.CalculateOrderQuantity(self.symbol, 0.02))

and

newTicket = self.StopMarketOrder(self.symbol, posSize*(-1), stopPrice)

Why does CalculateOrderQuantity return an decimal type when MarketOrder wants integer as input?

Does anyone know how i can convert posSize to integer so i can get m MarketOrder working?

Update Backtest








Hi David,

Just pass posSize to StopMarketOrder as the quantity parameter. You don't need to convert posSize to int since StopMarketOrder has 3 different method signatures, to which you can pass posSize as decimal, double or int.

0

Ok...?

When i change posSize to -10 000 everything works fine. But when i pass posSize i get status "Invalid" on the orders at backtesting.

newTicket = self.StopMarketOrder(self.symbol, -10000, stopPrice)
0

Most probably because your holding percentage 0.02 is too small.  Just to test first, set it to 1 in CalculateOrderQuantity. This should work.  Then, you need to find out the minimum allowed holding percentage.  This would depend on security, broker, leverage and your holding.

0

Can you look at my code? Something is screwing it up. Ordersizes are very big. StopMarketOrders are invalid.

https://www.quantconnect.com/terminal/processCache?request=embedded_backtest_f0fba2297a2116f3109c4a97dda74a8b.html
0

This is weird :/. I've used CalculateOrderQuantity successfully recently but have not tried it on FXCM

0

To fix this, don't set the brokerage model to FxcmBrokerage.   

def Initialize(self):

self.symbol = "EURUSD"

self.SetStartDate(2013,01,01) #Set Start Date
self.SetEndDate(2016,12,31) #Set End Date

#self.SetBrokerageModel(BrokerageName.FxcmBrokerage)

self.SetCash(100000) #Set Strategy Cash

self.AddSecurity(SecurityType.Forex, self.symbol, Resolution.Hour)

Actually, FXCM should be the default broker if you don't specify any.   This looks like a bug but I am not quite sure about this strange scenario..  Hence, I'd like to see clarification by Jared or QS staff.  Thanks. 

0

 - CalculateOrderQuantity returns a decimal to support fractional quantities. (crypto)

 - You were ignoring hundreds of error messages being shown in the console. By shortening the backtest we can focus on fixing the errors:

stopPrice = round(stopPrice, 5)
limitPrice = round(limitPrice, 5)

 - Finally this shows the real issue with the algorithm:

 

Backtest Handled Error: OrderID: 1 Warning - Code: NotSupported - This model does not support StopLimit order type.

I.e. FXCM brokerage does not have a StopLimit order type.

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.


Thanks for the help Jared and CloudTrader.

What ordertypes would you recommend? Do you have any examples? If i follow your link to FXCM i can see that they have a ordertype named: EntryOrder which would suit me. Cant find any examples in the documentation and also tried to google...

0

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