stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

TargetCloseAllTradesBE" when it "ClosePair (symbol)"
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=4844
Page 1 of 1
Author:  traderduke [ Sat Jul 30, 2016 1:36 pm ]
Post subject:  TargetCloseAllTradesBE" when it "ClosePair (symbol)"

Hi
I just started using TargetCloseAllTradesBE with the EmergPairLossPerc option (line 37), on BnG pg88. I identify the EA this way because their are same name EAs without the newest option.

The problem is "TargetCloseAllTradesBE" when "EmergPairLossPerc" calls for "ClosePair (symbol)" in BnG the errors are caused by the pending orders. The pending orders do get closed evently but with nuuuuuumerous failures. When you have hundreds of pending it can a lot of failures. We need a EA coder to close pending orders properly.

Thank you for your help

Ray


See attached:
TargetCloseAllTradesBE-wSymbol-EA.mq4

Application1(2016-7-30)0001-TMProb.jpg
Author:  renexxxx [ Sat Jul 30, 2016 8:24 pm ]
Post subject:  TargetCloseAllTradesBE" when it "ClosePair (symbol)"

traderduke ยป Sat Jul 30, 2016 11:36 pm wrote:We need a EA coder to close pending orders properly.
Your version of ClosePair(string pair):

Code: Select all

void ClosePair(string pair)
{
   for (int i = OrdersTotal()-1 ; i >=0 ; i--)
   {
      if ( !OrderSelect( i, SELECT_BY_POS, MODE_TRADES ) ) continue;
      if ( OrderSymbol() != pair) continue;
         
      int ticket = OrderTicket();
      while(IsTradeContextBusy()) Sleep(100);
      if (!OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) continue;

      bool res = OrderClose(ticket, OrderLots(), OrderClosePrice(), 3, CLR_NONE);
      if(res)
         Alert("Order #" + IntegerToString(ticket) + " was closed.");
      else 
         Alert("Closing order failed: " + ErrorDescription(GetLastError()));

      Alert("Closed Losing Pair ",pair, "  <",DoubleToStr(EmergPairLossPerc,1));
   }
   return;
}
You have to make a decision: Do you want ClosePair to also delete pendings or not? If not, add below if ( OrderSymbol() != pair) continue; the following:

Code: Select all

      if ( OrderSymbol() != pair) continue;
      if ( (OrderType() != OP_BUY) && (OrderType() != OP_SELL) ) continue;
If you DO want ClosePair() to delete pendings, you have to replace lines 372-376 with:

Code: Select all

      bool res = false;
      if ( (OrderType() == OP_BUY) || (OrderType() == OP_SELL) ) {
         res = OrderClose(ticket, OrderLots(), OrderClosePrice(), 3, clrNONE);
      }
      else {
         res = OrderDelete( ticket, clrNONE );
      }
      if(res)
         Alert("Order #" + IntegerToString(ticket) + " was closed.");
      else 
         Alert("Closing order failed: " + ErrorDescription(GetLastError()));
Pending trades are not closed ... they are deleted.

And, one other thing, get rid of the second OrderSelect() ... the order has already been selected, no need to select it again.

R.
Author:  traderduke [ Sun Jul 31, 2016 12:10 pm ]
Post subject:  TargetCloseAllTradesBE" when it "ClosePair (symbol)"

Rene
Thanks for your help, I'll test it this week!

Ray
All times are UTC Page 1 of 1