Bollinger Bands Upper and Lower crossing

 
void OnTick()
  {
  
  bool Newbar=Newbar();
   //define Ask, Bid
   double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
   double Bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
   
   //create an array for several prices
  
   MqlRates PriceInfo[];
   int data=CopyRates(_Symbol,_Period,0,3,PriceInfo);
   double MiddleBandArray[];
   double UpperBandArray[];
   double LowerBandArray[];
   
   //sort the price array from the cuurent candle downwards
   ArraySetAsSeries(MiddleBandArray,true);
   ArraySetAsSeries(UpperBandArray,true);
   ArraySetAsSeries(LowerBandArray,true);
   
   ArraySetAsSeries(PriceInfo,true);
   ArraySetAsSeries(open,true);
   ArraySetAsSeries(open_2,true);
   ArraySetAsSeries(close_1,true);
   ArraySetAsSeries(close_2,true);
   
   //define Bollinger Bands
   int BollingerBands = iBands(_Symbol,PERIOD_M15,20,0,2,PRICE_CLOSE);
   
   
   //copy price info into the array
   CopyBuffer(BollingerBands,0,0,3,MiddleBandArray);
   CopyBuffer(BollingerBands,1,0,3,UpperBandArray);
   CopyBuffer(BollingerBands,2,0,3,LowerBandArray);
   
   CopyClose(_Symbol,PERIOD_M1,0,5,close_1);
   CopyClose(_Symbol,PERIOD_M1,0,5,close_2);
   CopyClose(_Symbol,PERIOD_M1,0,5,close_3);
   CopyOpen(_Symbol,PERIOD_M1,0,5,open);
   CopyOpen(_Symbol,PERIOD_M1,0,5,open_2);
   
   //calcualte EA for the cuurent candle
   double MiddleBandValue=MiddleBandArray[0];
   double UpperBandValue=UpperBandArray[0];
   double LowerBandValue=LowerBandArray[0];
   
   //giving sell signal when price < MA
      
   if(Newbar==true)

     {     
   if (
      (Bid<=LowerBandArray[0])
      )
         {
         trade.Buy(0.05,NULL,Ask,Ask-500,Ask+20000*_Point,NULL);
         }  
   
      //check if we have no signal      
   if (
      (Bid>=UpperBandArray[0])
      )
         {
         trade.Sell(0.05,NULL,Bid,Bid+500,Bid-20000*_Point,NULL);
         }  
  }
  }

My EA's strategy is based on the Bollinger band

the idea: my EA should automatically open a buy position when the current price goes below the lower band of the Bollinger band.

Conversely, if the current price crosses above the upper band, it must open a sell position

problem: things are not going as hoped. he opens orders that I don't understand. I need help

 
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
MQL5 forum: Expert Advisors and Automated Trading
MQL5 forum: Expert Advisors and Automated Trading
  • www.mql5.com
How to create an Expert Advisor (a trading robot) for Forex trading
Reason: