How can get trend value of SuperTrend (ahtf + arrows + alerts) button

 

here is indicator code

// modified by banzai
// July 13th, 2020
// not for sale, rent, auction, nor lease
// I copied the code from Mr. Tools. Thank you.

#property copyright "Copyright 2016, mladen - MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//------------------------------------------------------------------
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_color1  clrGreen
#property indicator_color2  clrFireBrick
#property indicator_color3  clrOrange
#property indicator_width1  2
#property indicator_width2  2
#property indicator_width3  2
#property strict

#define _disLin 1
#define _disDot 4

enum enTimeFrames
{
   tf_cu  = PERIOD_CURRENT, // Current time frame
   tf_m1  = PERIOD_M1,      // 1 minute
   tf_m5  = PERIOD_M5,      // 5 minutes
   tf_m15 = PERIOD_M15,     // 15 minutes
   tf_m30 = PERIOD_M30,     // 30 minutes
   tf_h1  = PERIOD_H1,      // 1 hour
   tf_h4  = PERIOD_H4,      // 4 hours
   tf_d1  = PERIOD_D1,      // Daily
   tf_w1  = PERIOD_W1,      // Weekly
   tf_mn1 = PERIOD_MN1,     // Monthly
   tf_n1  = -1,             // First higher time frame
   tf_n2  = -2,             // Second higher time frame
   tf_n3  = -3              // Third higher time frame
};


enum enDisplay
{
   en_lin = _disLin,                  // Display line
   en_lid = _disLin+_disDot,          // Display lines with dots
   en_dot = _disDot                   // Display dots
};

extern enTimeFrames    TimeFrame          = tf_h1;   // Time frame
extern int                period                = 11;                // Super trend period
extern double             multiplier            = 3.0;               // Super trend multiplier
extern enDisplay          DisplayType           = en_lin;            // Display type
extern bool               alertsOn              = false;             // Turn alerts on?
extern bool               alertsOnCurrent       = false;             // Alerts on current (still opened) bar?
extern bool               alertsMessage         = true;              // Alerts should display a message?
extern bool               alertsSound           = false;             // Alerts should play a sound?
extern bool               alertsEmail           = false;             // Alerts should send an email?
extern bool               alertsNotify          = false;             // Alerts should send notification?
extern string             soundFile             = "alert2.wav";      // Sound file
extern bool               ArrowOnFirst          = true;              // Arrow on first bars
extern int                UpArrowSize           = 2;                 // Up Arrow size
extern int                DnArrowSize           = 2;                 // Down Arrow size
extern int                UpArrowCode           = 159;               // Up Arrow code
extern int                DnArrowCode           = 159;               // Down arrow code
extern double             UpArrowGap            = 0.5;               // Up Arrow gap        
extern double             DnArrowGap            = 0.5;               // Dn Arrow gap
extern color              UpArrowColor          = clrGreen;          // Up Arrow Color
extern color              DnArrowColor          = clrOrange;         // Down Arrow Color
extern bool               Interpolate           = true;              // Interpolate in multi time frame mode?

//add the following lines to #define _mtfCall(_buff,_ind) if there are mtf functions
//button_note1,btn_corner,DisplayID,btn_Font,btn_FontSize,btn_text_color,btn_background_color,btn_border_color,button_x,button_y,btn_Width,btn_Height,button_note2,
extern string             button_note1          = "------------------------------";
extern ENUM_BASE_CORNER   btn_corner            = CORNER_LEFT_UPPER; // chart btn_corner for anchoring
input string              DisplayID             = "Trend";              // Display id
extern string             btn_Font              = "Arial";
extern int                btn_FontSize          = 9;                // btn__font size
extern color              btn_text_color        = clrWhite;
extern color              btn_background_color  = clrDimGray;
extern color              btn_border_color      = clrBlack;
extern int                button_x              = 80;               // Horizontal location
extern int                button_y              = 53;                // Vertical location
extern int                btn_Width             = 60;                // btn__width
extern int                btn_Height            = 20;                // btn__height
extern string             button_note2          = "------------------------------";

double Trend[],TrendDoA[],TrendDoB[],Direction[],Up[],Dn[],arrUp[],arrDn[],count[];
string indicatorFileName;
#define _mtfCall(_buff,_y) iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,period,multiplier,DisplayType,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsEmail,alertsNotify,soundFile,ArrowOnFirst,UpArrowSize,DnArrowSize,UpArrowCode,DnArrowCode,UpArrowGap,DnArrowGap,UpArrowColor,DnArrowColor,Interpolate,button_note1,btn_corner,DisplayID,btn_Font,btn_FontSize,btn_text_color,btn_background_color,btn_border_color,button_x,button_y,btn_Width,btn_Height,button_note2,_buff,_y)
//+------------------------------------------------------------------------------------------------------------------+
int OnInit()
{
  if (ObjectFind(DisplayID)!=0)
  {     
         ObjectDelete    (ChartID(),DisplayID);
         ObjectCreate    (ChartID(),DisplayID,OBJ_BUTTON,0,0,0);
         ObjectSetInteger(ChartID(),DisplayID,OBJPROP_COLOR,btn_text_color);
         ObjectSetInteger(ChartID(),DisplayID,OBJPROP_BGCOLOR,btn_background_color);
         ObjectSetInteger(ChartID(),DisplayID,OBJPROP_BORDER_COLOR,btn_background_color);
         ObjectSetInteger(ChartID(),DisplayID,OBJPROP_XSIZE,btn_Width);
         ObjectSetInteger(ChartID(),DisplayID,OBJPROP_YSIZE,btn_Height);
         ObjectSetString (ChartID(),DisplayID,OBJPROP_FONT,btn_Font);
         ObjectSetString (ChartID(),DisplayID,OBJPROP_TEXT,DisplayID);
         ObjectSetInteger(ChartID(),DisplayID,OBJPROP_FONTSIZE,btn_FontSize);
         ObjectSetInteger(ChartID(),DisplayID,OBJPROP_SELECTABLE,false);
         ObjectSetInteger(ChartID(),DisplayID,OBJPROP_CORNER,btn_corner);
         ObjectSetInteger(ChartID(),DisplayID,OBJPROP_HIDDEN,true);
         ObjectSetInteger(ChartID(),DisplayID,OBJPROP_XDISTANCE,9999);
         ObjectSetInteger(ChartID(),DisplayID,OBJPROP_YDISTANCE,9999);
         ObjectSetInteger(ChartID(),DisplayID,OBJPROP_YDISTANCE,button_y);
         ObjectSetInteger(ChartID(),DisplayID,OBJPROP_XDISTANCE,button_x);
         ObjectSetInteger(ChartID(),DisplayID,OBJPROP_STATE,true);
  }
  
      int lstyle = DRAW_LINE;      if ((DisplayType&_disLin)==0) lstyle = DRAW_NONE;
      int astyle = DRAW_ARROW;     if ((DisplayType&_disDot)==0) astyle = DRAW_NONE;
      IndicatorBuffers(9);
      SetIndexBuffer(0, Trend);    SetIndexStyle(0,lstyle);
      SetIndexBuffer(1, TrendDoA); SetIndexStyle(1,lstyle);
      SetIndexBuffer(2, TrendDoB); SetIndexStyle(2,lstyle);
      SetIndexBuffer(3, arrUp);    SetIndexStyle(3,astyle,0,UpArrowSize,UpArrowColor); SetIndexArrow(3,UpArrowCode);
      SetIndexBuffer(4, arrDn);    SetIndexStyle(4,astyle,0,DnArrowSize,DnArrowColor); SetIndexArrow(4,DnArrowCode);
      SetIndexBuffer(5, Direction);
      SetIndexBuffer(6, Up);
      SetIndexBuffer(7, Dn);
      SetIndexBuffer(8, count); 
      indicatorFileName = WindowExpertName();
     TimeFrame         = (enTimeFrames)timeFrameValue(TimeFrame);
      IndicatorShortName(timeFrameToString(TimeFrame)+" SuperTrend");
   
  if (GetButtonState(DisplayID)!="off")
  {
      SetIndexStyle(0,lstyle);
      SetIndexStyle(1,lstyle);
      SetIndexStyle(2,lstyle);
      SetIndexStyle(3,astyle,0,UpArrowSize,UpArrowColor); SetIndexArrow(3,UpArrowCode);
      SetIndexStyle(4,astyle,0,DnArrowSize,DnArrowColor); SetIndexArrow(4,DnArrowCode);
  }
  else for (int mrtools=0; mrtools<5; mrtools++) SetIndexStyle(mrtools,DRAW_NONE);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------------------------------------------------------+
void OnDeinit(const int reason)
{ 
      switch(reason)
      {
         case REASON_PARAMETERS  :
         case REASON_CHARTCHANGE :
         case REASON_RECOMPILE   :
         case REASON_CLOSE       : break;
         default :
         {
            ObjectDelete(DisplayID);
         }                  
      }
}
//+------------------------------------------------------------------------------------------------------------------+
void OnChartEvent(const int id, const long& lparam, const double& dparam, const string& sparam)
{
   static string prevState ="";
   if (id==CHARTEVENT_OBJECT_CLICK && sparam==DisplayID)
   {
      string newState = GetButtonState(DisplayID);
         if (newState!=prevState)
         if (newState=="off")
                  { 
                    for (int mrtools=0; mrtools<5; mrtools++) 
                    SetIndexStyle(mrtools,DRAW_NONE);                  
                    prevState=newState; 
                  }
            else  { 
                    int lstyle = DRAW_LINE;      if ((DisplayType&_disLin)==0) lstyle = DRAW_NONE;
                    int astyle = DRAW_ARROW;     if ((DisplayType&_disDot)==0) astyle = DRAW_NONE;
                    SetIndexStyle(0,lstyle);
                    SetIndexStyle(1,lstyle);
                    SetIndexStyle(2,lstyle);
                    SetIndexStyle(3,astyle,0,UpArrowSize,UpArrowColor); SetIndexArrow(3,UpArrowCode);
                    SetIndexStyle(4,astyle,0,DnArrowSize,DnArrowColor); SetIndexArrow(4,DnArrowCode);
                    prevState=newState; 
                  }
            ObjectSetString(ChartID(),DisplayID,OBJPROP_TEXT,DisplayID);
   }
}  
//+------------------------------------------------------------------------------------------------------------------+
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 i,counted_bars = prev_calculated;
      if(counted_bars < 0) return(-1);
      if(counted_bars > 0) counted_bars--;
         int limit=fmin(rates_total-counted_bars,rates_total-1); count[0] = limit;
         if (TimeFrame!=_Period)
         {
            limit = (int)MathMax(limit,MathMin(rates_total-1,_mtfCall(6,0)*TimeFrame/_Period));
            if (Direction[limit] == -1) CleanPoint(limit,TrendDoA,TrendDoB);
            for (i=limit;i>=0 && !_StopFlag; i--)
            {
               int y = iBarShift(NULL,TimeFrame,Time[i]);
               int x = y;
               if (ArrowOnFirst)
                     {  if (i<Bars-1) x = iBarShift(NULL,TimeFrame,Time[i+1]);               }
               else  {  if (i>0)      x = iBarShift(NULL,TimeFrame,Time[i-1]); else x = -1;  }
                  Trend[i]     = _mtfCall(0,y);
                  Direction[i] = _mtfCall(5,y);
                  Up[i]        = _mtfCall(6,y);
                  Dn[i]        = _mtfCall(7,y);
                  TrendDoA[i]  = EMPTY_VALUE;
                  TrendDoB[i]  = EMPTY_VALUE;
                  arrUp[i]     = EMPTY_VALUE;
                  arrDn[i]     = EMPTY_VALUE;
                  if (x!=y)
                  {
                     arrUp[i]  = _mtfCall(3,y);
                     arrDn[i]  = _mtfCall(4,y);
                  }
      
                  if (!Interpolate || (i>0 && y==iBarShift(NULL,TimeFrame,Time[i-1]))) continue;
                  
                  #define _interpolate(buff) buff[i+k] = buff[i]+(buff[i+n]-buff[i])*k/n
                  int n,k; datetime ttime = iTime(NULL,TimeFrame,y);
                     for(n = 1; (i+n)<rates_total && time[i+n] >= ttime; n++) continue; 
                     for(k = 1; k<n && (i+n)<rates_total && (i+k)<rates_total; k++) 
                     {
                       _interpolate(Trend);  
                       _interpolate(Up);  
                       _interpolate(Dn);     
                     }                     
            }
            for(i=limit; i>=0; i--) if (Direction[i] == -1) PlotPoint(i,TrendDoA,TrendDoB,Trend); 
   return(rates_total);
   }               

   if (Direction[limit] == -1) CleanPoint(limit,TrendDoA,TrendDoB);
   for(i = limit; i >= 0; i--)
   {
      double atr    = iATR(NULL,0,period,i);
      double cprice =  close[i];
      double mprice = (high[i]+low[i])/2;
         Up[i]  = mprice+multiplier*atr;
         Dn[i]  = mprice-multiplier*atr;
         
         Direction[i] = (i<rates_total-1) ? (cprice > Up[i+1]) ? 1 : (cprice < Dn[i+1]) ? -1 : Direction[i+1] : 0;
         TrendDoA[i]  = EMPTY_VALUE;
         TrendDoB[i]  = EMPTY_VALUE;
         arrUp[i]     = EMPTY_VALUE;
         arrDn[i]     = EMPTY_VALUE;
            if (Direction[i] ==  1) { Dn[i] = fmax(Dn[i],Dn[i+1]); Trend[i] = Dn[i]; }
            if (Direction[i] == -1) { Up[i] = fmin(Up[i],Up[i+1]); Trend[i] = Up[i]; PlotPoint(i,TrendDoA,TrendDoB,Trend); }
            if (i<Bars-1 && Direction[i]!= Direction[i+1])
            {
              if (Direction[i] ==  1) arrUp[i] = fmin(Trend[i],Low[i] )-iATR(NULL,0,15,i)*UpArrowGap;
              if (Direction[i] == -1) arrDn[i] = fmax(Trend[i],High[i])+iATR(NULL,0,15,i)*DnArrowGap;
            }
   }
   if (alertsOn)
   {
      int whichBar = 1; if (alertsOnCurrent) whichBar = 0; 
      if (Direction[whichBar] != Direction[whichBar+1])
      if (Direction[whichBar] == 1)
               doAlert(" up");
         else  doAlert(" down");       
   }
return(rates_total);
}
//+------------------------------------------------------------------+
void CleanPoint(int i,double& first[],double& second[])
{
   if (i>Bars-2) return;
   if ((second[i]  != EMPTY_VALUE) && (second[i+1] != EMPTY_VALUE))
        second[i+1] = EMPTY_VALUE;
   else
      if ((first[i] != EMPTY_VALUE) && (first[i+1] != EMPTY_VALUE) && (first[i+2] == EMPTY_VALUE))
          first[i+1] = EMPTY_VALUE;
}
//+------------------------------------------------------------------+
void PlotPoint(int i,double& first[],double& second[],double& from[])
{
   if (i>Bars-3) return;
   if (first[i+1] == EMPTY_VALUE)
         if (first[i+2] == EMPTY_VALUE) 
               { first[i]  = from[i]; first[i+1]  = from[i+1]; second[i] = EMPTY_VALUE; }
         else  { second[i] = from[i]; second[i+1] = from[i+1]; first[i]  = EMPTY_VALUE; }
   else        { first[i]  = from[i];                          second[i] = EMPTY_VALUE; }
}
//+------------------------------------------------------------------+
string sTfTable[] = {"M1","M5","M15","M30","H1","H4","D1","W1","MN"};
int    iTfTable[] = {1,5,15,30,60,240,1440,10080,43200};

string timeFrameToString(int tf)
{
   for (int i=ArraySize(iTfTable)-1; i>=0; i--) 
         if (tf==iTfTable[i]) return(sTfTable[i]);
                              return("");
}
int timeFrameValue(int _tf)
{
   int add  = (_tf>=0) ? 0 : MathAbs(_tf);
   if (add != 0) _tf = _Period;
   int size = ArraySize(iTfTable); 
      int i =0; for (;i<size; i++) if (iTfTable[i]==_tf) break;
                                   if (i==size) return(_Period);
                                                return(iTfTable[(int)MathMin(i+add,size-1)]);
}
//+------------------------------------------------------------------+
void doAlert(string doWhat)
{
   static string   previousAlert="nothing";
   static datetime previousTime;
   string message;
   
      if (previousAlert != doWhat || previousTime != Time[0]) {
          previousAlert  = doWhat;
          previousTime   = Time[0];

          message =  StringConcatenate(Symbol()," ",timeFrameToString(_Period)," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," SuperTrend ",doWhat);
             if (alertsMessage) Alert(message);
             if (alertsNotify)  SendNotification(message);
             if (alertsEmail)   SendMail(_Symbol+" SuperTrend ",message);
             if (alertsSound)   PlaySound(soundFile);
      }
}
//+------------------------------------------------------------------------------------------------------------------+
string GetButtonState(string whichbutton)
{
      bool selected = ObjectGetInteger(ChartID(),whichbutton,OBJPROP_STATE);
      if (selected)
           { return ("on"); } 
      else { return ("off");}
}
//+------------------------------------------------------------------------------------------------------------------+

here is indicator photo

I try to get red trend line value and green trend line value

  double trendup = iCustom(Symbol(),0,"SuperTrend (ahtf + arrows + alerts) button",period,multiplier,1,1);
   double trenddn = iCustom(Symbol(),0,"SuperTrend (ahtf + arrows + alerts) button",period,multiplier,2,1);

   Print("uppp" +trendup+"");
    Print("dnn" +trenddn+"");
   

in real running,

when red trend line appear , trend down value is as follow

dnn 2147483647


when green trend line appear , trend up value is


uppp 2147483647


no order open

 double trendup = iCustom(Symbol(),0,"ss",period,multiplier,1,1);
   double trenddn = iCustom(Symbol(),0,"ss",period,multiplier,2,1);
   Print("uppp" +trendup+"");
    Print("dnn" +trenddn+"");
   
   if( trenddn !=EMPTY_VALUE ) return (sell);

How can get correct value this red and green trendline

thanks

 
LONNV: I try to get red trend line value and green trend line value

  double trendup = iCustom(Symbol(),0,"SuperTrend (ahtf + arrows + alerts) button",period,multiplier,1,1);
   double trenddn = iCustom(Symbol(),0,"SuperTrend (ahtf + arrows + alerts) button",period,multiplier,2,1);


#property indicator_color1  clrGreen
#property indicator_color2  clrFireBrick
#property indicator_color3  clrOrange

Green is buffer index zero. Red is buffer index one. You are reading one and two.

 
LONNV:

here is indicator code

here is indicator photo

I try to get red trend line value and green trend line value

in real running,

when red trend line appear , trend down value is as follow

dnn 2147483647


when green trend line appear , trend up value is


uppp 2147483647


no order open

How can get correct value this red and green trendline

thanks

//very simple
if(dnn!=2147483647 && dnn>0) Alert("SELL");

if(uppp!=2147483647 && uppp>0) Alert("BUY");