Placing more than one trade per Bar

 

I built this EA and I thought I put in the code to only make one trade per bar but it dont seem to be working. Sometimes it places more than one trade per bar. Could someone please help me figure out why? I'm checking with datetime and storing it in time.

Files:
CS_Stoch_EA.mq4  42 kb
 
Check. I did not look at all the code. Check in OnTick
Files:
CS_Stoch_EA.mq4  42 kb
 
SirFency: I built this EA and I thought I put in the code to only make one trade per bar but it dont seem to be working. Sometimes it places more than one trade per bar. Could someone please help me figure out why? I'm checking with datetime and storing it in time.
  1. In CheckForSignal, you have new bar code around your (many) tests. Each test could call EnterTrade. Thus your problem. After each EnterTrade add a return so you don't open more.

  2. You also have a bogus recursive call in CheckForSignal
          //Enters a buy trade if the conditions are met
          if(perGBP > perEUR && GbpEurDiff > gap && previousK < previousD && currentK > currentD && currentD < 20)
            {
            CheckForSignal();
            EnterTrade(OP_BUY);
            }
    

  3. Your code
       double GbpEurDiff = perGBP - perEUR;  //Check to see if the difference is below zero
          if(GbpEurDiff < 0)
          {     
          GbpEurDiff = -GbpEurDiff; //if its below zero invert the negative to positive 
          }
    
    Simplified
       double GbpEurDiff = MathAbs(perGBP - perEUR);  //Check to see if the difference is below zero
    


 
whroeder1:
  1. In CheckForSignal, you have new bar code around your (many) tests. Each test could call EnterTrade. Thus your problem. After each EnterTrade add a return so you don't open more.

  2. You also have a bogus recursive call in CheckForSignal

  3. Your code
    Simplified


Thank you whroeder1. Would I just return zero? return(0);

Reason: