I have an indicator that I have written and it is my first indicator.
It highlights candles that are twice the average size of the last so many candles. it highights the candles with a message.
In a separate window you can see the candle size against the average size plotted.
It is the message I am having problems with. If I return to my screen and re-compile the code all the messages pop onto the chart as normal, where they remain. But an hour or so later when I want to see more of the candles identified I have to recompile again, and then they appear.
What have I done wrong?
code -
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Black
#property indicator_color2 Red
int limit;
static datetime BARSTART;
int N,s;
double AVG1[];
double candle[];
double huger=1.5;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
string PatternText[200000];
int x;
double avgr;double a; // avg candle bar size
//+------------------------------------------------------------------+
//| CuStom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
// period(), 1,5,15,30,60,240,1440, 10080,43200
IndicatorBuffers(2);
SetIndexStyle(0,DRAW_ARROW,EMPTY , 0, Red);
SetIndexArrow(0,234);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_ARROW,EMPTY , 1, Blue);
SetIndexArrow(1,233);
SetIndexBuffer(1,ExtMapBuffer2);
IndicatorBuffers(2);
SetIndexStyle(0, DRAW_HISTOGRAM, STYLE_SOLID,2);
SetIndexBuffer(0,AVG1);
SetIndexStyle(1, DRAW_HISTOGRAM, STYLE_SOLID,1);
SetIndexBuffer(1,candle);
// if (Period()<60) {limit=999999;}
if (Period()==5) {limit=48;}
if (Period()==15) {limit=24;}
if (Period()==30) {limit=12;}
if (Period()==60) {limit=24;}
if (Period()<240) {limit=30;}
if (Period()<1220) {limit=14;}
IndicatorDigits(Digits+5);
IndicatorShortName("Huge Candle - bars. "+ limit + ". weighting "+huger);
SetIndexDrawBegin(0,AVG1);
SetIndexDrawBegin(1,candle);
//---- huge candle
return(0);
}
//+------------------------------------------------------------------+
//| CuStor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
ObjectsDeleteAll(PatternText,OBJ_TEXT);
//----
return(0);
}
//+------------------------------------------------------------------+
//| CuStom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
string text;
int counted_bars=IndicatorCounted();
for(N = 1; N < counted_bars ; N++) {
PatternText[N] = CharToStr(N);
if (BARSTART < Time[0])
{
BARSTART = Time[0]; avgr=0;
for (s=1;s<limit; s++)
{
avgr=avgr+(High[s]-Low[s]);
}
AVG1[N]=(avgr/limit*huger) ;
a=High[N]-Low[N];
candle[N]=a; //High[N]-Low[N]; a=High[N]-Low[N];
Comment(" time ",Time[0]," barStart ",BARSTART," avg ",AVG1[N]," candle ",candle[N]," ",High[N]-Low[N]);
}
// check for extra large candles
if (candle[N]>AVG1[N] && Open[N]<Close[N])
{
ObjectCreate(PatternText[N], OBJ_TEXT, 0, Time[N], Low[N] - (50*Point));
ObjectSetText(PatternText[N], "Huge candle", 9, "Times New Roman", Blue);
}
if (candle[N]>AVG1[N] && Open[N]>Close[N])
{
ObjectCreate(PatternText[N], OBJ_TEXT, 0, Time[N], High[N] + (50*Point));
ObjectSetText(PatternText[N], "Huge candle", 9, "Times New Roman", Red);
}
}
return(0);
}
It highlights candles that are twice the average size of the last so many candles. it highights the candles with a message.
In a separate window you can see the candle size against the average size plotted.
It is the message I am having problems with. If I return to my screen and re-compile the code all the messages pop onto the chart as normal, where they remain. But an hour or so later when I want to see more of the candles identified I have to recompile again, and then they appear.
What have I done wrong?
code -
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Black
#property indicator_color2 Red
int limit;
static datetime BARSTART;
int N,s;
double AVG1[];
double candle[];
double huger=1.5;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
string PatternText[200000];
int x;
double avgr;double a; // avg candle bar size
//+------------------------------------------------------------------+
//| CuStom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
// period(), 1,5,15,30,60,240,1440, 10080,43200
IndicatorBuffers(2);
SetIndexStyle(0,DRAW_ARROW,EMPTY , 0, Red);
SetIndexArrow(0,234);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_ARROW,EMPTY , 1, Blue);
SetIndexArrow(1,233);
SetIndexBuffer(1,ExtMapBuffer2);
IndicatorBuffers(2);
SetIndexStyle(0, DRAW_HISTOGRAM, STYLE_SOLID,2);
SetIndexBuffer(0,AVG1);
SetIndexStyle(1, DRAW_HISTOGRAM, STYLE_SOLID,1);
SetIndexBuffer(1,candle);
// if (Period()<60) {limit=999999;}
if (Period()==5) {limit=48;}
if (Period()==15) {limit=24;}
if (Period()==30) {limit=12;}
if (Period()==60) {limit=24;}
if (Period()<240) {limit=30;}
if (Period()<1220) {limit=14;}
IndicatorDigits(Digits+5);
IndicatorShortName("Huge Candle - bars. "+ limit + ". weighting "+huger);
SetIndexDrawBegin(0,AVG1);
SetIndexDrawBegin(1,candle);
//---- huge candle
return(0);
}
//+------------------------------------------------------------------+
//| CuStor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
ObjectsDeleteAll(PatternText,OBJ_TEXT);
//----
return(0);
}
//+------------------------------------------------------------------+
//| CuStom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
string text;
int counted_bars=IndicatorCounted();
for(N = 1; N < counted_bars ; N++) {
PatternText[N] = CharToStr(N);
if (BARSTART < Time[0])
{
BARSTART = Time[0]; avgr=0;
for (s=1;s<limit; s++)
{
avgr=avgr+(High[s]-Low[s]);
}
AVG1[N]=(avgr/limit*huger) ;
a=High[N]-Low[N];
candle[N]=a; //High[N]-Low[N]; a=High[N]-Low[N];
Comment(" time ",Time[0]," barStart ",BARSTART," avg ",AVG1[N]," candle ",candle[N]," ",High[N]-Low[N]);
}
// check for extra large candles
if (candle[N]>AVG1[N] && Open[N]<Close[N])
{
ObjectCreate(PatternText[N], OBJ_TEXT, 0, Time[N], Low[N] - (50*Point));
ObjectSetText(PatternText[N], "Huge candle", 9, "Times New Roman", Blue);
}
if (candle[N]>AVG1[N] && Open[N]>Close[N])
{
ObjectCreate(PatternText[N], OBJ_TEXT, 0, Time[N], High[N] + (50*Point));
ObjectSetText(PatternText[N], "Huge candle", 9, "Times New Roman", Red);
}
}
return(0);
}