Opening a single order

 

Good day, I'm not a coder, I know nothing about coding but I've managed to scrap together this script.

its pretty simple, when price is above Parabolic SAR-Buy. When Price is below Parabolic Sar-Sell.

The problem is that it opens multiple orders on the same candle.(refer to image)

Can you please help, I need it to open a single order.

#define EXPERT_MAGIC 123456   // MagicNumber of the expert

void OnTick() 
  {
  
// Create an Array for several prices
  double mySARArray[];
  
   // define the properties of the SAR
   int SARDefinition = iSAR(NULL,0,0.02,0.20 );
   
   // sort the price array from the current candle downwards 
   ArraySetAsSeries(mySARArray, true) ;
   
   // Define EA, current candle, 3 candlea,store results
   CopyBuffer(SARDefinition,0,0,3,mySARArray) ;
   
   // calculate EA for the current  candle
   double SARValue0=NormalizeDouble(mySARArray[0],5);
   
   // calculate EA for the current  candle
   double SARValue1=NormalizeDouble(mySARArray[1],5);
   
//-------------------------Parameters for Buy Order-------------------------------//
   
   MqlTradeRequest request={0};
   MqlTradeResult  result={0};
   
   request.action   =TRADE_ACTION_DEAL;                     // type of trade operation
   request.magic    =EXPERT_MAGIC;                          // MagicNumber of the order
   request.symbol   =Symbol();                              // symbol   
   request.volume   =0.10;                                   // volume of 0.1 lot
   request.price    = SymbolInfoDouble(Symbol(),SYMBOL_ASK); // price for opening
   request.tp       = SymbolInfoDouble(Symbol(),SYMBOL_ASK)+NormalizeDouble(100,Digits());
   request.sl       =SymbolInfoDouble(Symbol(),SYMBOL_ASK)-NormalizeDouble(50,Digits());   
   request.deviation=0;                                     // allowed deviation from the price
   request.type     =ORDER_TYPE_BUY;                        // order type
   
//-------------------------Parameters for Sell order--------------------------//
   
  MqlTradeRequest request1={0};
   MqlTradeResult  result1={0};
  
    //--- parameters of request
   request1.action   =TRADE_ACTION_DEAL;                     // type of trade operation
   request1.magic    =EXPERT_MAGIC;                          // MagicNumber of the order
   request1.symbol   =Symbol();                              // symbol   
   request1.volume   =0.10;                                   // volume of 0.1 lot
   request1.price    = SymbolInfoDouble(Symbol(),SYMBOL_BID); // price for opening
    request1.tp      = SymbolInfoDouble(Symbol(),SYMBOL_BID)-NormalizeDouble(50,Digits());
   request1.sl       =SymbolInfoDouble(Symbol(),SYMBOL_BID) +NormalizeDouble(25,Digits());   
   request.deviation=0;                                     // allowed deviation from the price
   request1.type     =ORDER_TYPE_SELL;                        // order type
  
   
   
//-----------------------To be used for getting recent/latest price quotes----------------------//   

   MqlTick Latest_Price;                   // Structure to get the latest prices      
   SymbolInfoTick(Symbol() ,Latest_Price); // Assign current prices to structure 

// The BID price.
   static double dBid_Price; 

// The ASK price.
   static double dAsk_Price; 

   dBid_Price = Latest_Price.bid;  // Current Bid price.
   dAsk_Price = Latest_Price.ask;  // Current Ask price.
   
//-----------------Condition to Buy--------------------------//  
if ( 
   (SARValue0<dBid_Price)
   && (SARValue1>=dAsk_Price)
   
   )
   {
    OrderSend(request,result);
    Alert("buy");
   Comment("buy");
   
   }
//-----------------Condition to Sell--------------------------//  
    
    if(
     (SARValue0>dAsk_Price)
     && (SARValue1<=dBid_Price)
     )
     {
    OrderSend(request1,result1); 
    Alert("sell");
    Comment("sell");
    
    }
}
//--------------------------------------------------------------------------------------------------------------------------------//
Files:
Reason: