This is taken from the Coder's guru course. Instead of plotting the indicator in a seperate window, I want to plot the indicator on the chart. What am I doing wrong?
//+------------------------------------------------------------------+
//| TCALERTv1.mq4 |
//| Copyright 2007, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2007, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red
double ExtMapBuffer1[];
//---- input parameters
//--extern int Len=21;
//--extern int Len=21;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,3,Red);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
IndicatorShortName("TCALERT");
SetIndexBuffer(0,ExtMapBuffer1);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//----Error Check
if (counted_bars < 0) return(-1);
//----Last Counted Bar Will Be Counted
if (counted_bars >0) counted_bars--;
int pos = Bars - counted_bars;
double dHigh, dLow, dResult;
//----Main Calc Loop
while(pos>=0)
{
dHigh = High[pos];
dLow = Low[pos];
dResult = dHigh - dLow;
ExtMapBuffer1[pos] = dResult;
pos--;
}
return(0);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| TCALERTv1.mq4 |
//| Copyright 2007, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2007, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red
double ExtMapBuffer1[];
//---- input parameters
//--extern int Len=21;
//--extern int Len=21;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,3,Red);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
IndicatorShortName("TCALERT");
SetIndexBuffer(0,ExtMapBuffer1);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//----Error Check
if (counted_bars < 0) return(-1);
//----Last Counted Bar Will Be Counted
if (counted_bars >0) counted_bars--;
int pos = Bars - counted_bars;
double dHigh, dLow, dResult;
//----Main Calc Loop
while(pos>=0)
{
dHigh = High[pos];
dLow = Low[pos];
dResult = dHigh - dLow;
ExtMapBuffer1[pos] = dResult;
pos--;
}
return(0);
}
//+------------------------------------------------------------------+