" difference between enter long by stop limit order and exit long by stop limit order".
However, I want to do this with unmanaged approach and am getting an error:
So obviously I am not doing it correctly. I wrote a function to place a limit entry order; that is, for a price below current price (for a buy):
private void PlaceLimitOrder(string dir, double price, int qty, string name="Entry")
{
/// If we are already in a limit order, cancel or ignore
if (entryOrder != null)
{
/// If a limit order is already active...
if (entryOrder.OrderType == OrderType.Limit)
{
if ((entryOrder.OrderAction == OrderAction.SellShort && dir == "Short")
|| (entryOrder.OrderAction == OrderAction.Buy && dir == "Long"))
{
if (entryOrder.LimitPrice == price)
{
Log("Already in Pending " + dir + " Limit order @ " + price + " - Doing nothing");
lastCaller = ""; // reset so if this method is entered again before other log, reprint the function name
return;
}
else
{
Log("Already in Pending " + dir + " Limit order, but at diff price (" + entryOrder.LimitPrice +
", not requested price of " + price + ") - Cancelling old " + entryOrder.OrderAction.ToString() +
" pending order");
CancelOrder(entryOrder);
}
}
else
Log("Unexpected: entryOrder != null, but OrderAction check failed");
}
}
Log("Place limit order @ " + price + ": dir = " + dir + ", qty = " + qty + ", name = " + name);
var action = (dir == "Long") ? OrderAction.Buy : OrderAction.SellShort;
SubmitOrderUnmanaged(1, action, OrderType.Limit, qty, price, 0, "", "Entry");
pendingPlaced = true;
lastCaller = ""; // reset so if this method is entered again before other log, reprint the function name
}
This works fine. But now I want a stop order entry -- I think - for a buy, that would be for a price above current price.
So I modified the one above to this:
private void PlaceStopOrder(string dir, double price, int qty, string name="Entry")
{
/// If we are already in a limit order, cancel or ignore
if (entryOrder != null)
{
/// If a limit order is already active...
if (entryOrder.OrderType == OrderType.StopLimit)
{
if ((entryOrder.OrderAction == OrderAction.SellShort && dir == "Short")
|| (entryOrder.OrderAction == OrderAction.Buy && dir == "Long"))
{
if (entryOrder.LimitPrice == price)
{
Log("Already in Pending " + dir + " Stop order @ " + price + " - Doing nothing");
lastCaller = ""; // reset so if this method is entered again before other log, reprint the function name
return;
}
else
{
Log("Already in Pending " + dir + " Stop order, but at diff price (" + entryOrder.LimitPrice +
", not requested price of " + price + ") - Cancelling old " + entryOrder.OrderAction.ToString() +
" pending order");
CancelOrder(entryOrder);
}
}
else
Log("Unexpected: entryOrder != null, but OrderAction check failed");
}
}
Log("Place stop order @ " + price + ": dir = " + dir + ", qty = " + qty + ", name = " + name);
var action = (dir == "Long") ? OrderAction.Buy : OrderAction.SellShort;
SubmitOrderUnmanaged(1, action, OrderType.StopLimit, qty, price, 0, "", "Entry");
pendingPlaced = true;
lastCaller = ""; // reset so if this method is entered again before other log, reprint the function name
}

Comment