how can I read this Line? no Buffer given

 

For example only Long

PLS SEE ATTACHED PICTURE TO UNDERSTAND MY PROBLEM

1.Indicator shows BullishDivergence: Bullish Arrow (Green)

  -THIS IS THE ENDPOINT OF THE DIVERGENCE

2.Indicator has now a line which goes from Endpoint (BullishDivergence Arrow (Green))

   TO A STARTPOINT (DIVERGENCE LINE GREEN)

My Question

I can read the arrow cause it is easy it has Buffer in this case its Buffer 3 of the indicator

But what is the Buffer of this line??? And how can I read it?

My Code and Try:

//---
   //counting Bars
   int counted_bars, limit;
   counted_bars=IndicatorCounted();
   limit=Bars-counted_bars;
   //Loop
   for(int i=0;i<5;i++){
      //initizilation of indicator (Traditional Macd Histogram Divergence Endpoint check)
      double macdBullishDivergence = iCustom(NULL, PERIOD_CURRENT, "Traditional Macd Histogram Divergence", "*** MACD Settings ***", 12, 26, 9, "*** Indicator Settings ***", true, true, true, 3, i);
      double macdBearishDivergence = iCustom(NULL, PERIOD_CURRENT, "Traditional Macd Histogram Divergence", "*** MACD Settings ***", 12, 26, 9, "*** Indicator Settings ***", true, true, true, 4, i);
         //initizilation of upArrow signal
         if(macdBullishDivergence != EMPTY_VALUE){
            //marking Divergence endpoint
            endPoint[i]=Low[i]-1.5*myPoint;
            //saving Bar index
            int currentCloseIndex = int(Close[i]);
            
            
            for(int j=currentCloseIndex;j<50;j++){
            //initizilation of indicator (Traditional Macd Histogram Divergence Startpoint check)
            double macdBullishDivergence = iCustom(NULL, PERIOD_CURRENT, "Traditional Macd Histogram Divergence", "*** MACD Settings ***", 12, 26, 9, "*** Indicator Settings ***", true, true, true, 3, j);
            double macdBearishDivergence = iCustom(NULL, PERIOD_CURRENT, "Traditional Macd Histogram Divergence", "*** MACD Settings ***", 12, 26, 9, "*** Indicator Settings ***", true, true, true, 4, j);
            //initizilation of upArrow signal
               if(macdBullishDivergence != EMPTY_VALUE){
                  startPoint[j]=Low[j]-1.5*myPoint;
               }
            }
          //initizilation of downArrow signal
         }
         }
//--- return value of prev_calculated for next call
   return(rates_total);
}
//+----------------------------------------------------------------+


Indicator code:

#property indicator_separate_window
#property indicator_buffers 5
#property indicator_color1 Silver
#property indicator_color2 DodgerBlue
#property indicator_color3 Red
#property indicator_color4 Lime
#property indicator_color5 Red
#property indicator_width1 2
#property indicator_level1 0
//----
#define arrowsDisplacement 0.0001
//---- input parameters
extern string separator1 = "*** MACD Settings ***";
extern int FastMAPeriod = 12;
extern int SlowMAPeriod = 26;
extern int SignalMAPeriod = 9;
extern string separator2 = "*** Indicator Settings ***";
extern bool   drawIndicatorTrendLines = true;
extern bool   drawPriceTrendLines = true;
extern bool   displayAlert = true;
//---- buffers
double MACDLineBuffer[];
double SignalLineBuffer[];
double HistogramBuffer[];
double bullishDivergence[]; //BullishArrow
double bearishDivergence[]; //BearishArrow
//---- variables
double alpha = 0;
double alpha_1 = 0;
//----
static datetime lastAlertTime;
static string   indicatorName;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   IndicatorDigits(Digits + 1);
   //---- indicators
   SetIndexBuffer(0, HistogramBuffer);
   SetIndexDrawBegin(0, SlowMAPeriod + SignalMAPeriod);
   SetIndexStyle(0, DRAW_HISTOGRAM);
   SetIndexDrawBegin(1, SlowMAPeriod);
   SetIndexBuffer(1, MACDLineBuffer);
   SetIndexDrawBegin(2, SlowMAPeriod + SignalMAPeriod);
   SetIndexBuffer(2, SignalLineBuffer);
   SetIndexStyle(3, DRAW_ARROW);
   SetIndexArrow(3, 233);
   SetIndexBuffer(3, bullishDivergence);
   SetIndexStyle(4, DRAW_ARROW);
   SetIndexArrow(4, 234);
   SetIndexBuffer(4, bearishDivergence);
   //---- name for DataWindow and indicator subwindow label
   indicatorName =("MACD(" + FastMAPeriod+"," + SlowMAPeriod + "," + SignalMAPeriod + ")");
   SetIndexLabel(2, "MACD");
   SetIndexLabel(3, "Signal");
   SetIndexLabel(4, "Histogr");
   IndicatorShortName(indicatorName);  
   //----
          alpha = 2.0 / (SignalMAPeriod + 1.0);
          alpha_1 = 1.0 - alpha;
   //----
   return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   for(int i = ObjectsTotal() - 1; i >= 0; i--)
     {
       string label = ObjectName(i);
       if(StringSubstr(label, 0, 19) != "MACD_DivergenceLine")
           continue;
       ObjectDelete(label);   
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars = IndicatorCounted();
   //---- check for possible errors
   if(counted_bars < 0) 
       return(-1);
   //---- last counted bar will be recounted
   if(counted_bars > 0) 
       counted_bars--;
   limit = Bars - counted_bars;
   CalculateIndicator(counted_bars);
//----
   for(int i = limit; i >= 0; i--)
     {
       MACDLineBuffer[i] = iMA(NULL, 0, FastMAPeriod, 0, MODE_EMA, PRICE_CLOSE, i) - 
                           iMA(NULL, 0, SlowMAPeriod, 0, MODE_EMA, PRICE_CLOSE, i);
       SignalLineBuffer[i] = alpha*MACDLineBuffer[i] + alpha_1*SignalLineBuffer[i+1];
       HistogramBuffer[i] = MACDLineBuffer[i] - SignalLineBuffer[i];
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void CalculateIndicator(int countedBars)
  {
   for(int i = Bars - countedBars; i >= 0; i--)
     {
       CalculateMACD(i);
       CatchBullishDivergence(i + 2);
       CatchBearishDivergence(i + 2);
     }              
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void CalculateMACD(int i)
  {
   MACDLineBuffer[i] = iMA(NULL, 0, FastMAPeriod, 0, MODE_EMA, PRICE_CLOSE, i) - 
                       iMA(NULL, 0, SlowMAPeriod, 0, MODE_EMA, PRICE_CLOSE, i);
   SignalLineBuffer[i] = alpha*MACDLineBuffer[i] + alpha_1*SignalLineBuffer[i+1];
   HistogramBuffer[i] = MACDLineBuffer[i] - SignalLineBuffer[i];      
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void CatchBullishDivergence(int shift)
  {
   if(IsIndicatorTrough(shift) == false)
       return;  
   int currentTrough = shift;
   int lastTrough = GetIndicatorLastTrough(shift);
//----   
   if(MACDLineBuffer[currentTrough] > MACDLineBuffer[lastTrough] && 
      Low[currentTrough] < Low[lastTrough])
     {
       bullishDivergence[currentTrough] = MACDLineBuffer[currentTrough] - 
                                          arrowsDisplacement;
       //----
       if(drawPriceTrendLines == true)
           DrawPriceTrendLine(Time[currentTrough], Time[lastTrough], 
                              Low[currentTrough], 
                             Low[lastTrough], Lime, STYLE_SOLID);
       //----
       if(drawIndicatorTrendLines == true)
          DrawIndicatorTrendLine(Time[currentTrough], 
                                 Time[lastTrough], 
                                 MACDLineBuffer[currentTrough],
                                 MACDLineBuffer[lastTrough], 
                                 Lime, STYLE_SOLID);
       //----
       if(displayAlert == true)
          DisplayAlert("Classical bullish divergence on: ", 
                        currentTrough);  
     }
//----   
   if(MACDLineBuffer[currentTrough] < MACDLineBuffer[lastTrough] && 
      Low[currentTrough] > Low[lastTrough])
     {
       bullishDivergence[currentTrough] = MACDLineBuffer[currentTrough] - 
                                          arrowsDisplacement;
       //----
       if(drawPriceTrendLines == true)
           DrawPriceTrendLine(Time[currentTrough], Time[lastTrough], 
                              Low[currentTrough], 
                              Low[lastTrough], Lime, STYLE_DOT);
       //----
       if(drawIndicatorTrendLines == true)                            
           DrawIndicatorTrendLine(Time[currentTrough], 
                                  Time[lastTrough], 
                                  MACDLineBuffer[currentTrough],
                                  MACDLineBuffer[lastTrough], 
                                  Lime, STYLE_DOT);
       //----
       if(displayAlert == true)
           DisplayAlert("Reverse bullish divergence on: ", 
                        currentTrough);   
     }      
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void CatchBearishDivergence(int shift)
  {
   if(IsIndicatorPeak(shift) == false)
       return;
   int currentPeak = shift;
   int lastPeak = GetIndicatorLastPeak(shift);
//----   
   if(MACDLineBuffer[currentPeak] < MACDLineBuffer[lastPeak] && 
      High[currentPeak] > High[lastPeak])
     {
       bearishDivergence[currentPeak] = MACDLineBuffer[currentPeak] + 
                                        arrowsDisplacement;
      
       if(drawPriceTrendLines == true)
           DrawPriceTrendLine(Time[currentPeak], Time[lastPeak], 
                              High[currentPeak], 
                              High[lastPeak], Red, STYLE_SOLID);
                            
       if(drawIndicatorTrendLines == true)
           DrawIndicatorTrendLine(Time[currentPeak], Time[lastPeak], 
                                  MACDLineBuffer[currentPeak],
                                  MACDLineBuffer[lastPeak], Red, STYLE_SOLID);

       if(displayAlert == true)
           DisplayAlert("Classical bearish divergence on: ", 
                        currentPeak);  
     }
   if(MACDLineBuffer[currentPeak] > MACDLineBuffer[lastPeak] && 
      High[currentPeak] < High[lastPeak])
     {
       bearishDivergence[currentPeak] = MACDLineBuffer[currentPeak] + 
                                        arrowsDisplacement;
       //----
       if(drawPriceTrendLines == true)
           DrawPriceTrendLine(Time[currentPeak], Time[lastPeak], 
                              High[currentPeak], 
                              High[lastPeak], Red, STYLE_DOT);
       //----
       if(drawIndicatorTrendLines == true)
           DrawIndicatorTrendLine(Time[currentPeak], Time[lastPeak], 
                                  MACDLineBuffer[currentPeak],
                                  MACDLineBuffer[lastPeak], Red, STYLE_DOT);
       //----
       if(displayAlert == true)
           DisplayAlert("Reverse bearish divergence on: ", 
                        currentPeak);   
     }   
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool IsIndicatorPeak(int shift)
  {
   if(MACDLineBuffer[shift] >= MACDLineBuffer[shift+1] && MACDLineBuffer[shift] > MACDLineBuffer[shift+2] && 
      MACDLineBuffer[shift] > MACDLineBuffer[shift-1])
       return(true);
   else 
       return(false);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool IsIndicatorTrough(int shift)
  {
   if(MACDLineBuffer[shift] <= MACDLineBuffer[shift+1] && MACDLineBuffer[shift] < MACDLineBuffer[shift+2] && 
      MACDLineBuffer[shift] < MACDLineBuffer[shift-1])
       return(true);
   else 
       return(false);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int GetIndicatorLastPeak(int shift)
  {
   for(int i = shift + 5; i < Bars; i++)
     {
       if(SignalLineBuffer[i] >= SignalLineBuffer[i+1] && SignalLineBuffer[i] >= SignalLineBuffer[i+2] &&
          SignalLineBuffer[i] >= SignalLineBuffer[i-1] && SignalLineBuffer[i] >= SignalLineBuffer[i-2])
         {
           for(int j = i; j < Bars; j++)
             {
               if(MACDLineBuffer[j] >= MACDLineBuffer[j+1] && MACDLineBuffer[j] > MACDLineBuffer[j+2] &&
                  MACDLineBuffer[j] >= MACDLineBuffer[j-1] && MACDLineBuffer[j] > MACDLineBuffer[j-2])
                   return(j);
             }
         }
     }
   return(-1);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int GetIndicatorLastTrough(int shift)
  {
    for(int i = shift + 5; i < Bars; i++)
      {
        if(SignalLineBuffer[i] <= SignalLineBuffer[i+1] && SignalLineBuffer[i] <= SignalLineBuffer[i+2] &&
           SignalLineBuffer[i] <= SignalLineBuffer[i-1] && SignalLineBuffer[i] <= SignalLineBuffer[i-2])
          {
            for (int j = i; j < Bars; j++)
              {
                if(MACDLineBuffer[j] <= MACDLineBuffer[j+1] && MACDLineBuffer[j] < MACDLineBuffer[j+2] &&
                   MACDLineBuffer[j] <= MACDLineBuffer[j-1] && MACDLineBuffer[j] < MACDLineBuffer[j-2])
                    return(j);
              }
          }
      }
    return(-1);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void DisplayAlert(string message, int shift)
  {
   if(shift <= 2 && Time[shift] != lastAlertTime)
     {
       lastAlertTime = Time[shift];
       Alert(message, Symbol(), " , ", Period(), " minutes chart");
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void DrawPriceTrendLine(datetime x1, datetime x2, double y1, 
                        double y2, color lineColor, double style)
  {
   string label = "MACD_DivergenceLine.0# " + DoubleToStr(x1, 0);
   ObjectDelete(label);
   ObjectCreate(label, OBJ_TREND, 0, x1, y1, x2, y2, 0, 0);
   ObjectSet(label, OBJPROP_RAY, 0);
   ObjectSet(label, OBJPROP_COLOR, lineColor);
   ObjectSet(label, OBJPROP_STYLE, style);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void DrawIndicatorTrendLine(datetime x1, datetime x2, double y1, 
                            double y2, color lineColor, double style)
  {
   int indicatorWindow = WindowFind(indicatorName);
   if(indicatorWindow < 0)
       return;
   string label = "MACD_DivergenceLine.0$# " + DoubleToStr(x1, 0);
   ObjectDelete(label);
   ObjectCreate(label, OBJ_TREND, indicatorWindow, x1, y1, x2, y2, 
                0, 0);
   ObjectSet(label, OBJPROP_RAY, 0);
   ObjectSet(label, OBJPROP_COLOR, lineColor);
   ObjectSet(label, OBJPROP_STYLE, style);
  }
//+------------------------------------------------------------------+


Documentation on MQL5: Common Functions / TesterHideIndicators
Documentation on MQL5: Common Functions / TesterHideIndicators
  • www.mql5.com
TesterHideIndicators - Common Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Files:
example-1.jpeg  69 kb
 
noSkill06s:

For example only Long

PLS SEE ATTACHED PICTURE TO UNDERSTAND MY PROBLEM

1.Indicator shows BullishDivergence: Bullish Arrow (Green)

  -THIS IS THE ENDPOINT OF THE DIVERGENCE

2.Indicator has now a line which goes from Endpoint (BullishDivergence Arrow (Green))

   TO A STARTPOINT (DIVERGENCE LINE GREEN)

My Question

I can read the arrow cause it is easy it has Buffer in this case its Buffer 3 of the indicator

But what is the Buffer of this line??? And how can I read it?

My Code and Try:


Indicator code:


That line is NOT on any buffer. That line is an OBJ_TREND 

an OBJ_TREND is a kind of line you can use to draw diagonals line along any part of the chart. You passa 2 PRICE coordinates to the OBJ_TREND, or other Value which represents the Scale of the indicator or main chart.

Than OBJ_TREND creates an object LINE connecting those 2 points and this is the Green Line that you see there.


You can get, however, obtain the 2 coordination points that were passed to it. Those values are on some other buffer, which is as easy to read as the buffer3 containing the values for the arrow. 

But intermediate values, which represents the path of the grren line between BEGIN and END points, does not exist at all, if you need it you will need to calculate the DIAGONAL using mathematics, considering you have the 2 essencial points, which is Begin and End, and you have a known vertical scale, so is the same an exercise on college to calculate a triangle diagonal by having a measure of the vertical scale + 2 reference points on any square  


For the Chart Green OBJ_TREND, ir receives 4 values: The First candle Value (which is the time of the candle) + the Price Value, which is the vertical point of the Candle (This becomes POINT1)

Than 2 more values: The Second candle + the Price on the candle. (This becomes POINT 2)


and OBJ_TREND connects those 2 points, making a diagonal line.


You can mathematically, calculate a triangle, because you have BASE + HIGH values.

Then it is easy to calculate a triangle diagonal using simple formulas, and once you do it, you will be able to know any intermediate values of the diagonal, since any point of the diagonal are just references to the Base Scale and High Scale of the triangle 





obj_trend MQL4


obj_trend MQL5

OBJ_TREND - Object Types - Objects Constants - Constants, Enumerations and Structures - MQL4 Reference
OBJ_TREND - Object Types - Objects Constants - Constants, Enumerations and Structures - MQL4 Reference
  • docs.mql4.com
OBJ_TREND - Object Types - Objects Constants - Constants, Enumerations and Structures - MQL4 Reference
 
noSkill06s:


Topics concerning MT4 and MQL4 have their own section.

In future please post in the correct section.

I have moved your topic to the MQL4 and Metatrader 4 section.