Download MetaTrader 5

Two EA's when amalgamated don't return the expected value

To add comments, please log in or register
xanderhinds
100
xanderhinds  

Hi,

I've got two different EA's both profitable over 2016 on GBPJPY on the 1H timeframe, one returns 267.51 and the other 233.54 yet when amalgamated into a single EA that uses both trading strategies simultaneously (whilst allowing the extra positions to be opened) the return was 269.97.

I had expected the return amount to be equal to both of the individual EA's return put together and was obviously wrong. Without posting the EA, is it common for an EA amalgamation to interfere with itself to return less profit than anticipated or is it more likely that the EA is programmed incorrectly?

Thanks! 

Fernando Carreiro
2947
Fernando Carreiro  
xanderhinds: I've got two different EA's both profitable over 2016 on GBPJPY on the 1H timeframe, one returns 267.51 and the other 233.54 yet when amalgamated into a single EA that uses both trading strategies simultaneously (whilst allowing the extra positions to be opened) the return was 269.97.

I had expected the return amount to be equal to both of the individual EA's return put together and was obviously wrong. Without posting the EA, is it common for an EA amalgamation to interfere with itself to return less profit than anticipated or is it more likely that the EA is programmed incorrectly?

Yes and no! There are several scenarios where one strategy can negatively impact the other.

The most obvious reason is, the money management! Lets say that when you back-tested each one separately, you were using 1% risk for each trade. Now with both working together, you may be attributing 0.5% risk to each strategy so that together they never go over the 1% Limit. So, in this case each is only contributing to half its initial test results and in the end they both together return a similar gain as the individual tests.

Another possibility, is that when one strategy is going into draw-down, thus reducing your balance, the profits based on a x% risk of the other strategy is not compounding but instead reducing (because of the overall draw-down caused by the other strategy), so that the final values are not as great.

These are just possibilities! There could be many other factors!

And yes, it could also be that the EA is not properly coded!

xanderhinds
100
xanderhinds  
Fernando Carreiro:

Yes and no! There are several scenarios where one strategy can negatively impact the other.

The most obvious reason is, the money management! Lets say that when you back-tested each one separately, you were using 1% risk for each trade. Now with both working together, you may be attributing 0.5% risk to each strategy so that together they never go over the 1% Limit. So, in this case each is only contributing to half its initial test results and in the end they both together return a similar gain as the individual tests.

Another possibility, is that when one strategy is going into draw-down, thus reducing your balance, the profits based on a x% risk of the other strategy is not compounding but instead reducing (because of the overall draw-down caused by the other strategy), so that the final values are not as great.

These are just possibilities! There could be many other factors!

And yes, it could also be that the EA is not properly coded!

Thanks for your response, it was helpful. I think then, as I've yet to input the MM system, the code must be defective. After some trial and error I'm going to suppose that it's because of this piece of code now becoming less active and not resetting the OMN to 0 as often.

if (OrdersTotal() == 0)
  {
     OMNB5 = 0;
     OMNS5 = 0;
     OMNB51 = 0;
     OMNS51 = 0;
  }

Instead I may input this piece of code, do you think it would have the desired effect?  

for ( int v = _OrdersTotal - 1; v >= 0; v -- )

    {

        //---- if an error occurs when searching for a position, go to the next one

 if ( !OrderSelect( v, SELECT_BY_POS ) )

        

    {

       _GetLastError = GetLastError();

       Print( "OrderSelect( ", v, ", SELECT_BY_POS ) - Error #", _GetLastError );

       continue;

    }

              

if ( OrderMagicNumber() == 5 )

   

    {

     

   if (OrderType() == OP_BUY)

       

        {

        return(0);

        }

   

   else 

       {

       OMNB5 = 0;

       }

        

   if (OrderType() == OP_SELL)

   

        {

        return(0);

        }

   else 

       {

       OMNS5 = 0;

       }

        

    }

     

if ( OrderMagicNumber() == 51 )

   

     {

     

   if (OrderType() == OP_BUY)

       

        {

        return(0);

        }

  else 

       {

       OMNB51 = 0;

       }

        

   if ( OrderType() == OP_SELL )

        

        {

        return(0);

        }

   else 

       {

       OMNS51 = 0;

       }

        

     }

 

 continue;    

     

  } // END OF FOR V

Fernando Carreiro
2947
Fernando Carreiro  
xanderhinds:

Thanks for your response, it was helpful. I think then, as I've yet to input the MM system, the code must be defective. After some trial and error I'm going to suppose that it's because of this piece of code now becoming less active and not resetting the OMN to 0 as often.

Instead I may input this piece of code, do you think it would have the desired effect?  

That is insufficient to be able to help you! But your coding style, does show that your code is very prone to logic flow problems!

Irrespective of that, your "if (OrdersTotal() == 0)" logic is flawed too. It will not play well if other EAs or instants of itself are running at the same.

whroeder1
16058
whroeder1  
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it

  2. Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.) Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 forum
xanderhinds
100
xanderhinds  
whroeder1:
  1. Please edit your post.
    For large amounts of code, attach it

  2. Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.) Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 forum
Thanks Whroeder
xanderhinds
100
xanderhinds  
whroeder1:
  1. Please edit your post.
    For large amounts of code, attach it

  2. Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.) Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 forum

Whroeder, I'm looking through your code but could you clarify something?

How/where is iWhat, eSelect, and ePool given a value? 

bool     MySelect(int iWhat, int eSelect, int ePool=MODE_TRADES) // MySelect bool, value given below

{
   if(!OrderSelect(iWhat, eSelect, ePool) )  return (false);
   if(OrderMagicNumber() != magic.number  )  return (false);
   if(OrderSymbol()      != symbol.chart  )  return (false);
   if(ePool != MODE_HISTORY               )  return (true);
   return(OrderType() <= OP_SELL);  
}

// So bool only true when

 As it is initiated only within the bool, why then would

OrderSelect(iWhat,eSelect,ePool)

ever return true? (For ePool it's because the order that has been selected is from MODE_TRADES (but not from MODE_HISTORY), but the iWhat and eSelect are befuddling me)


Also, where does 

return(OrderType() <= OP_SELL);  

come into play? 


 

xanderhinds
100
xanderhinds  

On further consideration I think I may have improperly worded my question..

When I ran my initial EA, it only looked at one symbol and one timeframe. The EA was never able to have more than one position open at a time, because of this fact I could use this rather primitive code 

 

if (OrdersTotal() == 0)
  {
     OMNB5 = 0;
     OMNS5 = 0;
  }

 to simply reset OMNB5/OMNS5 back to 0 in case

      if ((AO4 < 0.0))
            //(MACD1 < 0.0) ||
            {
                //---- close the position
                if ( !OrderClose( OrderTicket(), OrderLots(), Bid, 10, Green ) )
                {
                    _GetLastError = GetLastError();
                    Alert( "Error OrderClose # ", _GetLastError );
                    return(-1);
                }
                else
                {
                OMNB5--;
                continue;
                

'OMNB5--' is not triggered, say for example where a stop loss is moved to break even;

   else if(Bid > (OrderOpenPrice() + 250*Point()))
           //else if ( B < A)

                  {  
                   if (OrderModify(OrderTicket(),OrderOpenPrice(),(OrderOpenPrice()+5*Point()),OrderTakeProfit(),0,Green)== true)
                     {
                     //OMNB5--;
                     continue;
                    
                     }
                   else
                     {
                     Alert ("Problem whilst moving SL to BE");
                     return(0);
                     }
                  }  

The problem arose when I compiled multiple EA's into one another, sometimes multiple positions would open and close correctly as each has a unique magicnumber that excludes it from being closed by the wrong function, HOWEVER; The OMNB5/OMNS5 is now no longer effectively reset whenever OrdersTotal == 0.
 

For the life of me I can't think of a way to query the open orders and then reset OMNB5 back to = 0 when there are still other positions open but not position that was initiated by the OMN'5' strategy part..

Is there anyone who knows how to achieve this without using the 'OMNB5--;' function after successfully moving SL to Break even? 

To add comments, please log in or register