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?
CloudTrader
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.
Davidii111
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)
CloudTrader
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.
Davidii111
Can you look at my code? Something is screwing it up. Ordersizes are very big. StopMarketOrders are invalid.
Petter Hansson
This is weird :/. I've used CalculateOrderQuantity successfully recently but have not tried it on FXCM
CloudTrader
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.
Jared Broad
- 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.
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.
Davidii111
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...
Davidii111
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.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!