String defining and finding order by label
String defining and finding order by label
21 Nov 2016, 22:43
Why can't I define string
"string _Long = Symbol.Code.ToString() + "Long";"
in the section where all the parameters are defined and can only do it in OnBar() or PositionsOnClosed(PositionClosedEventArgs args)?
Going forward with the question: now I define labels in OnBar() for orders and then I define labels in PositionsOnClosed(PositionClosedEventArgs args) to find same orders and cancel them. It seems like it is unnecessary doubling of strings. How can I find orders in PositionsOnClosed(PositionClosedEventArgs args) without defining labels once again?
protected override void OnBar()
{.....
string buy_Order = Symbol.Code.ToString() + "Buy Order";
PlaceLimitOrder(TradeType.Buy, Symbol, Volume*2, (EntryPrice - DistanceOnOrders * Symbol.PipSize) , buy_Order, StopLossInPips_buy1, TakeProfitInPips1);
}
private void PositionsOnClosed(PositionClosedEventArgs args)
{
string buy_Order = Symbol.Code.ToString() + "Buy Order";
var B1 = Positions.FindAll(buy_Order, Symbol, TradeType.Buy);
foreach (Position position in B1)
{
Print("Canceled " + buy_Order);
foreach (var order in PendingOrders)
{
if (order.Label == buy_Order)
CancelPendingOrder(order);
}
}