linesmql5graphical-programmingmetatrader5

How to draw a Filling like a Rectangle, in MQL5?


can anybody suggest a way how to achieve this kind of drawing, as the official mql5 documentation does not point out this.

enter image description here

I have done the sample provided here
but it only outputs this result,
which is not what I wanted.
enter image description here anybody has any suggestion?


Solution

  • The simpler part: ... better forget Custom Indicators ( all share single-thread / block )

    For a faster and safer GUI, with a full control over painting these orthogonal shapes, the New-MQL4/MQL5 languages can use something like this:

    // --------------------------------------------------------------------
    #define           GUI_aFontSIZE       10
    #define           GUI_aFontNAME      "Courier New"
    #define           GUI_aTradeCOLOR     C'80,0,80'
    #define           GUI_aTPed_COLOR     clrDarkGreen
    #define           GUI_aSLed_COLOR     clrDarkRed
    #define           GUI_isSELECTABLE    True
    
    long              GUI_aMainWINDOW = CharID();
    int               GUI_anObjNUMBER = 0;
    string                             anInterimObjNAME    = StringFormat( "GUI.DEMO_RectangularOBJECT_[%d]", GUI_anObjNUMBER );
    if (  ObjectFind(                  anInterimObjNAME ) == GUI_aMainWINDOW )
          ObjectDelete(                anInterimObjNAME );                                          //--- prevent collisions
    
    ObjectCreate(     GUI_aMainWINDOW, anInterimObjNAME, OBJ_RECTANGLE, 0,      aTimeOfENTRY, anEntryPRICE,
                                                                                aTimeOfEXIT,  DBL_MIN
                                                                                );
    ObjectSetInteger( GUI_aMainWINDOW, anInterimObjNAME, OBJPROP_COLOR,         GUI_aSLed_COLOR );  //--- set color
    ObjectSetInteger( GUI_aMainWINDOW, anInterimObjNAME, OBJPROP_BACK,          True );             //--- display in the foreground (false) or background (true) ~ FILL-IT ~
    ObjectSetInteger( GUI_aMainWINDOW, anInterimObjNAME, OBJPROP_SELECTABLE,    GUI_isSELECTABLE ); //---------------------------------------- MAY AVOID GUI interactions
    ObjectSetInteger( GUI_aMainWINDOW, anInterimObjNAME, OBJPROP_SELECTED,      False );            //--- set GUI-object as (non)-pre-SELECT-ed
    ObjectSetInteger( GUI_aMainWINDOW, anInterimObjNAME, OBJPROP_HIDDEN,        False );            //--- hide (true) or display (false) graphical object name in the object list
    ObjectSetInteger( GUI_aMainWINDOW, anInterimObjNAME, OBJPROP_ZORDER,        1 );                //--- set the "layered" priority for receiving a mouse-click-event in the chart
    // --------------------------------------------------------------------
    

    If in doubts, use the GUI objects dialogue-panels to experiment manually and derive the missing syntax explanation(s) in the language documentation.

    vju:

    May use a more complex & a way more risky approach:

    If the story is to become based on a Custom Indicator, the toys get a bit more complex.

    There is a hardcoded-engine, that processes data in a so called IndicatorBuffer.

    In case, a particular data element there happens to equal to EMPTY_VALUE a special handling is provided for those particular bars.

    Such EMPTY_VALUE constant signals to the processing-engine the values of indicators that are not shown in the chart, as did surprise you.

    For example, for a built-in indicator Standard Deviation with a period of 20, the line for the first 19 bars in the history are not shown in the chart at all, using this feature trick. The same might be used anywhere further, all the way to the current bar[0], even dynamically, so as to emulate "vibrations" :o) ( do not risk this in production ... ).

    This can also create "dropped" parts of the painted areas in aPriceDOMAIN displayed Custom Indicators.

    For painting area "between" two generic Custom Indicator lines ( between "oscilating" curves ), one has to employ a few more tricks, using:

    //--- plot dual-line-filled----------------------------------------------
    #property indicator_label   "DEMO-Custom-2-Line-Filled-Indicator" 
    #property indicator_type     DRAW_FILLING       // THE MAGIC FILL-STYLING
    #property indicator_color    clrAqua,clrSalmon  // THE MAGIC FILL-STYLING
    #property indicator_width    2
    
    //--- Custom Indicator buffers -----------------------------------------
    double         aCustomIndicatorLineDATA_buffer1[];
    double         aCustomIndicatorLineDATA_buffer2[];
    
    //--- Next, fill DATA as usually and the GUI shows the magic FILL-STYLING
    

    Anyway:

    Enjoy the Wild Worlds of MQL4/MQL5


    Interested? May also like reading other MQL4 and low-latency trading posts