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.
Ofir Shmulevich
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/Executionyou 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
Vincent ole
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!