View Single Post
  #2 (permalink)  
Old 11-10-2005, 12:42 AM
codersguru's Avatar
codersguru codersguru is offline
Senior Member
 
Join Date: Oct 2005
Posts: 987
codersguru has a spectacular aura aboutcodersguru has a spectacular aura aboutcodersguru has a spectacular aura about
Arrow The magic of iCustom() function.

Quote:
Originally Posted by homicida
hi there

first i must say really lots of helpfull info on the board here its great

next my question

how do i get the indicatorresult (or other variable) as a returnvalue if i call it with icustom ?

i tryed to analyze the code of some other indicators for that part but... theres no difference (or i missed it ).

so how does it work?

greets homi
Hi homi,

Let’s assume we want to return the value of the indicator “Supertrend” of a specific bar using iCustom.

If we want to get the returned value of the Supertrend first line:
We can write this price of code inside start() function:

Code:
double val=iCustom(NULL, 0, "SuperTrend",0,0,pos);
Here val will hold the returned value of Supertrend indicator(first line).

If you want the returned value of the second line, we can write:

Code:
double val=iCustom(NULL, 0, "SuperTrend",0,1,pos);
This is a program which will use Supertrend indicator using iCustom:


Code:
#property copyright "Coders Guru"
#property link      "http://www.forex-tsd.com"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }


int start()
  {
   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--;
   
   int pos=Bars-counted_bars;
   
     
 
   while(pos>=0)
     {
         ExtMapBuffer1[pos] = iCustom(NULL, 0, "SuperTrend",0,0,pos);
         ExtMapBuffer2[pos] = iCustom(NULL, 0, "SuperTrend",0,1,pos);

         pos--;
     }
     
     
     
//----
   return(0);
  }
//+------------------------------------------------------------------+
__________________
Hope it helps !
Coders' Guru
Senior MQL programmer:
www.xpworx.com/custom.htm
Reply With Quote