//------------------------------------------------------------------
#property link      "https://howtofxmarkets.web.app/"
#property copyright "https://howtofxmarkets.web.app/ IchimokuAveragesMomentum by csj179t"
//   - Forex education, mentorship, trading rooms.
//   - Low cost forex broker, high leverage available. With a lot of FREE additional services.
//   - And a Guide-o-FX is a list of FREE useful forex resources.
//------------------------------------------------------------------
#property copyright "www.forex-station.com"
// Many thanks to forex-station.com, to mrtools, mladen
// and other coder helping for free. Special thanks to Jimmy! 
// I got this code template at forex-station:  bars iterator, mtf feature...
// And making my indicators, by editing modifying it.


#property indicator_separate_window
#property indicator_buffers    3

#property indicator_level3    100
#property indicator_levelcolor clrWhite
#property indicator_levelstyle STYLE_DOT

extern ENUM_TIMEFRAMES    TimeFrame       = PERIOD_CURRENT;
extern int          tenkan_sen   = 9;
extern  int          kijun_sen       =26;
extern  int          senkou_span_b    =52;
extern int            Momentum =          50;
extern bool showIchiMa = true;
extern color             IchiMaCol = clrYellow;
extern bool showTenKijMa = true;
extern color             TenKijMaCol = clrLime;
extern bool showSenMa = true;
extern color             SenMaCol = clrRed;
extern bool               Interpolate   = true;

extern string             name = "IchimokuAveragesMomentum";


double buffer1[];
double buffer2[];
double buffer3[];

double buffer4[];
double buffer5[];
double buffer6[];

string indicatorFileName;
bool   returnBars;

string name2 = name + " " + TimeFrame;



//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
  {

   IndicatorBuffers(6);
   SetIndexBuffer(0,buffer1);
   SetIndexStyle(0,DRAW_LINE,0,2,IchiMaCol);
   SetIndexBuffer(1,buffer2);
   SetIndexStyle(1,DRAW_LINE,0,2,TenKijMaCol);
   SetIndexBuffer(2,buffer3);
   SetIndexStyle(2,DRAW_LINE,0,2,SenMaCol);
   SetIndexBuffer(3,buffer4);
   SetIndexBuffer(4,buffer5);
   SetIndexBuffer(5,buffer6);

   indicatorFileName = WindowExpertName();
   returnBars        = TimeFrame==-99;
   TimeFrame         = fmax(TimeFrame,_Period);

   IndicatorShortName(name2);

   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit()
  {



   return(0);

  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {




   int counted_bars=IndicatorCounted();
   int i,limit;


   if(counted_bars < 0)
      return(-1);
   if(counted_bars > 0)
      counted_bars--;
   limit = MathMin(Bars-counted_bars,Bars-1);
   if(returnBars)
     {
      buffer1[0] = limit+1;
      return(0);
     }


   if(TimeFrame == Period())
     {

      for(i=limit; i>=0; i--)
        {
         if(showIchiMa)
            buffer4[i] = (iIchimoku(NULL,0,tenkan_sen,kijun_sen,senkou_span_b,3,i) + iIchimoku(NULL,0,tenkan_sen,kijun_sen,senkou_span_b,4,i) + iIchimoku(NULL,0,tenkan_sen,kijun_sen,senkou_span_b,1,i) + iIchimoku(NULL,0,tenkan_sen,kijun_sen,senkou_span_b,2,i)   + Close[i+25])/5;
         if(showTenKijMa)
            buffer5[i] = (iIchimoku(NULL,0,tenkan_sen,kijun_sen,senkou_span_b,1,i) + iIchimoku(NULL,0,tenkan_sen,kijun_sen,senkou_span_b,2,i))/2;
         if(showSenMa)
            buffer6[i] = (iIchimoku(NULL,0,tenkan_sen,kijun_sen,senkou_span_b,3,i) + iIchimoku(NULL,0,tenkan_sen,kijun_sen,senkou_span_b,4,i))/2;

         if(showIchiMa)
            buffer1[i] = iMomentumOnArray(buffer4,0,Momentum,i);
         if(showTenKijMa)
            buffer2[i] = iMomentumOnArray(buffer5,0,Momentum,i);
         if(showSenMa)
            buffer3[i] = iMomentumOnArray(buffer6,0,Momentum,i);

        }

      return(0);
     }


   limit = MathMax(limit,MathMin(Bars-1,iCustom(NULL,TimeFrame,indicatorFileName,-99,0,0)*TimeFrame/Period()));
   for(i=limit; i>=0; i--)
     {
      int y = iBarShift(NULL,TimeFrame,Time[i]);

      buffer1[i] = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,tenkan_sen,kijun_sen,senkou_span_b,Momentum,showIchiMa,IchiMaCol,showTenKijMa,TenKijMaCol,showSenMa,SenMaCol,0,y);
      buffer2[i] = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,tenkan_sen,kijun_sen,senkou_span_b,Momentum,showIchiMa,IchiMaCol,showTenKijMa,TenKijMaCol,showSenMa,SenMaCol,1,y);
      buffer3[i] = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,tenkan_sen,kijun_sen,senkou_span_b,Momentum,showIchiMa,IchiMaCol,showTenKijMa,TenKijMaCol,showSenMa,SenMaCol,2,y);
      //
      //
      //
      //
      //

      if(!Interpolate || y==iBarShift(NULL,TimeFrame,Time[i-1]))
         continue;

      //
      //
      //
      //
      //

      datetime time = iTime(NULL,TimeFrame,y);
      for(int n = 1; i+n < Bars && Time[i+n] >= time; n++)
         continue;
      for(int x = 1; x < n; x++)
        {


         buffer1[i+x] = buffer1[i] + (buffer1[i+n] - buffer1[i]) * x/n;

         buffer2[i+x] = buffer2[i] + (buffer2[i+n] - buffer2[i]) * x/n;
         buffer3[i+x] = buffer3[i] + (buffer3[i+n] - buffer3[i]) * x/n;




        }
     }







   return(0);
  }



//+------------------------------------------------------------------+
