Draw Horizontal Line expiration only one day

 

Hi,

how can I draw an horizonal line, which I can see only on the actual day?

That is my old code:

ObjectCreate(name,OBJ_HLINE,0,Time[0],high,Time[0],high);

ObjectSet (name,OBJPROP_COLOR,MediumSeaGreen);


But what should I change now?

 
sunshineh:

Hi,

how can I draw an horizonal line, which I can see only on the actual day?

That is my old code:

ObjectCreate(name,OBJ_HLINE,0,Time[0],high,Time[0],high);

ObjectSet (name,OBJPROP_COLOR,MediumSeaGreen);


But what should I change now?


ObjectCreate(name,OBJ_HLINE,0,Time[0],high,Time[1],high);

Will draw a line from the last bar to the current bar. I've never tried [-1] but see what happens.

sn

 

@serpentsnoir

Yes, I saw this function. But I want to draw it for expample at 8 a.m. for the hole day. On the other day at 8 a.m. the horizonal line is at another high.

What happens, when I have always the same name for the line, does this replace it?

 
  1. Hline is a horizontal line across the entire chart. Create takes only one price (the time is ignored)
  2. Tline is what you want, with ray=false. The second point is Time[1]. A Tline of zero length isn't visible.
  3. does this replace it?
    No it doesn't replace, Create fails since the object already exists and nothing changes.
void TLine( string name, datetime T0, double P0, datetime T1, double P1
          , color clr, bool ray=false ){                #define WINDOW_MAIN 0
    if (!Show.Objects)  return;
    /**/ 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());
}
void HLine(string name, double P0, color clr){  //      #define WINDOW_MAIN 0
    if (!Show.Objects)  return;
    /**/ 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());
}
string  PriceToStr(double p){
    string pFrc = DoubleToStr(p, Digits);       if(Digits.pips==0) return(pFrc);
    string pPip = DoubleToStr(p, Digits-1);
    if (pPip+"0" == pFrc)       return(pPip);           return(pFrc);          }
//++++ These are adjusted for 5 digit brokers.
int     pips2points;    // slippage  3 pips    3=points    30=points
double  pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
int     init(){
    if (Digits == 5 || Digits == 3){    // Adjust for five (5) digit brokers.
                pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
    } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
}