View Single Post
  #15 (permalink)  
Old 12-07-2005, 10:38 PM
codersguru's Avatar
codersguru codersguru is offline
Senior Member
 
Join Date: Oct 2005
Posts: 994
codersguru has a spectacular aura aboutcodersguru has a spectacular aura aboutcodersguru has a spectacular aura about
Arrow MQL to MQL4

Quote:
Originally Posted by saslam
This is agreat course. I went through the lessons until the first custom indicator. I have some understanding, but not thorogh. I hope in due course I will get the hang of it. THANK YOU CODEGURU for putting together this course.

I tried to convert one of my simple indicator from mql2, but there is something wrong. Can you check it?
saslam,

Please try this code:

PHP Code:
//+------------------------------------------------------------------+
//|                                                     2PROC.mq4 |
//|                                                         saslam |
//|                                     http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "saslam"
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];

//----
//int ExtCountedBars=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   
SetIndexStyle(0,DRAW_LINE);
   
SetIndexBuffer(0,ExtMapBuffer1);
   
SetIndexStyle(1,DRAW_LINE);
   
SetIndexBuffer(1,ExtMapBuffer2);
   
string short_name "2PROC";
   
IndicatorShortName(short_name);
//----
   
return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                     |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   
return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                             |
//+------------------------------------------------------------------+
int start()
  {
   
int pos;
   
int counted_bars=IndicatorCounted();
//---- check for possible errors
   
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   
if(counted_bars>0counted_bars--;

   
pos=Bars-counted_bars;
   
   

//---- main calculation loop
   
while(pos>=0)
   {
// ----Main loop   
 
      
ExtMapBuffer1[pos]=(Close[pos+1]-Close[pos+3])+Close[pos+2];
      
ExtMapBuffer2[pos]=(Close[pos+0]-Close[pos+2])+Close[pos+1];
      
pos--;
      }
     
//----
   
return(0);
  }
//+------------------------------------------------------------------+ 
__________________
Hope it helps !
Coders' Guru
Senior MQL programmer:
www.xpworx.com/custom.htm
Reply With Quote