Back

Limit Order not filled

Hello Community,

I'm new to QuantConnect and still figuring out the Doc etc.

I hope someone can help me with this:
There should be a Market Order and simultaniously a Take Profit 40 pips above and a Stop Loss 100 pips below. It seems to work, but the orders never get filled. I do not see any profitable trades in the backtest pane and the log of the Filled and Canceled order is also never triggered. 

# Trade execution
if (momentum >= 1.5) and (closePct >= 0.9):

marketOrder = self.MarketOrder(self.forex.Symbol, 1000)
self.Log('Market Order filled at: {}, Momentum: {}, ClosePct:, {}'.format(marketOrder.AverageFillPrice, momentum, closePct))

self.LimitOrder(self.forex.Symbol, -1000, t0bidClose+0.004)
self.StopMarketOrder(self.forex.Symbol, -1000, t0bidClose-0.01)
self.Log('TP: {}, SL: {}'.format((t0bidClose+0.004), (t0bidClose-0.01)))

def OnOrderEvent(self, orderEvent):
order = self.Transactions.GetOrderById(orderEvent.OrderId)

if order.Status == OrderStatus.Filled:
self.Log(str(orderEvent))

if order.Type == OrderType.Limit or order.Type == OrderTpye.StopMarket:
self.Transactions.CancelOpenOrders(order.Symbol)

if order.Status == OrderStatus.Canceled:
self.Log(str(orderEvent))

Thank you and I'm happy for any help.

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.


Hey,

I think it'll be better if you manage your risks with RiskManager Module,

Knowing that, check : 

https://github.com/QuantConnect/Lean/blob/master/Algorithm.Framework/Execution

you can use TrailingStopRiskManagementModel and add custom rules for taking profits,

I think that for precise results you should use minute time frames ,longer time frames might be misleading

1

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