Drawing stoploss position on a chart of expert advisor

 

Hello, I am currently learning mql4.

1) Does any one know a good tutorial ?

2) Is it possible in an EA to draw a line on the chart, for instance indicating the position of a moving stoploss ? I've discovered how to print such a line on an indicator, but it appears it doesn't work in EA.

 

EA can draw on chart only by using ObjectCreate().

So, monitor your open trades.

Create a horizontal line or trend line at the stop-loss price.

Monitor your open trades...

When the stop-loss changes, change the price attributes of the stop-loss line object.

 
If you'd like to see a permanent visual of where the SL was instead of only the last position (via HLINE) try:
//+------------------------------------------------------------------+
//| Level object creation function                                   |
//+------------------------------------------------------------------+
#define ARROW_NDASH       4                     //#define ARROW_CIRCLEDOT   164
void MakeMarker( string name,   int ticket,     int barNum,
                 double price,  color obColor,  int arrow=ARROW_NDASH ){
    if (!Show.Objects) return;
    #define MAXOBJ 100                  // Prevent Tester memory handler: tester
    string                              // stopped because not enough memory
    objName = StringConcatenate(name, "#",  ticket%MAXOBJ, "-", barNum);
    if (!ObjectMove( objName, 0,        TimeCurrent(), price)){
        if (!ObjectCreate( objName, OBJ_ARROW, WINDOW_MAIN,
                                    TimeCurrent(), price)){  Alert(
            "ObjectCreate(", objName, "Arrow) failed: ",    GetLastError());
            return;
        }
        if (!ObjectSet( objName, OBJPROP_ARROWCODE, arrow ))            Alert(
            "ObjectSet(", objName, "Arrow) [2] failed: ",       GetLastError());
        if (!ObjectSet( objName, OBJPROP_COLOR, obColor ))              Alert(
            "ObjectSet(", objName, "Color) [3] failed: ",       GetLastError());
    }
                                                    #define STD_TEXT_SIZE EMPTY
    if (!ObjectSetText( objName, DoubleToStr(price, Digits), STD_TEXT_SIZE
        ))  Alert("ObjectSetText(", objName, ") failed:",       GetLastError());
    return;
}   // MakeMarker
int barNum = iBarShift(NULL,0, OrderOpenTime());
 
phy:

EA can draw on chart only by using ObjectCreate().

So, monitor your open trades.

Create a horizontal line or trend line at the stop-loss price.

Monitor your open trades...

When the stop-loss changes, change the price attributes of the stop-loss line object.


Thank you very much, I appreciate your help.

Have a nice day, Fiorenzo

Reason: