UseZeljko - Checking For Open BUYSTOP & LIMIT Orders

Post Reply
theforexedge
Trader
Posts: 220
Joined: Thu Apr 26, 2012 10:31 pm
Location: Torquay

UseZeljko - Checking For Open BUYSTOP & LIMIT Orders

Post by theforexedge »

Hi

After the GBP flash crash earlier this month i've been looking at strategies to limit currency pairs when markets are extended and have revisited UseZeljko in Steves shellcode EA..

As my coding is quite limited i'm hoping someone could let me know if i would need to add
type ==OP_BUYSTOP && type == OP_BUYLIMIT if i want to check to see if pending orders are currently open in other pairs as I noticed the Current call is:

Code: Select all

if (UseZeljko && !BalancedPair(OP_BUY))
  return; 
Change to:

Code: Select all

if (UseZeljko && (!BalancedPair(OP_BUY)||!BalancedPair(OP_BUYSTOP)))                   return;
balanced pair code:

Do I need to add to check for open Limit Orders?

Code: Select all

 if (type == OP_BUY || type == OP_BUYSTOP ||  type == OP_BUYLIMIT)

Code: Select all

bool BalancedPair(int type)
{
   string BuyCcy1, SellCcy1, BuyCcy2, SellCcy2;

   if (type == OP_BUY || type == OP_BUYSTOP)
   {
      BuyCcy1 = StringSubstrOld(Symbol(), 0, 3);
      SellCcy1 = StringSubstrOld(Symbol(), 3, 3);
   }//if (type == OP_BUY || type == OP_BUYSTOP)
   else
   {
      BuyCcy1 = StringSubstrOld(Symbol(), 3, 3);
      SellCcy1 = StringSubstrOld(Symbol(), 0, 3);
   }//else

   for (int cc = OrdersTotal() - 1; cc >= 0; cc--)
   {
      if (!OrderSelect(cc, SELECT_BY_POS)) continue;
      if (OrderSymbol() == Symbol()) continue;
      if (OrderMagicNumber() != MagicNumber) continue;      
      if (OrderType() == OP_BUY || OrderType() == OP_BUYSTOP)
      {
         BuyCcy2 = StringSubstrOld(OrderSymbol(), 0, 3);
         SellCcy2 = StringSubstrOld(OrderSymbol(), 3, 3);
      }//if (OrderType() == OP_BUY || OrderType() == OP_BUYSTOP)
      else
      {
         BuyCcy2 = StringSubstrOld(OrderSymbol(), 3, 3);
         SellCcy2 = StringSubstrOld(OrderSymbol(), 0, 3);
      }//else
      if (BuyCcy1 == BuyCcy2 || SellCcy1 == SellCcy2) return(false);
   }//for (int cc = OrdersTotal() - 1; cc >= 0; cc--)

   //Got this far, so it is ok to send the trade
   return(true);

}//End bool BalancedPair(int type)
Thanks, Jason
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

UseZeljko - Checking For Open BUYSTOP & LIMIT Orders

Post by SteveHopwood »

theforexedge » Thu Oct 20, 2016 8:08 am wrote:Hi

After the GBP flash crash earlier this month i've been looking at strategies to limit currency pairs when markets are extended and have revisited UseZeljko in Steves shellcode EA..

As my coding is quite limited i'm hoping someone could let me know if i would need to add
type ==OP_BUYSTOP && type == OP_BUYLIMIT if i want to check to see if pending orders are currently open in other pairs as I noticed the Current call is:

Code: Select all

if (UseZeljko && !BalancedPair(OP_BUY))
  return; 
Change to:

Code: Select all

if (UseZeljko && (!BalancedPair(OP_BUY)||!BalancedPair(OP_BUYSTOP)))                   return;
balanced pair code:

Do I need to add to check for open Limit Orders?

Code: Select all

 if (type == OP_BUY || type == OP_BUYSTOP ||  type == OP_BUYLIMIT)

Code: Select all

bool BalancedPair(int type)
{
   string BuyCcy1, SellCcy1, BuyCcy2, SellCcy2;

   if (type == OP_BUY || type == OP_BUYSTOP)
   {
      BuyCcy1 = StringSubstrOld(Symbol(), 0, 3);
      SellCcy1 = StringSubstrOld(Symbol(), 3, 3);
   }//if (type == OP_BUY || type == OP_BUYSTOP)
   else
   {
      BuyCcy1 = StringSubstrOld(Symbol(), 3, 3);
      SellCcy1 = StringSubstrOld(Symbol(), 0, 3);
   }//else

   for (int cc = OrdersTotal() - 1; cc >= 0; cc--)
   {
      if (!OrderSelect(cc, SELECT_BY_POS)) continue;
      if (OrderSymbol() == Symbol()) continue;
      if (OrderMagicNumber() != MagicNumber) continue;      
      if (OrderType() == OP_BUY || OrderType() == OP_BUYSTOP)
      {
         BuyCcy2 = StringSubstrOld(OrderSymbol(), 0, 3);
         SellCcy2 = StringSubstrOld(OrderSymbol(), 3, 3);
      }//if (OrderType() == OP_BUY || OrderType() == OP_BUYSTOP)
      else
      {
         BuyCcy2 = StringSubstrOld(OrderSymbol(), 3, 3);
         SellCcy2 = StringSubstrOld(OrderSymbol(), 0, 3);
      }//else
      if (BuyCcy1 == BuyCcy2 || SellCcy1 == SellCcy2) return(false);
   }//for (int cc = OrdersTotal() - 1; cc >= 0; cc--)

   //Got this far, so it is ok to send the trade
   return(true);

}//End bool BalancedPair(int type)
Thanks, Jason
Yes, you would.

Make sure you have the latest BobStuff shell so we are talking about the same line numbers, because you need a teensy bit of additional code. Line 1513 is:
if (type == OP_BUY || type == OP_BUYSTOP)

It needs to be:
if (type == OP_BUY || type == OP_BUYSTOP || type == OP_BUYLIMIT)

the 'else' at 1518 takes care of all the SELL/STOP/LIMIT order types.

Great to see you getting your hands dirty Jason. :clap: :clap: :clap: :clap: :clap:

:xm:
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
theforexedge
Trader
Posts: 220
Joined: Thu Apr 26, 2012 10:31 pm
Location: Torquay

UseZeljko - Checking For Open BUYSTOP & LIMIT Orders

Post by theforexedge »

Steve

Thank you very much for replying and its always good to get some clarification when changing / adding stuff :good: as the shell code is such a great way for novice coders to start to understand mql4..

Anyway the other issue I've been having is using

Code: Select all

if (DeletePendingsDuringWideSpread) 
to close pending trades:

Code: Select all

CloseAllTrades(OP_BUYSTOP);
CloseAllTrades(OP_BUYLIMIT);
I was finding that when crapperquotes Empty4 was freezing up it occasionally was also closing the open OP_SELL or OP_BUY trades, so i could only assume this was being executed by ForceTradeClosure but only a guess!

Code: Select all

 if (!result) ForceTradeClosure= true;


Anyway I've cut and pasted the existing CloseAllTrades code so it now only looks to close the pending orders and again just wanted to ask if my logic is OK...

Code: Select all

void CloseAllPendingTrades(int type)
{
      if (OrdersTotal() == 0) return;
      
      bool result = false;
      
      for (int cc = ArraySize(FifoTicket) - 1; cc >= 0; cc--)
      {
         if (!OrderSelect(FifoTicket[cc], SELECT_BY_TICKET, MODE_TRADES) ) continue;
         if (OrderMagicNumber() != MagicNumber) continue;
         if (OrderSymbol() != Symbol() ) continue;
         if (OrderType() != type) 
            if (type != AllTrades)
               continue;
         
         while(IsTradeContextBusy()) Sleep(500);
        
            if (OrderType() > 1) 
            {
               result = OrderDelete(OrderTicket(), clrNONE);
               if (result) 
               {
                  cc++;
                  OpenTrades--;
                  DeletePendingPriceLines();
               }//(result) 
            
            if (!result) break;
            }
      }//End void CloseAllPendingTrades()
}            
Thanks, Jason
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

UseZeljko - Checking For Open BUYSTOP & LIMIT Orders

Post by SteveHopwood »

theforexedge » Sun Oct 23, 2016 1:00 pm wrote:Steve

Thank you very much for replying and its always good to get some clarification when changing / adding stuff :good: as the shell code is such a great way for novice coders to start to understand mql4..

Anyway the other issue I've been having is using

Code: Select all

if (DeletePendingsDuringWideSpread) 
to close pending trades:

Code: Select all

CloseAllTrades(OP_BUYSTOP);
CloseAllTrades(OP_BUYLIMIT);
I was finding that when crapperquotes Empty4 was freezing up it occasionally was also closing the open OP_SELL or OP_BUY trades, so i could only assume this was being executed by ForceTradeClosure but only a guess!

Code: Select all

 if (!result) ForceTradeClosure= true;


Anyway I've cut and pasted the existing CloseAllTrades code so it now only looks to close the pending orders and again just wanted to ask if my logic is OK...

Code: Select all

void CloseAllPendingTrades(int type)
{
      if (OrdersTotal() == 0) return;
      
      bool result = false;
      
      for (int cc = ArraySize(FifoTicket) - 1; cc >= 0; cc--)
      {
         if (!OrderSelect(FifoTicket[cc], SELECT_BY_TICKET, MODE_TRADES) ) continue;
         if (OrderMagicNumber() != MagicNumber) continue;
         if (OrderSymbol() != Symbol() ) continue;
         if (OrderType() != type) 
            if (type != AllTrades)
               continue;
         
         while(IsTradeContextBusy()) Sleep(500);
        
            if (OrderType() > 1) 
            {
               result = OrderDelete(OrderTicket(), clrNONE);
               if (result) 
               {
                  cc++;
                  OpenTrades--;
                  DeletePendingPriceLines();
               }//(result) 
            
            if (!result) break;
            }
      }//End void CloseAllPendingTrades()
}            
Thanks, Jason
Looks ok to me. Try it out when the markets open and we can sort out any glitches from there.

:xm:
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
theforexedge
Trader
Posts: 220
Joined: Thu Apr 26, 2012 10:31 pm
Location: Torquay

UseZeljko - Checking For Open BUYSTOP & LIMIT Orders

Post by theforexedge »

Thanks Steve...

I will test this week and let you know if I need any further help.. :good:

Have a great week..

Jason
Post Reply

Return to “Coders Hangout”