Back

Is it possible to close a specific order id ?

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.

Update Backtest








documentation might help......

https://www.quantconnect.com/docs/algorithm-reference/trading-and-orders#Trading-and-Orders-Order-Events// 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");
0

@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.

0

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?

0

/// <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");
0

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