draw a line between OrderOpenPrice & TP

 


Hi, I am trying to write the code that draws a line between OrderOpenPrice and the TP point as

string name="Arrow_"+OrderTicket();  
        ObjectDelete(name);
        ObjectCreate(name,OBJ_ARROW,0,Time[0],TP);
        ObjectSet(name, OBJPROP_STYLE, STYLE_DOT);
    ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
    ObjectSet(name, OBJPROP_COLOR, Black);
         name="TP line_"+OrderTicket();  
        ObjectCreate(name,OBJ_TREND,0,OrderOpenTime(),OrderOpenPrice(),Time[0],TP);
        ObjectSet(name,OBJPROP_COLOR,White); 
        ObjectSet(name,OBJPROP_STYLE,2);
        ObjectSet(name,OBJPROP_WIDTH,0);

shown on the diagram. I've tried it with codes but failed

1. it draws the trendline that is longer than the two end points

2. it does not delete the old lines when new bar appears

thanks in advance

 
For 1) look into OBJPROP_RAY here. For 2) make sure you have the correct name+ Ticket#, use print statements to help debug.
 
  ObjectCreate(name,OBJ_TREND,0,OrderOpenTime(),OrderOpenPrice(),Time[0],TP);
Once you create the object, that call will not do anything - lines will not move. Try this pattern from my code:
TLine(name, OrderOpenTime, OrderOpenPrice(), Time[0], TP, White);
:
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());
}
Always test return codes.
 

wow, big thanks to WHRoeder, you really help a lot to this forum

million thanks!!!!

Reason: