Wednesday, 26 December 2012

Supertrend of a specific bar using iCustom

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);
  }
//+------------------------------------------------------------------+

==================================================
Use something like this in your EA:

Buff0=iCustom(NULL,0,"Indicator Name",0,0); //Top color of indicator
Buff0=iCustom(NULL,0,"Indicator Name",0,1); //1-Back

Buff1=iCustom(NULL,0,"Indicator Name",1,0); //Next to top color of indicator
Buff1=iCustom(NULL,0,"Indicator Name",1,1); //1-Back

Modify the variables in the indicator itself, and recompile the indicator which will update the buffers and the indicator on the graph!
===================================================


iCustom(NULL,0,"SuperTrend",10,3,0,1) //buffer 0 ie uptrend
 
iCustom(NULL,0,"SuperTrend",10,3,1,1) //buffer 1 ie downtrend

1 comment:

  1. GPS robot tripled the $100k deposit [live proof]

    I just got done with a webinar with Mark and his partner, Antony, two days ago and it was AWESOME.

    During the webinar MARK and ANTONY shared their stories to success and answered questions about their new release of the GPS Forex Robot that CAME OUT TODAY!

    ReplyDelete