Can anybody help me with this indicator? What is missing?

 

Hello and Thanks for your time to look at my post.

I have tried a lot of different approaches to plot a simple arrow when bb middle line is above ma 200 and vice versa but It did not work or even plots.

I hope you help figure out what I am missing 

Thanks

//+------------------------------------------------------------------+
//|                                         Indicator BB and SMA.mq5 |
//|                                    Copyright 2023, Ahmed Ibrahim |
//|                        https://www.mql5.com/en/users/ahmedgouda0 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, Ahmed Ibrahim"
#property link      "https://www.mql5.com/en/users/ahmedgouda0"
#property version   "1.00"
#property indicator_chart_window
#include <MovingAverages.mqh>

#property indicator_buffers 4
#property indicator_plots   2

#property indicator_label1  "BUY"
#property indicator_type1   DRAW_ARROW
#property indicator_color1  clrBlue
#property indicator_style1  STYLE_SOLID 
#property indicator_width1  2

#property indicator_label2  "SELL"
#property indicator_type2   DRAW_ARROW
#property indicator_color2  clrRed
#property indicator_style2  STYLE_SOLID 
#property indicator_width2  2

input string G ="================= General Parameters =================";//=============================================================
input double   TakeProfit     = 600; 
input bool     Enable_Alert   = true;
input string B ="================= BB Parameters =================";//=============================================================
input int      BB_Period      = 15;
input int      BB_Shift       = 0;
input double   BB_Deviation   = 2.0;
input string M ="================= MA Parameters =================";//=============================================================
input int      MA_Period      = 200;
input ENUM_MA_METHOD MA_Method= MODE_EMA;

double                   BBBuffer[];
double                   MABuffer[];
double                   BuyArrow[],SellArrow[];
int                      BBHandle,MAHandle;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,BuyArrow,INDICATOR_DATA);
   SetIndexBuffer(1,SellArrow,INDICATOR_DATA);
   SetIndexBuffer(2,BBBuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(3,MABuffer,INDICATOR_CALCULATIONS);
   
   //IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
   
   //PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,BB_Period-2);
   //PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,BB_Period-2);
   
   PlotIndexSetInteger(0,PLOT_ARROW,100);
   PlotIndexSetInteger(1,PLOT_ARROW,100);
   
   ArrayGetAsSeries(BBBuffer);
   ArrayGetAsSeries(MABuffer);
   
   ArraySetAsSeries(MABuffer,true); 
   ArraySetAsSeries(BBBuffer,true); 
   
   BBHandle = iBands(NULL,PERIOD_CURRENT,BB_Period,BB_Shift,BB_Deviation,PRICE_CLOSE);
   MAHandle = iMA(NULL,PERIOD_CURRENT,MA_Period,0,MA_Method,PRICE_CLOSE);
   
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
     if(rates_total<MA_Period)
      return(0);
   
   
   int calculated=BarsCalculated(MAHandle);
   if(calculated<rates_total)
     {
      Print("Not all data of ExtFastMaHandle is calculated (",calculated,"bars ). Error",GetLastError());
      return(0);
     }
   calculated=BarsCalculated(BBHandle);
   if(calculated<rates_total)
     {
      Print("Not all data of ExtSlowMaHandle is calculated (",calculated,"bars ). Error",GetLastError());
      return(0);
     }
     
   int to_copy;
   if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total;
   else
     {
      to_copy=rates_total-prev_calculated;
      if(prev_calculated>0) to_copy++;
     }
     
   CopyBuffer(MAHandle,0,0,to_copy,MABuffer);
   CopyBuffer(BBHandle,0,0,to_copy,BBBuffer);

   
   int limit;
   
   if(prev_calculated==0)
      limit=0;
   else limit=prev_calculated-1;
     
   for(int i=limit ;i<rates_total && IsStopped();i++){
   
      if(MABuffer[i]<BBBuffer[i] )
         BuyArrow[i]=low[i];
         
      if(MABuffer[i]>BBBuffer[i])
         SellArrow[i]=high[i];
      }
      
   
   
   
   
   
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+


 
//ArrayGetAsSeries(BBBuffer);
//ArrayGetAsSeries(MABuffer);
   
   ArraySetAsSeries(BuyArrow,true); 
   ArraySetAsSeries(SellArrow,true); 
   ArraySetAsSeries(MABuffer,true); 
   ArraySetAsSeries(BBBuffer,true); 
 if(rates_total<MA_Period)
      return(0);
   
   ArraySetAsSeries(high,true); 
   ArraySetAsSeries(low,true); 
   
   int calculated=BarsCalculated(MAHandle);
if(prev_calculated==0)
      limit=rates_total - MA_Period;
   else limit=rates_total - prev_calculated+1;
     
   for(int i=limit ;i>=0 && !IsStopped();i--){
   
        BuyArrow[i]= EMPTY_VALUE;
        SellArrow[i]= EMPTY_VALUE;
        
      if(MABuffer[i]<BBBuffer[i] )
         BuyArrow[i]=low[i];
         
      if(MABuffer[i]>BBBuffer[i])
         SellArrow[i]=high[i];
      }



 
Nagisa Unada #:



Ok Thank you I will try your solution , but I have solve it with this solution

int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,BuyArrow,INDICATOR_DATA);
   SetIndexBuffer(1,SellArrow,INDICATOR_DATA);
   SetIndexBuffer(2,BBBuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(3,MABuffer,INDICATOR_CALCULATIONS);
   
   PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_ARROW);
   PlotIndexSetInteger(0,PLOT_ARROW,233);
   
   PlotIndexSetInteger(1,PLOT_DRAW_TYPE,DRAW_ARROW);
   PlotIndexSetInteger(1,PLOT_ARROW,234);
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE);
   
   ArraySetAsSeries(BuyArrow,true); 
   ArraySetAsSeries(SellArrow,true); 
   ArraySetAsSeries(MABuffer,true); 
   ArraySetAsSeries(BBBuffer,true); 
   
   BBHandle = iBands(NULL,PERIOD_CURRENT,BB_Period,BB_Shift,BB_Deviation,PRICE_CLOSE);
   MAHandle = iMA(NULL,PERIOD_CURRENT,MA_Period,0,MA_Method,PRICE_CLOSE);
   
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   int limit;
   if(rates_total<MA_Period)
         return(0);
   
  
   
   
   limit=rates_total - prev_calculated-1;

   for(int x=limit;x>=0;x--)
     {
      CopyBuffer(MAHandle,0,x,limit,MABuffer);
      CopyBuffer(BBHandle,0,x,limit,BBBuffer);
     }  
   
     
    for(int i=1; i<rates_total ;i++){
        
        
      if(MABuffer[i]<BBBuffer[i] && MABuffer[i-1]>BBBuffer[i-1]){
         BuyArrow[i]=low[i];
         if(Enable_Alert)
         Alert("Buy Signal "+_Symbol);
         }
         
      if(MABuffer[i]>BBBuffer[i] && MABuffer[i-1]<BBBuffer[i-1]){
         SellArrow[i]=high[i];
         if(Enable_Alert)
         Alert("Sell Signal "+_Symbol);
         }
      }
      
   
   
   
   
   
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }