Get specific value from indicator through iCustom

 

Dear mql4 forum

I'm currently trying to build my first EA. Everything goes well, except that I am not able to read the values for support red / green trendlines from the indicator (please verify the print-screen)

TrendLines


Even though I can get the current trend with (Trend_TF = variable of desired timeframe)

XtrendDown = iCustom(NULL,Trend_TF,"XSuperTrend",2,1);
XtrendUp = iCustom(NULL,Trend_TF,"XSuperTrend",1,1);

I'm not able to get the trendlines which I plan to use together with the current spread as SL for the trades.

Thank you in Advance.

The code from Xaphod'd indicator is follows:

/*------------------------------------------------------------------------------------
   Name: xSuperTrend.mq4
   Copyright ©2011, Xaphod, http://wwww.xaphod.com
  
   Description: SuperTrend Indicator
             
   Change log:
       2011-11-25. Xaphod, v1.00
          - First Release
-------------------------------------------------------------------------------------*/
// Indicator properties
#property copyright "Copyright © 2010, Xaphod"
#property link      "http://wwww.xaphod.com"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Yellow
#property indicator_color2 FireBrick
#property indicator_color3 Green
#property indicator_width1 1
#property indicator_width2 2
#property indicator_width3 2
#property indicator_style1 STYLE_DOT
#property indicator_maximum 1
#property indicator_minimum 0

// Constant definitions
#define INDICATOR_NAME "xSuperTrend"
#define INDICATOR_VERSION "v1.00, www.xaphod.com"

// Indicator parameters
extern string Version.Info=INDICATOR_VERSION;
extern string SuperTrend.Info="——————————————————————————————";
extern int    SuperTrend.Period=10;      // SuperTrend ATR Period
extern double SuperTrend.Multiplier=1.7; // SuperTrend Multiplier

// Global module varables
double gadUpBuf[];
double gadDnBuf[];
double gadSuperTrend[];


//-----------------------------------------------------------------------------
// function: init()
// Description: Custom indicator initialization function.
//-----------------------------------------------------------------------------
int init() {
   SetIndexStyle(0, DRAW_LINE);
   SetIndexBuffer(0, gadSuperTrend);
   SetIndexLabel(0, "SuperTrend");
   SetIndexStyle(1, DRAW_LINE);
   SetIndexBuffer(1, gadDnBuf);
   SetIndexLabel(1, "SuperTrend Down");
   SetIndexStyle(2, DRAW_LINE);
   SetIndexBuffer(2, gadUpBuf);
   SetIndexLabel(2, "SuperTrend Up");
   IndicatorShortName(INDICATOR_NAME+"["+SuperTrend.Period+";"+DoubleToStr(SuperTrend.Multiplier,1)+"]");
  return(0);
}


//-----------------------------------------------------------------------------
// function: deinit()
// Description: Custom indicator deinitialization function.
//-----------------------------------------------------------------------------
int deinit() {
   return (0);
}


///-----------------------------------------------------------------------------
// function: start()
// Description: Custom indicator iteration function.
//-----------------------------------------------------------------------------
int start() {
  int iNewBars, iCountedBars, i;
  double dAtr,dUpperLevel, dLowerLevel; 
 
  // Get unprocessed ticks
  iCountedBars=IndicatorCounted();
  if(iCountedBars < 0) return (-1);
  if(iCountedBars>0) iCountedBars--;
  iNewBars=Bars-iCountedBars;
 
  for(i=iNewBars; i>=0; i--) {
    // Calc SuperTrend
    dAtr = iATR(NULL, 0, SuperTrend.Period, i);
    dUpperLevel=(High[i]+Low[i])/2+SuperTrend.Multiplier*dAtr;
    dLowerLevel=(High[i]+Low[i])/2-SuperTrend.Multiplier*dAtr;
   
    // Set supertrend levels
    if (Close[i]>gadSuperTrend[i+1] && Close[i+1]<=gadSuperTrend[i+1]) {
      gadSuperTrend[i]=dLowerLevel;
    }
    else if (Close[i]<gadSuperTrend[i+1] && Close[i+1]>=gadSuperTrend[i+1]) {
      gadSuperTrend[i]=dUpperLevel;
    }
    else if (gadSuperTrend[i+1]<dLowerLevel)
        gadSuperTrend[i]=dLowerLevel;
    else if (gadSuperTrend[i+1]>dUpperLevel)
        gadSuperTrend[i]=dUpperLevel;
    else
      gadSuperTrend[i]=gadSuperTrend[i+1];
   
    // Draw SuperTrend lines
    gadUpBuf[i]=EMPTY_VALUE;
    gadDnBuf[i]=EMPTY_VALUE;
    if (Close[i]>gadSuperTrend[i] || (Close[i]==gadSuperTrend[i] && Close[i+1]>gadSuperTrend[i+1]))
      gadUpBuf[i]=gadSuperTrend[i];
    else if (Close[i]<gadSuperTrend[i] || (Close[i]==gadSuperTrend[i] && Close[i+1]<gadSuperTrend[i+1]))
      gadDnBuf[i]=gadSuperTrend[i]; 
  }
 
  return(0);
}
//+------------------------------------------------------------------+
 

In the iCustom call you have to include the external parameters of the indicator.


XtrendDown = iCustom(NULL,Trend_TF,"XSuperTrend", "", "", 10, 1.7, 2,1);

 
szgy74:

In the iCustom call you have to include the external parameters of the indicator.


XtrendDown = iCustom(NULL,Trend_TF,"XSuperTrend", "", "", 10, 1.7, 2,1);

Only if the default values in the Indicator are not suitable . . .
 
RaptorUK:
Only if the default values in the Indicator are not suitable . . .


Thanks RaptorUK


Yes of course. Unfortunately I did not write my question clear enough.

In my opinion this is only necessary if I wanted to changed those parameters in the EA. I do not want them to be changed, so the indicator is using the params from the indicator code itself. -- at least the EA is correctly detecting the correct trend, either bearish or bullish. So this is working as expected.

But my problem is rather to get the values from the support trend line (the red or green vertical lines). They are actually specifying the current stop loss levels of this particular trend. The indicator is writing them to particular values of this particular trend.
I'm getting up and downtrend from buffer 1 and 2, but how can I get the trend (support) line values?

Thank you

 
bobele:

I'm getting up and downtrend from buffer 1 and 2, but how can I get the trend (support) line values?

Buffer 0 ? The best way to determine what you need . . . put the Indicator on a chart and examine it's buffers using the Data Window ( Ctrl + D ) then you can see what buffers you need and what kind of values you can expect . . .
 
RaptorUK:
Buffer 0 ? The best way to determine what you need . . . put the Indicator on a chart and examine it's buffers using the Data Window ( Ctrl + D ) then you can see what buffers you need and what kind of values you can expect . . .


Thanks RaptorUK


Well, it was as usual much easier than I thought. The data windows pointed me to the solution. The opposite buffer has the value for the current support trend line in it. So uptrend has support line for the downtrend and vice versa. I always looked after other buffers than 1 and 2. Thanks again to show me the right direction to the solution!

 
bobele:

Thanks RaptorUK


Well, it was as usual much easier than I thought. The data windows pointed me to the solution. The opposite buffer has the value for the current support trend line in it. So uptrend has support line for the downtrend and vice versa. I always looked after other buffers than 1 and 2. Thanks again to show me the right direction to the solution!

Glad to hear you figured it out
Reason: