Adding line every 12.00

 

Hi seems to be easy task but, i cant figure it out so easily, and can't find simple info for it. I just need that my EA would add hline every day at given time for ex 12.00. I have tryed that but it does not draw anything, also i need that it would be able to see in strategy tester.


ObjectCreate("name", OBJ_HLINE, 0, Time[12:00], Close[0]);
ObjectSet("name", OBJPROP_COLOR, Red);
ObjectSet("name", OBJPROP_WIDTH, 1);

}


Is it so dificuilt to specify the simple time cordinates to EA ???

 
Vyckaa:

Hi seems to be easy task but, i cant figure it out so easily, and can't find simple info for it. I just need that my EA would add hline every day at given time for ex 12.00. I have tryed that but it does not draw anything, also i need that it would be able to see in strategy tester.


ObjectCreate("name", OBJ_HLINE, 0, Time[12:00], Close[0]); <------ Time[12:00] is incorrect. Time[] array takes in of int type, the shift in no. of bars.
ObjectSet("name", OBJPROP_COLOR, Red);
ObjectSet("name", OBJPROP_WIDTH, 1);

}


Is it so dificuilt to specify the simple time cordinates to EA ???

You need a conditional like this:

if(TimeHour(Time[0])==12 && TimeMinute(Time[0])==0) { then create the object..use a different "name" for different object
 
THANK YOU! it worked :) finaly, but one more thing, i need that it draw the line every day at 12, with this code it draws one time and stays forever.It should draw one and wait for the next one and delete old one. Is it hard to do?
 
Vyckaa:
THANK YOU! it worked :) finaly, but one more thing, i need that it draw the line every day at 12, with this code it draws one time and stays forever.It should draw one and wait for the next one and delete old one. Is it hard to do?
Create the line once . . . then use https://docs.mql4.com/objects/ObjectMove or https://docs.mql4.com/objects/ObjectSet to change it's position at the appropriate time.
 
datetime now = Time[0],
         bod = now - now % 86400, // 00:00
         H1200 = bod + 12 * 3600;
if (H12 > now) H1200 = bod - 12 * 3600;
int      iH12 = iBarShift(NULL,0, H12); // Handle weekends and holidays.
HLine("name", Close[iH12], Red);
:
void HLine(string name, double P0, color clr){        #define WINDOW_MAIN 0
    if      (ObjectMove( name, 0, Time[0], P0 )){}
    else if (!ObjectCreate( name, OBJ_HLINE, WINDOW_MAIN, Time[0], P0 ))
        Alert("ObjectCreate(",name,",HLINE) failed: ", GetLastError() );
    if (!ObjectSet(name, OBJPROP_COLOR, clr )) // Allow color change
        Alert("ObjectSet(", name, ",Color) [1] failed: ", GetLastError() );
    if (!ObjectSetText(name, PriceToStr(P0), 10))
        Alert("ObjectSetText(",name,") [1] failed: ", GetLastError());
}
  1. You want the noon close, not close[0]
  2. You have to delete the old and recreate or move it.
  3. There is no noon on Saturday or Sunday.
  4. You might like a horizontal trendline starting at noon instead of a Hline.
    :
    TLine("name", Time[iH12], Close[iH12], Time[0], Close[iH2], Red, true);
    :
    void TLine( string name, datetime T0, double P0, datetime T1, double P1
              , color clr, bool ray=false ){                #define WINDOW_MAIN 0
        if      (ObjectMove( name, 0, T0, P0 ))     ObjectMove(name, 1, T1, P1);
        else if (!ObjectCreate( name, OBJ_TREND, WINDOW_MAIN, T0, P0, T1, P1 ))
            Alert("ObjectCreate(",name,",TREND) failed: ", GetLastError() );
        else if (!ObjectSet( name, OBJPROP_RAY, ray ))
            Alert("ObjectSet(", name, ",Ray) failed: ", GetLastError());
        if (!ObjectSet(name, OBJPROP_COLOR, clr )) // Allow color change
            Alert("ObjectSet(", name, ",Color) [2] failed: ", GetLastError());
        string  P0t = PriceToStr(P0);           if (MathAbs(P0 - P1) >= Point)
                P0t = StringConcatenate(P0t, " to ", PriceToStr(P1));
        if (!ObjectSetText(name, P0t, 10))
            Alert("ObjectSetText(",name,") [2] failed: ", GetLastError());
    }
    

 
Vyckaa:
THANK YOU! it worked :) finaly, but one more thing, i need that it draw the line every day at 12, with this code it draws one time and stays forever.It should draw one and wait for the next one and delete old one. Is it hard to do?
That, you have to implement the other helpers codes or answers. Try it.
 

Доброго времени суток уважаемые форумчане!

Меня зовут Герман, мне 23 года, я являюсь трейдером компании "Инстафорекс"

Помогите в поиске нужного скрипта! Скрипт нужен для сетки отложенных ордеров.

 

Thanks for help, but some of your sugestions is too dificult, so i did lines to apear every day like that, but now i have other the most important problem. How to make space betwen those two lines,exactly for ex 20p ? i tryed ydistance but it is not working. I need that ea would add twoo lines at given time with the 20p space. Is it posible?


if(TimeHour(Time[0])==10 && TimeMinute(Time[0])==0)
      
ObjectDelete("virsus");
ObjectDelete("apacia");

      
 if(TimeHour(Time[0])==11 && TimeMinute(Time[0])==0) 
      ObjectCreate("virsus", OBJ_HLINE, 0, Time[0], High[0]);
      ObjectSet("virsus", OBJPROP_COLOR, Red);
      ObjectSet("virsus", OBJPROP_WIDTH, 1);
     
    
 if(TimeHour(Time[0])==11 && TimeMinute(Time[0])==0)      
      ObjectCreate("apacia", OBJ_HLINE, 0, Time[0], Low[0]);
      ObjectSet("apacia", OBJPROP_COLOR, Blue);
      ObjectSet("apacia", OBJPROP_WIDTH, 1);
     
   
    
    double virsus = ObjectGet("virsus", OBJPROP_PRICE1);
    double apacia = ObjectGet("apacia", OBJPROP_PRICE1);
    
 
Vyckaa:

Thanks for help, but some of your sugestions is too dificult, so i did lines to apear every day like that, but now i have other the most important problem. How to make space betwen those two lines,exactly for ex 20p ? i tryed ydistance but it is not working. I need that ea would add twoo lines at given time with the 20p space. Is it posible?


Just add/subtract it from the High[0]/Low[0]
 
sorry but what do you meen? I tryed to make the space by using low on one line and high at the other one, but its not ok becouse its not always the same.i need to keep it fixed.
 
If you want one line on the high use High[0] for it and High[0] + (20 * Point) for the other line . . you will have to adjust for 4/5 digit brokers . .