Vertical Line Problem

 

Guys,

what unbelievably stupid thing haven't i done here? I just want to draw a vertical line between 2 points at a particular bar position (bar 5 in this example). It draws a line but the full height of the chart and at position 1!!!

please can anybody help.

ObjectCreate("cc", OBJ_VLINE, 0,Time[5],1.2383, 0,1.2353);
ObjectSet("cc",OBJPROP_WIDTH,5);
ObjectSet("cc",OBJPROP_COLOR, White);
thanks
 

Enumerated types and explanation here

Probably better to use OBJ_TREND which uses two co-ordinates where VLINE uses only one.

 
Ickyrus:

Enumerated types and explanation here

Probably better to use OBJ_TREND which uses two co-ordinates where VLINE uses only one.


well the documentation says Vertical line. Uses time part of first coordinate. This implies there is a 2nd coordinate so I'm not sure if that's true. I've actually tried using OBJ_TREND and that doesn't work either!
 
Found this comment in the forum - Sorry not programed objects in MLQ myself.
 
sd59:

well the documentation says Vertical line. Uses time part of first coordinate. This implies there is a 2nd coordinate so I'm not sure if that's true. I've actually tried using OBJ_TREND and that doesn't work either!

sorry you are right OBJ_TREND does work - but isn't it unbelievable that the more obvious one doesn't work!?
 

Virtical line needs only one value to be drawn - the time - the program requires as parameters two values so the price value is added in but not used.

Trend line requires two co-ordinates, Two end points. Makes sense to a programmer (smile)

 
sd59: It draws a line but the full height of the chart and at position 1!!!

of course it does, that's what a VLINE is. Use a TLine.

From my code:

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) [2] failed: ", GetLastError() );
    if (!ObjectSetText(name, TimeToStr(T0, TIME_MINUTES), 10))
        Alert("ObjectSetText(",name,") [4] failed: ", GetLastError());
}
void TLine( string name, datetime T0, double P0, datetime T1, double P1,
           color clr, double V0=INF, double V1=INF, bool ray=false, int iWin=0){
    if (!Show.Objects)  return;                         #define WINDOW_MAIN 0
    if      (ObjectMove( name, 0, T0, P0 ))     ObjectMove(name, 1, T1, P1);
    else if (!ObjectCreate( name, OBJ_TREND, iWin, 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) [4] failed: ", GetLastError());
    if (V0 != INF && V0 != P0)  // Non-price indicator overlayed on chart
        if (MathAbs( (V0 - V1) / MathMax(V0, V1) ) < 0.001)             string
                P0t = StringConcatenate(V0,"");
        else    P0t = StringConcatenate(V0, " to ", V1);
    else if (iWin != WINDOW_MAIN)
        if (MathAbs( (P0 - P1) / MathMax(P0, P1) ) < 0.001)
                P0t = StringConcatenate(P0,"");
        else    P0t = StringConcatenate(P0, " to ", P1);
    else if (MathAbs(P0 - P1) < Point_2)
                P0t = PriceToStr(P0);
    else        P0t = PriceToStr(P0) + " to " + PriceToStr(P1);
    if (!ObjectSetText(name, P0t, 10))
        Alert("ObjectSetText(",name,") [1] failed: ", GetLastError());
}