My First Test Indicator Doesn't Work > Need guidance

 

Hi,


The full code I have is:


//+------------------------------------------------------------------+

//| asdf.m4q

//|

//| 

//+------------------------------------------------------------------+

#property copyright "Test"

#property link "www.test.com"

//#property indicator_chart_window

//#property indicator_buffers 1

//#property indicator_color1 Red

//---- buffers

double ExtMapBuffer1[];

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

//---- indicators

SetIndexBuffer(0,ExtMapBuffer1);

//----

return(1);

}

//+------------------------------------------------------------------+

//| Custor indicator deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{
ObjectsDeleteAll(OBJ_TREND);
//----

//----

return(0);

}

//+------------------------------------------------------------------+

//| Custom indicator iteration function |

//+------------------------------------------------------------------+

int start()

{

int counted_bars=IndicatorCounted();

//---- check for possible errors

if (counted_bars<0) return(-1);

//---- last counted bar will be recounted

if (counted_bars>0) counted_bars--;

int pos=Bars-counted_bars;



//---- main calculation loop

while(pos>=0)

{




if ( Low[pos] == Low[pos-1] ) {
   if(!ObjectCreate("lowLine", OBJ_TREND, 0, Time[pos-1], Low[pos], Time[pos+1], Low[pos] ) ) {
      Print("error: can't create text_object! code #",GetLastError());
      return(0);
      }
   ObjectSet("lowLine", OBJPROP_COLOR, Yellow);
   ObjectSet("lowLine", OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet("lowLine", OBJPROP_WIDTH, 2);
   ObjectSet("lowLine", OBJPROP_RAY, False);
   
}

if ( High[pos] == High[pos-1] ) {
   if(!ObjectCreate("highLine", OBJ_TREND, 0, Time[pos-1], High[pos], Time[pos+1], High[pos] ) ) {
      Print("error: can't create text_object! code #",GetLastError());
      return(0);
      }
   ObjectSet("highLine", OBJPROP_COLOR, Yellow);
   ObjectSet("highLine", OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet("highLine", OBJPROP_WIDTH, 2);
   ObjectSet("highLine", OBJPROP_RAY, False);
}



pos--;

}

//----

return(0);

}


No trendlines are created in the window. Also, when I insert breakpoints, and I insert the indicator, nothing happens.


Any help appreciated.

Thanks

 
skyhr:

Hi,


The full code I have is:



No trendlines are created in the window. Also, when I insert breakpoints, and I insert the indicator, nothing happens.


Any help appreciated.

Thanks



I added a couple of lines of code:



//+------------------------------------------------------------------+

//| asdf.m4q

//|

//| 

//+------------------------------------------------------------------+

#property copyright "Test"

#property link "www.test.com"

#property indicator_chart_window

#property indicator_buffers 1

//#property indicator_color1 Red

//---- buffers

double ExtMapBuffer1[];

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

//---- indicators

SetIndexBuffer(0,ExtMapBuffer1);

//----

return(1);

}

//+------------------------------------------------------------------+

//| Custor indicator deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{
ObjectsDeleteAll(OBJ_TREND);
//----

//----

return(0);

}

//+------------------------------------------------------------------+

//| Custom indicator iteration function |

//+------------------------------------------------------------------+

int start()

{

int counted_bars=IndicatorCounted();

//---- check for possible errors

if (counted_bars<0) return(-1);

//---- last counted bar will be recounted

if (counted_bars>0) counted_bars--;

int pos=Bars-counted_bars;



//---- main calculation loop



while(pos>=0)

{

if ( Low[pos] == Low[pos-1] ) {
   if(!ObjectCreate("lowLine", OBJ_TREND, 0, Time[pos-1], Low[pos], Time[pos+1], Low[pos] ) ) {
      Print("error: can't create text_object! code #",GetLastError());
      return(0);
      }
   string lowLine = "lowLine"+  pos ; 
   ObjectSet(lowLine, OBJPROP_COLOR, Yellow);
   ObjectSet(lowLine, OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet(lowLine, OBJPROP_WIDTH, 2);
   ObjectSet(lowLine, OBJPROP_RAY, False);


   
}
   string highLine = "highLine"+  pos ; 
if ( High[pos] == High[pos-1] ) {
   if(!ObjectCreate("highLine", OBJ_TREND, 0, Time[pos-1], High[pos], Time[pos+1], High[pos] ) ) {
      Print("error: can't create text_object! code #",GetLastError());
      return(0);
      }
   ObjectSet(highLine, OBJPROP_COLOR, Yellow);
   ObjectSet(highLine, OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet(highLine, OBJPROP_WIDTH, 2);
   ObjectSet(highLine, OBJPROP_RAY, False);
   
}



pos--;

}

//----

return(0);

}


When I ran your indicator I saw it did create an object.


So adding pos to the object name would create all of the objects that fit your criteria:





Hope that helps.

 

Hi,


I copied and pasted your code and tried it but it didn't work at all. Have you tried your indicator wit h the pos? If you manage to get it fixed, could you tell me?


Thanks