Guys,
I am trying to code an indicator which allows me to plot a horizontal grid spaced a specific number of points apart, anchored to a specific price high or low. Eg if the market makes a low at 1.1266 (USDCAD on 20061110) then I want to be able to plot horizontal lines a configurable distance apart up or down as the price moves up or down from that low.
Here is the code I have
Code:
//+------------------------------------------------------------------+
//| Market_Grid.mq4 |
//| Copyright © 2006, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Market Analytics & Automated Trading Ltd"
#property link "http://www.blackboxfutures.com"
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Gainsboro
//---- input parameters
extern double base=1.1266;
extern double incr=0.0050;
extern bool Debug = true;
int i;
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(4);
SetIndexStyle(0,DRAW_LINE, STYLE_DOT,1,indicator_color1);
SetIndexBuffer(0, ExtMapBuffer1);
SetIndexStyle(1,DRAW_LINE, STYLE_DOT,1,indicator_color1);
SetIndexBuffer(1, ExtMapBuffer2);
SetIndexStyle(2,DRAW_LINE, STYLE_DOT,1,indicator_color1);
SetIndexBuffer(2, ExtMapBuffer3);
SetIndexStyle(3,DRAW_LINE, STYLE_DOT,1,indicator_color1);
SetIndexBuffer(3, ExtMapBuffer4);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
double _level0=0.0;
double _level1=0.0 ;
double _level2=0.0;
double _level3=0.0;
int counted_bars=IndicatorCounted();
//----
i=Bars-counted_bars-1;
while(i>=0)
{
_level0 = URLevel(base, incr, i);
_level1 = _level0+incr;
_level2 = _level0+(incr*2);
_level3 = _level0-incr;
if(Debug)
{
Print("_level0 :" + _level0);
Print("_level1 :" + _level1);
Print("_level2 :" + _level2);
Print("_level3 :" + _level3);
Print("incr : " + incr);
}
ExtMapBuffer1[i]= _level0;
ExtMapBuffer2[i]= _level1;
ExtMapBuffer3[i]= _level2;
ExtMapBuffer4[i]= _level3;
i--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
double URLevel(double base, double incr, int idx)
{
double offset = 0;
double _urlevel = 0;
offset = base - (MathFloor(base/incr) * incr);
_urlevel = (MathFloor(Close[idx]/incr) * incr) + offset;
if(Debug)
{
Print("MathFloor(base/incr)) : " + MathFloor(base/incr));
Print("Offset : " + offset);
Print("URLevel : " + _urlevel);
}
return(_urlevel);
}
Currently this plots continuous lines. When I open the indicator in the indicators list dialogbox, plots 2 to 4 (i.e. ExtMapBuffer1 2 and 3) are black... i.e. for some reason the indicator is not picking up that I have specified the plots to be in the color defined in the indicator_color1 property. Also all other propereties are not set. And despite specifiying STYLE_DOT in the SetIndexStyle method call it is plotting a dotted line. I have tried using DRAW_LINE and DRAW_SECTION. The effect I am trying to achieve is shown in the attached Market_Grid.gif . The effect I am getting is shown in USDCAD_Grid.gif.
Can anyone tell me how to get the plots as dots rather than dotted lines and point out how to get the Indicator to pick up the values I am specifying.
Thanks
Paz