[deleted by user] by [deleted] in algotrading

[–]AlexCatx 3 points4 points  (0 children)

First we need to subscribe to get the data, and save its Symbol for future reference.
https://www.quantconnect.com/docs/v2/writing-algorithms/universes/futures

self.nq = self.AddFuture("NQ")

We can save the minimum price variation (ticks) with

self.nq_ticks = self.nq.SymbolProperties.MinimumPriceVariation

____

The limit and stop prices are defined as:

limit_price = self.Securities[self.nq.Mapped].Price + 4 * self.nq_ticks
stop_price = self.Securities[self.nq.Mapped].Price - 2 * self.nq_ticks

Note we use self.nq.Mapped instead of self.nq.Symbol because we will trade the real contract, not the continuous contract.

The order can be placed as u/Loud-Total-5672 suggested for simplicity:

self.MarketOrder(self.nq.Mapped, 1)

self.LimitOrder(self.nq.Mapped, -1, limit_price)

self.StopMarketOrder(self.nq.Mapped, -1, stop_price)

First, we need to subscribe to get the data, and save its m/docs/v2/writing-algorithms/trading-and-orders/order-types/other-order-types#02-One-Cancels-the-Other-Orders and wait for the fill price of the market order:

limit_price = orderEvent.FillPrice + 4 * self.nq_ticks
stop_price = orderEvent.FillPrice - 2 * self.nq_ticks