william007
william007

Reputation: 18537

How to draw a rectangle around a set of candles in a Custom Indicator?

Say I have two candles that satisfy a property, I want to draw a rectangle around them, like in the following picture under, in a Custom Indicator.

What should I do?

The SetIndexStyle() does not seem to have this option.

enter image description here

Upvotes: 1

Views: 1939

Answers (1)

user3666197
user3666197

Reputation: 1

Doable ( but not via any of the Custom Indicator line-formatting services )

Given the said above,
the rectangle placement & formatting ought be programmed explicitly, best using a principal, re-useable GUI-object handling function template idea like this:

void UpdateRECTANGLE( int      const     anObjIdNUM,
                      datetime const       fromTIME,
                      datetime const         toTIME,
                      double   const      fromPRICE,
                      double   const        toPRICE,
                      color    const         aCOLOR = clrDarkBlue,
                      int      const aLineTHICKNESS = 2,
                      int      const      aLineTYPE = STYLE_SOLID,
                      ){
#define aMainWINDOW   0

     string                         anInterimObjNAME = StringFormat( "GUI_RECTANGLE[%6d]", anObjIdNUM );
     if (  ObjectFind(              anInterimObjNAME ) == aMainWINDOW )
           ObjectDelete(            anInterimObjNAME );
     else: ObjectCreate( ChartID(), anInterimObjNAME, OBJ_RECTANGLE, 0, fromTIME, fromPRICE,
                                                                          toTIME,   toPRICE
                                                                          );         
     ObjectSet( anInterimObjNAME, OBJPROP_COLOR,         aCOLOR );
     ObjectSet( anInterimObjNAME, OBJPROP_BACK,          True );
     ObjectSet( anInterimObjNAME, OBJPROP_WIDTH,         aLineTHICKNESS );
     ObjectSet( anInterimObjNAME, OBJPROP_STYLE,         aLineTYPE );
     ObjectSet( anInterimObjNAME, OBJPROP_SELECTABLE,    GUI_SELECTABLE ); // ----------------------------------------- AVOIDS GUI interactions
     ObjectSet( anInterimObjNAME, OBJPROP_SELECTED,      False );
     return;
}

Epilogue:
one may also be aware, the Custom Indicator is a bit risky piece of code to place any heavy-lifting processing, convoluted TimeSeries re-counting, external AI/ML-code transactions handling into, because, all, yes all MetaTrader Terminal graphs all share, yes, indeed, all SHARE a single thread ( and one can imagine, what a blocking / long hanging processing may cause to all dependent processes, if all ( again, YES, ALL ) have to wait, till a single, shared, blocking thread gets enough CPU-clocks to finish processing of all the queue of requests all other graphs' experts and their dependent Custom Indicator calls have placed in front of our call request.
Does not sound risky to your ears? Believe me, it is... A lot!

Upvotes: 0

Related Questions