Please tell me what is wrong with this simple code - page 2

 

Here is some more code: (Oh! I see I have forgotten to change the array size with my test if BUY is true - but that should not make any difference to the string of SELL alerts I am getting for EURUSD at the moment, because with the SELL test the array size is correct (??)

  
// 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;  

AND: 
 
 if (StochSellSignal == true || CurrencySellSignal == true) SellArray[3] = true; 
 if (StochBuySignal == true || CurrencyBuySignal == true) BuyArray[3] = true; 
    
 // Sell true/false
                  
         for (i=0; i<5; i++) 
         if (!SellArray[i]) break;
         if (i<4) Sell = false;
         else Sell = true;   
         
 // Buy true/false
                  
         for (i=0; i<6; i++) 
         if (!BuyArray[i]) break;
         if (i<5) Buy = false;
         else Buy = true;
 
RaptorUK:

Ernest, can you show the relationship between CurrencyBuySignal and CurrencySellSignal and these variables . . .

I'm not clear how the code in your first post relates to the Alert, can you explain please ?
 

To generate one of the conditions for an alert I have a Buy/Sell Array[4] which generates a "Buy" or a "Sell" if all 4 instances are true. (There are other tests too)

One of the instances (Buy/Sell Array[3]) is generated if either the StochBuy/SellSignal or the CurrencyBuy/SellSignal is true.

Last mentioned bool refers to my code in my first post.

 
ernest02:

To generate one of the conditions for an alert I have a Buy/Sell Array[4] which generates a "Buy" or a "Sell" if all 4 instances are true. (There are other tests too)

One of the instances (Buy/Sell Array[3]) is generated if either the StochBuy/SellSignal or the CurrencyBuy/SellSignal is true.

Last mentioned bool refers to my code in my first post.

Even if CurrencySell/BuySignal are false if StochSell/BuySignal are true Sell/BuyArray[3] will be true . . . so to answer your first post . . .

Here is the simple code. I get an alert signal even when just the middle condition (e.g. EURafter < USDafter) is true and the other two conditions are false !

. . . this can happen.
 

Yes but the problem is there when the StochSell/BuySignal is false and the CurrencySell/BuySignal should actually also be false - but is not.

The signal is generated because of the incorrect CurrencySell/BuySignal input. If i take away the StochSell/BuySignal code the problem is still there.