Bollinger Band Expert Advisor

 

My EA is created with the idea that it should execute a buy order when the current price goes below the lower band and a sell order

when the current price crosses above the upper band. But he doesn't react as he wishes. At first he carried out orders but now nothing

I review the code but I don't understand what's wrong, no problem. yet nothing works. I need help

Auto-translation applied by moderator

#include<Trade/Trade.mqh>
#include <Trade\PositionInfo.mqh>
#include <Trade\OrderInfo.mqh>
COrderInfo Order;
CPositionInfo  position;
CTrade trade;

double open[];
double close_1[];

double Low[];
double High[];
int BollingerBands;

int OnInit()
  {
//---
   Newbar();

    BollingerBands = iBands(_Symbol,PERIOD_M1,20,0,2,PRICE_CLOSE);
    
    ChartIndicatorAdd(0,0,BollingerBands);

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
  
  bool Newbar=Newbar();
   
   double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
   double Bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
   
   MqlRates PriceInfo[];
   int data=CopyRates(_Symbol,_Period,0,3,PriceInfo);
   double MiddleBandArray[];
   double UpperBandArray[];
   double LowerBandArray[];
   
   ArraySetAsSeries(MiddleBandArray,true);
   ArraySetAsSeries(UpperBandArray,true);
   ArraySetAsSeries(LowerBandArray,true);
  
   CopyBuffer(BollingerBands,0,0,3,MiddleBandArray);
   CopyBuffer(BollingerBands,1,0,3,UpperBandArray);
   CopyBuffer(BollingerBands,2,0,3,LowerBandArray);
   
   double current_price = iLow(_Symbol, _Period, 0);
   double current_price1 = iHigh(_Symbol, _Period, 0);
   double last_price = iLow(_Symbol, _Period, 1);
   double last_price1 = iHigh(_Symbol, _Period, 1);
   
   CopyClose(_Symbol,PERIOD_M1,0,5,close_1);
   CopyOpen(_Symbol,PERIOD_M1,0,5,open);

   //calcualte EA for the cuurent candle
   double MiddleBandValue=MiddleBandArray[0];
   double UpperBandValue=UpperBandArray[0];
   double LowerBandValue=LowerBandArray[0];
   
   double MiddleBandValue1=MiddleBandArray[1];
   double UpperBandValue1=UpperBandArray[1];
   double LowerBandValue1=LowerBandArray[1];
   //giving sell signal when price < MA
   
   Print("Prix actuel : ", current_price, " | Bande inférieure : ", LowerBandValue);
   Print("Prix actuel : ", current_price1, " | Bande supérieure : ", UpperBandValue);

   if(Newbar==true)

     {     
   if(current_price<LowerBandValue&&last_price>LowerBandValue)
           {
         trade.Buy(0.005,NULL,Ask,Ask-100*_Point,Ask+2000*_Point,NULL);
            }  
         
   if(current_price1>UpperBandValue&&last_price1<UpperBandValue)
      
         {
         trade.Sell(0.005,NULL,Bid,Bid+100*_Point,Bid-2000*_Point,NULL);
         }  
  }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void CloseAllOrders()
  {
   int i=PositionsTotal()-1;
   while(i>=0)
     {

      if(trade.PositionClose(PositionGetSymbol(i)))
         i--;

     }

  }

void CheckBreakaeEvenStop(double ASK)

  {
   for(int i=PositionsTotal()-1; i>=0; i--)
     {
      string symbol= PositionGetSymbol(i);
      double positionStopLoss= PositionGetDouble(POSITION_SL);
      double positionTakeProfit= PositionGetDouble(POSITION_TP);

      if(_Symbol==symbol)
        {
         ulong positionTicket= PositionGetInteger(POSITION_TICKET);
         //get the position buy price
         double PositionBuyPrice= PositionGetDouble(POSITION_PRICE_OPEN);

         if(ASK>(PositionBuyPrice+100*_Point))
           {
            trade.PositionModify(positionTicket,PositionBuyPrice+20*_Point,positionTakeProfit);

           };

        }

     }

  }

void CheckBreakaeEvenStop1(double BID)

  {
   for(int i=PositionsTotal()-1; i>=0; i--)
     {
      string symbol= PositionGetSymbol(i);
      double positionStopLoss= PositionGetDouble(POSITION_SL);
      double positionTakeProfit= PositionGetDouble(POSITION_TP);
      if(_Symbol==symbol)
        {
         ulong positionTicket= PositionGetInteger(POSITION_TICKET);
         //get the position buy price
         double PositionBuyPrice= PositionGetDouble(POSITION_PRICE_OPEN);
         if(BID<(PositionBuyPrice-100*_Point))
           {
            trade.PositionModify(positionTicket,PositionBuyPrice-20*_Point,positionTakeProfit);

           };
        }
     }
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool Newbar()
  {

   static datetime previous_time= 0;
   datetime current_time= iTime(Symbol(),PERIOD_CURRENT,0);
   if(previous_time!=current_time)
     {
      previous_time=current_time=current_time;
      return(true);

     }
   return(false);

  }

void ModifyPo()

  {

   for(int i=PositionsTotal()-1; i>=0; i--)
     {


      string symbol= PositionGetSymbol(i);
      double positionStopLoss= PositionGetDouble(POSITION_SL);
      double PositionBuyPrice= PositionGetDouble(POSITION_PRICE_OPEN);
      double BID= NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
      double MyAccountEquity=  AccountInfoDouble(ACCOUNT_EQUITY);
      double MyAccountProfit=  AccountInfoDouble(ACCOUNT_PROFIT);
      double positionTakeProfit= PositionGetDouble(POSITION_TP);
      if(_Symbol==symbol)
        {
         ulong positionTicket= PositionGetInteger(POSITION_TICKET);
         //get the position buy price
         double PositionStopPoint=((BID-PositionBuyPrice) /4)*3;
         double positionStopPrice=(MathAbs( PositionBuyPrice+PositionStopPoint));
         if(20<=MyAccountProfit)
           {
            trade.PositionModify(positionTicket,positionStopPrice,positionTakeProfit);

           };
        }

     }

  }

//+------------------------------------------------------------------+
 
On the English forum, please write in English. Either use the automatic translation tool, or post in one of the other language forums.