I have a time problem in my code

thread: I have a time problem in my code

  1. #1
    Senior Member Orduniik11's Avatar
    101

    I have a time problem in my code

    I've this code and it work good, drawing a vertical line at 10:00 and another perpendicular line at 20:00, but if I set the time into e.g. 7:00 and 20:00 it only draw the 20:00 line.

    Can anybody tell me what's wrong?

    Inserted Code extern int iHour1 = 10; extern int iHour2 = 20;
    Inserted Code if(TimeHour(Time#91;I#93;-RRB-==iHour1 TimeMinute(Time#91;t#93;-RRB-==0) x ; ObjectCreate(Time x,OBJ_VLINE,0,Time#91;t#93;,Top#91;t#93;-RRB-; ObjectSet(Time x,OBJPROP_COLOR,Red); // Color value to set/get object colour. ObjectSet(Time x,OBJPROP_STYLE,STYLE_DOT); // Value is one of STYLE_SOLID, STYLE_DASH, STYLE_DOT, STYLE_DASHDOT, STYLE_DASHDOTDOT constants into set/get thing line fashion. ObjectSet(Time x,OBJPROP_WIDTH,1); // Integer value to set/get thing line width. Can be from 1 to 5. ObjectSet(Time x,OBJPROP_BACK,true); // Boolean value to set/get desktop drawing flag for thing. (such as true will conceal the value at the bottom of the chart.) Else if(TimeHour(Time#91;t#93;-RRB-==iHour2 TimeMinute(Time#91;t#93;-RRB-==0) x ; ObjectCreate(Time x,OBJ_VLINE,0,Time#91;t#93;,Top#91;t#93;-RRB-; ObjectSet(Time x,OBJPROP_COLOR,Yellow); // Color value to set/get object colour. ObjectSet(Time x,OBJPROP_STYLE,STYLE_DOT); // Value is one of STYLE_SOLID, STYLE_DASH, STYLE_DOT, STYLE_DASHDOT, STYLE_DASHDOTDOT constants into set/get thing line fashion. ObjectSet(Time x,OBJPROP_WIDTH,1); // Integer value to set/get thing line width. Can be from 1 to 5. ObjectSet(Time x,OBJPROP_BACK,true); // Boolean value to set/get desktop drawing flag for thing. (such as true will conceal the value at the bottom of the chart.)

  2. #2
    Senior Member ouuhyeaah's Avatar
    155
    You are probably missing the one second window for drawing on the line... Maybe there were no ticks during that window or another motive... Your code shouldn't be absolute since you will experience bugs. Rather your algo ought to be something along the lines of: if line doesn't exist and time is gt;= draw_time then draw line.

    Additionally, don't use extern if you don't have a desire to alter the input parameter from the code (which should be not), utilize the input key word rather since you want the compiler to complain if you accidentally attempt to programmatically alter the input.

  3. #3
    Senior Member Orduniik11's Avatar
    101
    You are probably missing the 1 second window for drawing the line... Perhaps there were no ticks through that window or another reason... Your code should never be absolute because you'll experience bugs. Instead your algo ought to be something along the lines of: if line does not exist and time is gt;= draw_time subsequently draw line. In addition, don't use extern if you don't absolutely have a necessity to alter the input parameter from the code (which should be not), use the input keyword rather because you want the compiler to complain if you inadvertently...
    Forgot to mention I'm testing this at the egy tester, so what's it about this moment? If I set iHour1 to 7 is does not get the job done, but should I set iHour1 into 10 it functions. Strange isn't it?

  4. #4
    Senior Member ouuhyeaah's Avatar
    155
    quote Forgot to say I am testing this in the egy tester, so what's it about this moment? If I set iHour1 to 7 is does not work, but should I set iHour1 to 10 it works. Strange isn't it?
    Like I said... you can't use absolutes. Your code says do this ONLY if the exact period is 7hrs and 00 mins.

  5. #5
    Senior Member Orduniik11's Avatar
    101
    quote Just like I said... you cannot use absolutes. Your code says do this ONLY if the exact period is 7hrs and 00 mins.
    Okay, I have attempted to change the code. It appears that this today, but nevertheless merely draw the 20:00 line.

    Inserted Code enter int iHour1 = 7; enter int iHour2 = 20;
    Inserted Code if(TimeHour(Time#91;I#93;-RRB-==iHour1 TimeMinute(Time#91;I#93gt;=0) x ; ObjectCreate(Time x,OBJ_VLINE,0,Time#91;I#93;,Top#91;I#93;-RRB-; ObjectSet(Time x,OBJPROP_COLOR,Red); // Color value to set/get object colour. ObjectSet(Time x,OBJPROP_STYLE,STYLE_DOT); // Value is one of STYLE_SOLID, STYLE_DASH, STYLE_DOT, STYLE_DASHDOT, STYLE_DASHDOTDOT constants into set/get object line style. ObjectSet(Time x,OBJPROP_WIDTH,1); // Integer value to set/get object line width. Could be from 1 to 5. ObjectSet(Time x,OBJPROP_BACK,true); // Boolean value to set/get desktop drawing flag for object. (such as true will hide the value in the bottom of the chart.) Else if(TimeHour(Time#91;t#93;-RRB-==iHour2 TimeMinute(Time#91;t#93gt;=0) x ; ObjectCreate(Time x,OBJ_VLINE,0,Time#91;t#93;,High#91;I#93;-RRB-; ObjectSet(Time x,OBJPROP_COLOR,Yellow); // Color value to set/get object colour. ObjectSet(Time x,OBJPROP_STYLE,STYLE_DOT); // Value is one of STYLE_SOLID, STYLE_DASH, STYLE_DOT, STYLE_DASHDOT, STYLE_DASHDOTDOT constants into set/get object line style. ObjectSet(Time x,OBJPROP_WIDTH,1); // Integer value to set/get object line width. Could be from 1 to 5. ObjectSet(Time x,OBJPROP_BACK,true); // Boolean value to set/get desktop drawing flag for object. (such as true will hide the value in the bottom of the chart.)

  6. #6
    Member fanl1's Avatar
    45
    How do you initialize x? Local or Global? If neighborhood does it run as int x=0 before the loop? Then each time you will get x=0, each new vertical will delete the preceding. And make sure you're changed at 1hr tf and not 4hr since 4hr won't show your line at 7:00.
    https://www.cliqforex.com/attachment...2122877888.mq4

  7. #7
    Senior Member Orduniik11's Avatar
    101
    How do you initialize x? Global or local? If neighborhood does it operate as int x=0 before the loop? Then every time you will get x=0, every new vertical will delete the preceding. And be sure you are switched at 1hr tf rather than 4hr since 4hr won't show your lineup at 7:00. document
    x is global

    I am Just on M15 charts

  •