Help Positions Entry

 

Hi Guys, I have a problem with EA.  It's working fine but it doesn't trade until the previous trade is done....

I'm pretty sure it has to do with, PositionsTotal() or OrderTotal() function...

I'm missing lots of good trades, for that reason...


Could you guys help me to solve this one???


Thanks


//****************************************************************************************

#include<Trade\Trade.mqh>

CTrade  trade;



void OnTick()

  {   

//============================PRECOS DO METATRADER PARA CONDICOES=================================================    

   double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);  // Get the Ask price  

   double Bid=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);  // Get the Bid price       

MqlRates PriceInfo[];                                                      // We create an array for the prices

   ArraySetAsSeries(PriceInfo,true);                                          // We sort the price array from the current candle downwards  

   int PriceData =CopyRates(Symbol(),Period(),0,10,PriceInfo);                 // We fill the array with the price data


string signal="";

      

      // create an Array for several prices

      double myMovingAverageArray1[],myMovingAverageArray2[],myMovingAverageArray3[],myMovingAverageArray4[];

      

      // define the properties of the Moving Average1

      int movingAverageDefinition1 = iMA (_Symbol,_Period,55,0,MODE_EMA,PRICE_CLOSE);

      

      // define the properties of the Moving Average2

      int movingAverageDefinition2 = iMA (_Symbol,_Period,144,0,MODE_EMA,PRICE_CLOSE);

      

      // define the properties of the Moving Average3

      int movingAverageDefinition3 = iMA (_Symbol,_Period,233,0,MODE_EMA,PRICE_CLOSE);

      

      // define the properties of the Moving Average4

      int movingAverageDefinition4 = iMA (_Symbol,_Period,377,0,MODE_EMA,PRICE_CLOSE);      

      

      // sort the price array1 from the current candle downwards

      ArraySetAsSeries(myMovingAverageArray1,true);

      

      // sort the price array2 from the current candle downwards

      ArraySetAsSeries(myMovingAverageArray2,true);

      

      // sort the price array1 from the current candle downwards

      ArraySetAsSeries(myMovingAverageArray3,true);

      

      // sort the price array2 from the current candle downwards

      ArraySetAsSeries(myMovingAverageArray4,true);      

      

      // Defined MA1, one line,current candle,3 candles, store result 

      CopyBuffer(movingAverageDefinition1,0,0,3,myMovingAverageArray1);

      

      // Defined MA2, one line,current candle,3 candles, store result 

      CopyBuffer(movingAverageDefinition2,0,0,3,myMovingAverageArray2);

      

      // Defined MA3, one line,current candle,3 candles, store result 

      CopyBuffer(movingAverageDefinition3,0,0,3,myMovingAverageArray3);

      

      // Defined MA4, one line,current candle,3 candles, store result 

      CopyBuffer(movingAverageDefinition4,0,0,3,myMovingAverageArray4);      

      

      // calculate MA1 for the current candle

      double myMovingAverageValue1=myMovingAverageArray1[0];

      

      // calculate MA2 for the current candle

      double myMovingAverageValue2=myMovingAverageArray2[0];

      

      // calculate MA3 for the current candle

      double myMovingAverageValue3=myMovingAverageArray3[0];

      

      // calculate MA4 for the current candle

      double myMovingAverageValue4=myMovingAverageArray4[0];

      

       

      // Sell Signal

      if (myMovingAverageValue1 < myMovingAverageValue2)

      if (myMovingAverageValue2 < myMovingAverageValue3)

      if (myMovingAverageValue3 < myMovingAverageValue4)

      if (PositionsTotal()<1)

      if (OrdersTotal()<1)      

            {

       trade.Sell(0.10,NULL,Bid,0,(Bid-150*_Point),NULL);

            }       

                

      // Buy Signal

      if (myMovingAverageValue1 > myMovingAverageValue2)

      if (myMovingAverageValue2 > myMovingAverageValue3)

      if (myMovingAverageValue3 > myMovingAverageValue4)

      if (PositionsTotal()<1)

      if (OrdersTotal()<1)      

            {

      trade.Buy(0.10,NULL,Ask,0,Ask+150*_Point,NULL);

            }     

            

      Comment ("Signal: ",signal,"\n",

               "myMovingAverageValue1: ",myMovingAverageValue1,"\n",

               "myMovingAverageValue2: ",myMovingAverageValue2,"\n",

               "myMovingAverageValue3: ",myMovingAverageValue3,"\n",  

               "myMovingAverageValue4: ",myMovingAverageValue4,"\n"                                           

              );

              

  }

 
      if (PositionsTotal()<1)

      if (OrdersTotal()<1)      
modify these to maybe a maximum but be aware that you may get more trades open than you really want.