open just 1 order, when a variable change status

 

Good evening everybody, 

I'm really stuck, I want my code open 1 time, 1 order, 1 single time 1 order when the signal is BUY , then 1 time, 1 single time when signal is SELL, and so on everytime ( and just ) the signal change


but my code open 60 orders everytime the signal change from BUY to SELL, ( 60 time as 60 second, the time frame I m watching


please anybodu knows how to help me telling the EA, "OPEN JUST ONE ORDER WHEN THE SIGNAL VARIABLE CHANGE STATUS?


( i tried with number order, and open max number plus 1, but noting, then I tried, " if the candle is 60 sec, then open once in 60 second, nothing.... please some idea?)


here the code


// PROBLEM  PROBLEM PROBLEM : open 60 new reds on 1 min Time frame

input int SmallSMA=10;

input int BigSMA=20;

//datetime LastActionTime = 0; // test num 19



void OnTick()

{ 

   string signal ="";



   double SmallMovingAverage1 = iMA(_Symbol, _Period, SmallSMA, 0, MODE_SMA, PRICE_CLOSE, 1);

   double BigMovingAverage1 = iMA(_Symbol, _Period, BigSMA, 0, MODE_SMA, PRICE_CLOSE, 1);

   double SmallMovingAverage2 = iMA(_Symbol, _Period, SmallSMA, 0, MODE_SMA, PRICE_CLOSE, 2);

   double BigMovingAverage2 = iMA(_Symbol, _Period, BigSMA, 0, MODE_SMA, PRICE_CLOSE,2);

  

//  SELL

      if (BigMovingAverage1 > SmallMovingAverage1)

      if (BigMovingAverage2 < SmallMovingAverage2)

   {

   signal ="sell";

   }

// BUY

      if (BigMovingAverage1 < SmallMovingAverage1)

      if (BigMovingAverage2 > SmallMovingAverage2)

   {

   signal ="buy";

   }

  // if ((LastActionTime != Time[0]) && (signal == "buy") ) // test number 19

if (signal == "buy")

   {

     OrderSend (Symbol(), OP_BUY, 0.01, Ask, 0, 0, 0, NULL, 0, 0, Green) ;

    // LastActionTime = Time[0];

   }

    // if ((LastActionTime != Time[0]) && (signal == "sell") )

if (signal == "sell") 

   {

     OrderSend (Symbol(), OP_SELL, 0.01, Bid, 0, 0, 0, NULL, 0, 0, Green) ;

     // LastActionTime = Time[0];

   }

}
 
For
This you should include one more filter … to open orders only if OrdersTotal<1… 
Reason: