iCustom Indicator-Need Help

 

Hi Everyone,

I've been reading,explaining, and commenting about an indicator all this morning and not getting very far in the learning curve. It is only an exercise to understand the MQL4. It is an indicator that closely resembles the ATR, authored by Wells.

Build a program that returns the difference of the highest high minus the lowest low of the day. Note that yesterdays high, low, does NOT figure into this formula. In that way, it does not resemble the ATR.

What I have come up with so far:

//+------------------------------------------------------------------+
//| DR_Calculatation ver1.mq4 |
//| Copyright © 2009, MetaQuotes Software Corp. |
//| https://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, MetaQuotes Software Corp."
#property link "https://www.metaquotes.net/"


//---This is only an exercise to build a foundation.
//---A measurement of understanding of the MQL4.
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Blue
//---indicator parameters
//---??????????????????
extern int ???
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers (1);
//----Drawing preference
SetIndexStyle(3,DRAW_LINE,STYLE_SOLID,2,Blue);
SetIndexDrawBegin(0,IndicatorShortName);
IndicatorDigits(MarketInfo(NULL,MODE_?????);
//---Indicator Buffer Mapping
SetIndexBuffer(0,ind_buffer1);
//---Name for Separate DataWindow
IndicatorShortName ("DRMA("+20 MA, high-low of the day+")");
//---initialization done
return (0)

}


Compiling 'DR_Calculatation ver1.mq4'...

'int' - variable expected C:\Program Files\MBT MetaTrader 4\experts\DR_Calculatation ver1.mq4 (21, 1)
'init' - expression on global scope not allowed C:\Program Files\MBT MetaTrader 4\experts\DR_Calculatation ver1.mq4 (21, 5)
'MODE_?????' - variable not defined C:\Program Files\MBT MetaTrader 4\experts\DR_Calculatation ver1.mq4 (27, 38)
'ind_buffer1' - variable not defined C:\Program Files\MBT MetaTrader 4\experts\DR_Calculatation ver1.mq4 (29, 24)
'MA' - variable not defined C:\Program Files\MBT MetaTrader 4\experts\DR_Calculatation ver1.mq4 (31, 36)
'high' - variable not defined C:\Program Files\MBT MetaTrader 4\experts\DR_Calculatation ver1.mq4 (31, 40)
'low' - variable not defined C:\Program Files\MBT MetaTrader 4\experts\DR_Calculatation ver1.mq4 (31, 45)
'of' - variable not defined C:\Program Files\MBT MetaTrader 4\experts\DR_Calculatation ver1.mq4 (31, 49)
'the' - variable not defined C:\Program Files\MBT MetaTrader 4\experts\DR_Calculatation ver1.mq4 (31, 52)
'day' - variable not defined C:\Program Files\MBT MetaTrader 4\experts\DR_Calculatation ver1.mq4 (31, 56)

I really want to make some sense of what it is asking. Any help out there?

Regards

Huckleberry

 

Hi. This is my first post here but I'll try to make it of some value.


First off, I'm not sure that you've really set this up in the proper way. I'm somewhat new to mql4, certainly compared to some people around here, but it seems you haven't really gotten a grasp of how custom technical indicators work. You should go to the Book section of this site. There's an explanation in there, and even if you don't commit the code to memory you can at least use the code as a template, and build from there. Here is a direct link. Basically, as far as I can tell, you've provided a lot of parameters governing your indicator without making it do anything. While there are some problems with those parameters, there is a more important problem in the fact that you aren't apparently doing anything with the Start function to draw your indicator. Try this. Look at my comments and read the code. I was going to go into more detail, but it's getting late, so just ask me any questions. One thing I wanted to note was that for setindexstyle you were setting it to buffer 4 (of an index of 3) instead of the first (0). Little things like that mean a lot. And don't take it for granted, as I have things to learn myself. Also, doesn't seem to work for the current timeperiod. Probably they require the period to be over, though I'm not sure; didn't think that was the case. Thought it would draw it with the current highest and lowest.


//+------------------------------------------------------------------+
//|                 m                                           .mq4 |
//|                                Copyright © 2009,  Brett          |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009,  Brett"
#property link      ""

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
//---- declaration of first and only buffer variable
double Buf1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init(){
//---- sets the style of the buffer and links the buffer to the proper variable.
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,Buf1);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int i,
      /*this declares variables used to ensure that the indicator isn't needlessly 
      recalculated every tick. The i is then used in a loop to set buffer values.*/
      counted_bars=IndicatorCounted();
      i=Bars-counted_bars-1;
   while(i>0){
      //Discerns difference between high and low using iHigh and iLow functions
      Buf1[i] = iHigh(Symbol(),0,i) - iLow(Symbol(),0,i);
      i--;
   }
         
         
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+