Counting Question

 

Trying to count the number of times that the Ask price goes above the High of the day.  Only seem to get zero, with the following code.  Can someone tell me what I'm doing wrong or missing?  Seems like this should be pretty simple.  Perhaps code is only being seen as a true or false condition.


Thanks!

#property indicator_chart_window

extern string Settings_n_1 = "--------------------------";
extern int Side = 1;
extern int MP_Y = 0; 
extern int MP_X = 0;

int start()

{
        string text;
        int highcnt = 0;

        double DH =  iHigh(NULL,PERIOD_D1,0);

        if(Ask > DH)
        {  
        highcnt = highcnt + 1;
        text=" Count =  "+ highcnt;   
        Write("MP14350", Side, MP_X+30, MP_Y+230, text, 12, "Tahoma", White);
        }  


//----
   return(0);
}
//+------------------------------------------------------------------+


 // Write Procedure
    void Write(string LBL, double side, int pos_x, int pos_y, string text, int fontsize, string fontname, color Tcolor=CLR_NONE)
       {
       ObjectCreate(LBL, OBJ_LABEL, 0, 0, 0);
       ObjectSetText(LBL,text, fontsize, fontname, Tcolor);
       ObjectSet(LBL, OBJPROP_CORNER, side);
       ObjectSet(LBL, OBJPROP_XDISTANCE, pos_x);
       ObjectSet(LBL, OBJPROP_YDISTANCE, pos_y);
  
 
Yellowbeard1781:

Trying to count the number of times that the Ask price goes above the High of the day.  Only seem to get zero, with the following code.  Can someone tell me what I'm doing wrong or missing?  Seems like this should be pretty simple.  Perhaps code is only being seen as a true or false condition.


Thanks!

I think start() is deprecated.

You want to look up Event Handling Functions to determine where you want to do your testing. OnStart() and OnInit() aren't the correct place as these are only used for initialization. You probably want OnTick() for an EA or OnCalculate() for an indicator.

 
Yellowbeard1781: Trying to count the number of times that the Ask price goes above the High of the day.  Only seem to get zero, with the following code. 

You are resetting the count to zero each tick.

Reason: