Hi All,
Need some help with my indicator. Please find the code below.
It's is supposed to draw arrows in regions where price moved more that "X" number of pips within the last 20 bars hence:
Open[i] > (Open[i+20] + PriceMove * Point) )
It draws arrow fine on the chart where i want them, but for some reason, does not update live. If have to restart the indicator and the arrows appear after that only. Please advise where there error in the code is if you can.
Rgrds and thanks in advance,
------------------------------
#property indicator_chart_window
// The number of buffers for calculation, up to 8
#property indicator_buffers 2
// The color for displaying arrows
#property indicator_color1 Green // Long signal
#property indicator_color2 Red // Short signal
// Width of the arrows
#property indicator_width1 2 // Long signal arrow
#property indicator_width2 2 // Short signal arrow
extern int PriceMove = 20 ;
// Buffers for the calculations
double Up_Arrow_Buffer[]; // Long buffer for display
double Down_Arrow_Buffer[]; // Short buffer for display
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
// SetIndexStyle - sets the new type, style, width and color for a given indicator line
// SetIndexBuffer - binds the array variable declared at a global level to the custom indicator pre-defined buffer
// SetIndexArrow - sets an arrow symbol for indicators line of the DRAW_ARROW type.
SetIndexStyle(0, DRAW_ARROW);
SetIndexBuffer(0, Up_Arrow_Buffer);
SetIndexArrow(0, 233); // Up arrow
SetIndexStyle(1, DRAW_ARROW);
SetIndexBuffer(1, Down_Arrow_Buffer);
SetIndexArrow(1, 234); // Down arrow
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int i; // Bar index
int Counted_bars; // Number of counted bars
//--------------------------------------------------------------------
Counted_bars=IndicatorCounted(); // Number of counted bars
i=Bars-Counted_bars-2; // Index of the first uncounted
while(i>0) // Loop for uncounted bars
{
if (isUpSwingBar(i))
{
Up_Arrow_Buffer[i] = Low[i] - (20 * Point);
Down_Arrow_Buffer[i] = EMPTY_VALUE;
i--;
continue;
}
if (isDownSwingBar(i))
{
Down_Arrow_Buffer[i] = High[i] + (20 * Point);
Up_Arrow_Buffer[i] = EMPTY_VALUE;
i--;
continue;
}
Up_Arrow_Buffer[i] = EMPTY_VALUE;
Down_Arrow_Buffer[i] = EMPTY_VALUE;
i--;
}
//----
return(0);
}
bool isUpSwingBar(int i)
{
if (Open[i] > (Open[i+20] + PriceMove * Point) )
{
return (true);
}
return (false);
}
bool isDownSwingBar(int i)
{
if (Open[i] < (Open[i+20] -PriceMove * Point) )
{
return (true);
}
return (false);
}
//+------------------------------------------------------------------+
Need some help with my indicator. Please find the code below.
It's is supposed to draw arrows in regions where price moved more that "X" number of pips within the last 20 bars hence:
Open[i] > (Open[i+20] + PriceMove * Point) )
It draws arrow fine on the chart where i want them, but for some reason, does not update live. If have to restart the indicator and the arrows appear after that only. Please advise where there error in the code is if you can.
Rgrds and thanks in advance,
------------------------------
#property indicator_chart_window
// The number of buffers for calculation, up to 8
#property indicator_buffers 2
// The color for displaying arrows
#property indicator_color1 Green // Long signal
#property indicator_color2 Red // Short signal
// Width of the arrows
#property indicator_width1 2 // Long signal arrow
#property indicator_width2 2 // Short signal arrow
extern int PriceMove = 20 ;
// Buffers for the calculations
double Up_Arrow_Buffer[]; // Long buffer for display
double Down_Arrow_Buffer[]; // Short buffer for display
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
// SetIndexStyle - sets the new type, style, width and color for a given indicator line
// SetIndexBuffer - binds the array variable declared at a global level to the custom indicator pre-defined buffer
// SetIndexArrow - sets an arrow symbol for indicators line of the DRAW_ARROW type.
SetIndexStyle(0, DRAW_ARROW);
SetIndexBuffer(0, Up_Arrow_Buffer);
SetIndexArrow(0, 233); // Up arrow
SetIndexStyle(1, DRAW_ARROW);
SetIndexBuffer(1, Down_Arrow_Buffer);
SetIndexArrow(1, 234); // Down arrow
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int i; // Bar index
int Counted_bars; // Number of counted bars
//--------------------------------------------------------------------
Counted_bars=IndicatorCounted(); // Number of counted bars
i=Bars-Counted_bars-2; // Index of the first uncounted
while(i>0) // Loop for uncounted bars
{
if (isUpSwingBar(i))
{
Up_Arrow_Buffer[i] = Low[i] - (20 * Point);
Down_Arrow_Buffer[i] = EMPTY_VALUE;
i--;
continue;
}
if (isDownSwingBar(i))
{
Down_Arrow_Buffer[i] = High[i] + (20 * Point);
Up_Arrow_Buffer[i] = EMPTY_VALUE;
i--;
continue;
}
Up_Arrow_Buffer[i] = EMPTY_VALUE;
Down_Arrow_Buffer[i] = EMPTY_VALUE;
i--;
}
//----
return(0);
}
bool isUpSwingBar(int i)
{
if (Open[i] > (Open[i+20] + PriceMove * Point) )
{
return (true);
}
return (false);
}
bool isDownSwingBar(int i)
{
if (Open[i] < (Open[i+20] -PriceMove * Point) )
{
return (true);
}
return (false);
}
//+------------------------------------------------------------------+