please, help me with the code

 

Hello, Can anybody help me with code?

I want to create an indicator, drawing vline since 1970.01.01 after every 1000000.54 seconds.

I wrote something like this but it doesn't work:

int start()
  {     
   datetime nl = 1000000.54;
        datetime start =  StrToTime("1970.1.1 00:00");
        int counted_bars = IndicatorCounted();
        int i=Bars-counted_bars-1; 

 while(i>=0){

        for (start = StrToTime("1970.1.1 00:00"); start < TimeCurrent(); start = start + nl)

        datetime startTime = start;

         

        i--; 

        }
        startLine(start);
        }

void startLine(datetime startTime){

   ObjectCreate("start",OBJ_VLINE,0,startTime,0);

   ObjectSet("start",OBJPROP_COLOR,Maroon);

   WindowRedraw();

   return(0);

} 

 

start = 0 https://docs.mql4.com/dateandtime "A group of functions providing the working with data of the datetime type (integer representing the amount of seconds elapsed from midnight, 1 January, 1970)."

You need to give each of your lines a new name, unless you want to just move a single line across the screen.

You need to check that your values generated by your loop are greater than the datetime for bar Bars-1 . . . if they are then you can draw them, otherwise they are off chart.

 
Please, can anyone help me to write this code? I do not know how to give a different name for the next object. Maybe use indicator's buffer instead ObjectCreate(); function? but how??
 
use a for loop, Name+i or something like this
 
void startLine(datetime startTime){
   
   int all_objects = ObjectsTotal();
   string name; 
   for(int cn=0;cn < all_objects; cn++)
   name = "new_moon"+cn;
   ObjectCreate("start"+cn,OBJ_VLINE,0,startTime,0);
   ObjectSet("start"+cn,OBJPROP_COLOR,Maroon);
   WindowRedraw();
   return(0);
}

after that there are many lines with different names but all of them are in one place (time)

 
m4dmike:

Hello, Can anybody help me with code?

I want to create an indicator, drawing vline since 1970.01.01 after every 1000000.54 seconds.

I wrote something like this but it doesn't work:

   datetime nl = 1000000.54;

Of course it doesn't since a datetime is WHOLE seconds.
int start(){
    datetime from = Time[Bars-1], to = Time[0];
    for(double seconds=0; true; seconds += 1000000.54){
        if (seconds < from) continue;
        if (seconds > to  ) break;
        VLine("second"+seconds, seconds, Red);
    }
}
void VLine(string name, datetime T0, color clr){      #define WINDOW_MAIN 0
    if (!Show.Objects)  return;
    if      (ObjectMove( name, 0, T0, 0 )){}
    else if (!ObjectCreate( name, OBJ_VLINE, WINDOW_MAIN, T0, 0 ))
        Alert("ObjectCreate(",name,",VLINE) failed: ", GetLastError() );
    if (!ObjectSet(name, OBJPROP_COLOR, clr )) // Allow color change
        Alert("ObjectSet(", name, ",Color) [1] failed: ", GetLastError() );
    if (!ObjectSetText(name, TimeToStr(T0, TIME_MINUTES), 10))
        Alert("ObjectSetText(",name,") [1] failed: ", GetLastError());
}
 

thanks a lot WHRoeder

it works properly

Reason: