My EA seems to be in a loop! Help please!

 

I have written an EA that scans several currency pairs and when it finds a particular condition it mus alert me.

Now I find that the EA gets seemingly in a loop on one currency pair (USDCHF) and does not operate correctly. Here is the message from the Journal:

22:35:16 2013.01.10 00:00 NonLagMA_v7.1 Usdchf,H1: loaded successfully
22:35:16 2013.01.10 00:00 NonLagMA_v7.1 Usdchf,H1: removed
22:35:16 2013.01.10 00:00 NonLagMA_v7.1 Usdchf,H1: loaded successfully
22:35:16 2013.01.10 00:00 NonLagMA_v7.1 Usdchf,H1: removed
22:35:16 2013.01.10 00:00 NonLagMA_v7.1 Usdchf,H1: loaded successfully

22:35:16 2013.01.10 00:00 NonLagMA_v7.1 Usdchf,H1: removed

Could somebody please have a look at my code and tell me what i am doing wrong?

nt start()
  {
   if(Bars<200 || IsTradeAllowed()==false) return;
  
// Trading Hours
                if (TradeHoursFunc == true)
             {  
                     
                     // Convert start time
                    string StartConstant = StringConcatenate(StartHour,":",StartMinute);    

                    datetime StartTime = StrToTime(StartConstant);

                    // Convert end time
                    string EndConstant = StringConcatenate(EndHour,":",EndMinute);  

                    datetime EndTime = StrToTime(EndConstant);

                    // Choose local or server time
                    if(UseLocalTime == true) datetime CurrentTime = TimeLocal();        
                    else CurrentTime = TimeCurrent();   

                    // Check for trade condition
                    if(StartTime <= CurrentTime && EndTime > CurrentTime) 
                              {
                                      Trade = true;     
                              }
                    else Trade = false;
             }
      else Trade = true;  
      
      
      string Symbols[]= {"Eurusd","Usdjpy","Gbpusd","Usdchf","Usdcad","Audusd","Nzdusd","Gbpchf","Gbpjpy","Euraud","Eurchf","Eurjpy",
      "Eurgbp","Eurcad","Chfjpy","Audnzd","Audjpy","Cadjpy","Audcad","Audchf","Cadchf","Eurnzd","Gbpaud","Gbpcad","Gbpnzd","Nzdchf","Nzdcad","Nzdjpy"};

      for(int i=0;i<ArraySize(Symbols);i++)
      {
//And:

        UpLong = iCustom(Symbols[i],TimeFrame,"NonLagMA_v7.1",PriceModeLong,LengthLong,0,FilterLong,1,0,0,0,0,1,1);
        DownLong = iCustom(Symbols[i],TimeFrame,"NonLagMA_v7.1",PriceModeLong,LengthLong,0,FilterLong,1,0,0,0,0,2,1);
        UpShort = iCustom(Symbols[i],TimeFrame,"NonLagMA_v7.1",PriceModeShort,LengthShort,0,FilterShort,1,0,0,0,0,1,1);
        DownShort = iCustom(Symbols[i],TimeFrame,"NonLagMA_v7.1",PriceModeShort,LengthShort,0,FilterShort,1,0,0,0,0,2,1);
        
        UpLong2 = iCustom(Symbols[i],TimeFrame,"NonLagMA_v7.1",PriceModeLong,LengthLong,0,FilterLong,1,0,0,0,0,1,2);
        DownLong2 = iCustom(Symbols[i],TimeFrame,"NonLagMA_v7.1",PriceModeLong,LengthLong,0,FilterLong,1,0,0,0,0,2,2);
        DownShort2 = iCustom(Symbols[i],TimeFrame,"NonLagMA_v7.1",PriceModeShort,LengthShort,0,FilterShort,1,0,0,0,0,2,2);
        UpShort2 = iCustom(Symbols[i],TimeFrame,"NonLagMA_v7.1",PriceModeShort,LengthShort,0,FilterShort,1,0,0,0,0,1,2);

         
         if (UpLong == 2147483647) UpLong = 0;
         if (UpLong2 == 2147483647) UpLong2 = 0;
         if (UpShort == 2147483647) UpShort = 0;
         if (UpShort2 == 2147483647) UpShort2 = 0;
         if (DownLong == 2147483647) DownLong = 0;
         if (DownLong2 == 2147483647) DownLong2 = 0;
         if (DownShort == 2147483647) DownShort = 0;
         if (DownShort2 == 2147483647) DownShort2 = 0;
         
         
         Print(" UpLong is ", UpLong, " DownLong is ", DownLong, " UpLong2 is ", UpLong2, " DownLong2 is ", DownLong2, " UpShort is ", 
          UpShort, " UpShort2 is ". UpShort2, " DownShort is ", DownShort, " DownShort2 is ", DownShort2);
         
         if ((UpShort != 0 && DownShort != 0) || (UpLong != 0 && DownLong != 0))
         return(0);
         
     if (UseNonLag == true)
       {
         if ((UpLong != 0 && UpShort != 0) && (UpLong2 != 0 && UpShort2 != 0)) BuyArray[2] = true;
         else BuyArray[2] = false;
         if ((DownLong2 != 0 && DownShort2 != 0) && (DownLong2 != 0 && DownShort2 != 0)) SellArray[2] = true;
         else SellArray[2] = false;
         }
     if (UseNonLag == false)
         {
         if (UpLong != 0 && UpLong2 != 0) BuyArray[2] = true;
         else BuyArray[2] = false;
         if (DownLong != 0 && DownLong2 != 0) SellArray[2] = true;
         else SellArray[2] = false;
         }   
 
ernest02:

I have written an EA that scans several currency pairs and when it finds a particular condition it mus alert me.

Now I find that the EA gets seemingly in a loop on one currency pair (USDCHF) and does not operate correctly. Here is the message from the Journal:

22:35:16 2013.01.10 00:00 NonLagMA_v7.1 Usdchf,H1: loaded successfully

Are you certain that you have the symbol names correctly specified ? I've never seen lowercase used in symbol pair names.
 

notice: EMPTY_VALUE = 2147483647

         if (UpLong == 2147483647) UpLong = 0;
         if (UpLong2 == 2147483647) UpLong2 = 0;
 
ernest02:
22:35:16 2013.01.10 00:00 NonLagMA_v7.1 Usdchf,H1: loaded successfully
22:35:16 2013.01.10 00:00 NonLagMA_v7.1 Usdchf,H1: removed
22:35:16 2013.01.10 00:00 NonLagMA_v7.1 Usdchf,H1: loaded successfully
22:35:16 2013.01.10 00:00 NonLagMA_v7.1 Usdchf,H1: removed
22:35:16 2013.01.10 00:00 NonLagMA_v7.1 Usdchf,H1: loaded successfully
Continous reloading of custom indicator in EA - MQL4 forum
 
szgy74:

notice: EMPTY_VALUE = 2147483647



Sorry, but I am missing the point.

Please expand if you do not mind

 
Try using capitals i.e. EURUSD
 
ernest02:

Sorry, but I am missing the point.

Please expand if you do not mind


not really important.

you can use the EMPTY_VALUE constant when you don't want to bother with this long number :-)

 
ernest02: Sorry, but I am missing the point. Please expand if you do not mind
Don't hard code numbers
Use the constants
2147483647EMPTY_VALUE
0
PRICE_CLOSE
0
DRAW_LINE
0
MODE_MAIN
0MODE_SMA
0
OBJPROP_TIME1
0NULL
0OP_BUY
0WHOLE_ARRAY
Etc.
 

Guys,

Thanks for all the advice.

It seems to me that the problem was NOT using capitals in in the currency pair's names. I picked this piece of code (scanning pairs one by one) up from this site and the pairs was defined as I had them originally. I hought this programmer knew what he was doing.

Cost me a lot of time though!

Hope this EA will now start giving me signals on my live account.

Will let you know if the problem is still not solved.


Ernest.

 

Sorry Guys! The EA is still not working. It stopped that load/remove loop of the USDCHF currency when I made all the names of the pairs in capital letters, but now it only loads 3 pairs (EURUSD; USDCHF and USDCAD) and none of the other.

Then it only loops through the code for the pair on which the EA is loaded, ie GBPUSD. It does not go to the other pairs at all. How can I get the code to loop through all the pairs and not just the one the EA is loaded on?

Need your help. I am completely out of my depth here!


Ernest.

 
ernest02:

Sorry Guys! The EA is still not working. It stopped that load/remove loop of the USDCHF currency when I made all the names of the pairs in capital letters, but now it only loads 3 pairs (EURUSD; USDCHF and USDCAD) and none of the other.

Then it only loops through the code for the pair on which the EA is loaded, ie GBPUSD. It does not go to the other pairs at all. How can I get the code to loop through all the pairs and not just the one the EA is loaded on?

Need your help. I am completely out of my depth here!

Do you have data for all the other pairs ? if you don't you will know by checking for error 4066 ( search for error 4066 for more info ) then wait, then try again and again check for error 4066.
Reason: