Hello guys,
I'm wondering if it's possible to close a specific order ID, because Liquidate function closes all the open orders, but i would like to close some order IDs based on a specific condition that might occur in a different date.
Also i'm wondering what is the right way to use Stop loss and Take profit, because when i get the results i see that the close price is always incorrect (based on the SL price or TP price i entered).
Thank you so much for your time.
Michael Manus
documentation might help......
// Creating an Order: OrderTicket limitOrderTicket = LimitOrder("SPY", 100, 205); // Updating an Order: limitOrderTicket.Update(new UpdateOrderFields{LimitPrice = 207.50}; // Cancel an Order: limitOrderTicket.Cancel(); // Cancel all open orders from SPY List cancelledOrders = Transactions.CancelOpenOrders("SPY") // Cancel order #10 OrderTicket cancelledOrder = Transactions.CancelOrder(10); // Get open orders List openOrders = Transactions.GetOpenOrders(); List openOrders = Transactions .GetOrders(x => x.Status.IsOpen()).ToList(); // Get open orders from SPY List openOrders = Transactions.GetOpenOrders("SPY"); List openOrders = Transactions .GetOrders(x => x.Status.IsOpen() && x.Symbol == "SPY").ToList(); // Get open order #10 Order openOrder = Transactions.GetOrderById(10); // Get order ticket #10 OrderTicket orderTicket = Transactions.GetOrderTicket(10); // Get open orders tickets from SPY IEnumerable openOrderTickets = Transactions .GetOrderTickets(x => x.Status.IsOpen() && x.Symbol == "SPY");
Hanaa
@Michael, thank you so much for your reply.
The point is that i don't want to cancel the order, i just wanna "close" an order based on it's ID.
Also i tried LimitOrder for take profit and StopMarketOrder for stop loss, but always it's closing the trades incorrectly for some reason, because if i calculate the pips based on the entry price and exit price i see that they are incorrect.
Michael Manus
hmm yes some people already mentioned that.....waiting till it goes up and sell or pull the line and rescue.......you have always to work with the Time (datetime class) variable so will get the exact time when this order gets executed.....
from docu:
// Override the base class event handler for order events public override void OnOrderEvent(OrderEvent orderEvent) { var order = Transactions.GetOrderById(orderEvent.OrderId); Console.WriteLine("{0}: {1}: {2}", Time, order.Type, orderEvent); }
close? vs cancel? you mean close the position and close all orders releated to this position?
Michael Manus
/// <summary> /// Removes the security with the specified symbol. This will cancel all /// open orders and then liquidate any existing holdings /// </summary> /// <param name="symbol">The symbol of the security to be removed</param> bool RemoveSecurity(Symbol symbol); /// <summary> /// Liquidate your portfolio holdings: /// </summary> /// <param name="symbolToLiquidate">Specific asset to liquidate, defaults to all.</param> /// <param name="tag">Custom tag to know who is calling this.</param> /// <returns>list of order ids</returns> List<int> Liquidate(Symbol symbolToLiquidate = null, string tag = "Liquidated");
Stanley O
Hello. Again, how can one close just one order based on its order id or ticket. For example, several market orders have been opened for EURUSD pair and I want to close ONLY the first order
Shile Wen
Hi Stanley,
In OnOrderEvent, we can compare the Order ID of our first order with the Order ID of the OrderEvent, and close the position if they match. I've shown this in the attached backtest.
Best,
Shile Wen
Hanaa
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!