//+------------------------------------------------------------------+
//|                             Beast Super Signal MTF Extension.mq4 |
//|                               Copyright 2024, Explosionkibo @ FF |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, Explosionkibo @ FF"
#property description "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
#property description "  Note: In order to use this indicator extension,"
#property description "  the source indicator file: Beast Super Signal.ex4"
#property description "  must be available in the mt4 indicator folder!"
#property description "  To prevent high cpu usage/slow calculations on "
#property description "  higher time frames, input parameter"
#property description "  'Max Look Back Bars', should be low enough!"
#property description "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
#property strict
#property indicator_buffers 2
#property indicator_chart_window

enum x         // Time Frame
     {
     t00,      // Current
     t01,      // M1
     t02,      // M5
     t03,      // M15
     t04,      // M30
     t05,      // H1
     t06,      // H4
     t07,      // 1D
     t08,      // 1W
     t09,      // 1MN
     t10       // Renko OffLine Charts
     };

extern int                 mlb                     =  1000;                       // Max Look Back Bars
extern x                   TF                      =  t00;                        // Time Frame
extern int                 rtf                     =  3;                          // Renko Offline Chart Time Frame
extern string              SIN                     =  "Beast Super Signal";       // Source Indicator File Name
extern int                 sdep                    =  60;                         // Signal Depth
extern int                 sdev                    =  5;                          // Signal Deviation
extern int                 sbac                    =  3;                          // Signal Backstep
extern int                 stlen                   =  7;                          // Stochastic Length
extern double              stfil                   =  0.0;                        // Stochastic Filter
extern double              stobl                   =  70.0;                       // Stochastic Overbought Level
extern double              stosl                   =  30.0;                       // Stochastic Oversold Level
extern int                 mtlp                    =  10;                         // MA Trend Line Period
extern ENUM_MA_METHOD      malm                    =  MODE_SMA;                   // MA Line Method
extern ENUM_APPLIED_PRICE  mtap                    =  PRICE_CLOSE;                // MA Trend Line Applied Price
extern int                 map                     =  15;                         // MA Period
extern int                 mas                     =  0;                          // MA Shift
extern ENUM_MA_METHOD      mam                     =  MODE_SMA;                   // MA Method
extern ENUM_APPLIED_PRICE  maap                    =  0;                          // MA Applied Price
extern bool                mao                     =  true;                       // Message Alert ON?
extern bool                pnao                    =  false;                      // Push Notification Alert ON?
extern bool                eao                     =  false;                      // Email Alert ON?
extern int                 adis                    =  50;                         // Buy/Sell Arrow Distance
extern color               bac                     =  clrYellowGreen;             // Buy Arrow Color
extern color               sac                     =  clrRed;                     // Sell Arrow Color
extern int                 bacode                  =  217;                        // Buy Arrow Code
extern int                 sacode                  =  218;                        // Sell Arrow Code
extern int                 bsas                    =  2;                          // Buy/Sell Arrow Size

double buy[],sell[];
int    limit,i,tf;
        
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
   int OnInit(){
   IndicatorBuffers  (02);
   SetIndexBuffer    (00,buy);
   SetIndexStyle     (00,DRAW_ARROW,EMPTY,bsas,bac);
   SetIndexLabel     (00,"Buy Arrow: ("+IntegerToString(sdep,0)+")@(M"+IntegerToString(Period())+")");
   SetIndexArrow     (00,bacode);
   SetIndexBuffer    (01,sell);
   SetIndexStyle     (01,DRAW_ARROW,EMPTY,bsas,sac);
   SetIndexLabel     (01,"Sell Arrow: ("+IntegerToString(sdep,0)+")@(M"+IntegerToString(Period())+")");
   SetIndexArrow     (01,sacode);
           
   IndicatorShortName("Beast Super Signal MTF Extension");
  
   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      [])
   {limit = rates_total - prev_calculated;
   ArraySetAsSeries(buy,         true);         ArraySetAsSeries(sell,         true);
   if(prev_calculated < 1){
   ArrayInitialize(buy,          EMPTY_VALUE);  ArrayInitialize(sell,          EMPTY_VALUE);}
   
   if(TF==00)tf=PERIOD_CURRENT;else if(TF==01)tf=PERIOD_M1;     else if(TF==02)tf=PERIOD_M5;else if(TF==03)tf=PERIOD_M15; else 
   if(TF==04)tf=PERIOD_M30;    else if(TF==05)tf=PERIOD_H1;     else if(TF==06)tf=PERIOD_H4;else if(TF==07)tf=PERIOD_D1;  else 
   if(TF==08)tf=PERIOD_W1;     else if(TF==09)tf=PERIOD_MN1;    else if(TF==10)tf=rtf;
      
   for(i = Bars-2; i >= 0; i--){
   if (i >= MathMin(mlb, rates_total-sdep))        continue;
   int y = iBarShift(Symbol(),tf,Time[i]); if(y<0) continue;
    
   double b=iCustom(Symbol(),tf,"Beast Super Signal",sdep,sdev,sbac,stlen,stfil,stobl,stosl,mtlp,malm,mtap,map,mas,mam,maap,mao,pnao,eao,adis,0,y);
   double s=iCustom(Symbol(),tf,"Beast Super Signal",sdep,sdev,sbac,stlen,stfil,stobl,stosl,mtlp,malm,mtap,map,mas,mam,maap,mao,pnao,eao,adis,1,y);
   if(b!=EMPTY_VALUE) buy[i] =b; else buy[i] =EMPTY_VALUE;
   if(s!=EMPTY_VALUE) sell[i]=s; else sell[i]=EMPTY_VALUE;}
     
   return(rates_total);}
   
//+------------------------------------------------------------------+