Metodi di Binding Ogetti

Graphical objects Text, Label, Bitmap and Bitmap Label (OBJ_TEXT, OBJ_LABEL, OBJ_BITMAP and OBJ_BITMAP_LABEL) can have one of the 9 different ways of coordinate binding defined by the OBJPROP_ANCHOR property.

Object

ID

X/Y

Width/Height

Date/Price

OBJPROP_CORNER

OBJPROP_ANCHOR

OBJPROP_ANGLE

Text

OBJ_TEXT

Yes

Yes

Yes

Label

OBJ_LABEL

Yes

Yes (read only)

Yes

Yes

Yes

Button

OBJ_BUTTON

Yes

Yes

Yes

Bitmap

OBJ_BITMAP

Yes (read only)

Yes

Yes

Bitmap Label

OBJ_BITMAP_LABEL

Yes

Yes (read only)

Yes

Yes

Edit

OBJ_EDIT

Yes

Yes

Yes

Rectangle Label

OBJ_RECTANGLE_LABEL

Yes

Yes

Yes

The following designations are used in the table:

  • X/Y – coordinates of anchor points specified in pixels relative to a chart corner;
  • Width/Height – objects have width and height. For "read only", the width and height values are calculated only once the object is rendered on chart;
  • Date/Price – anchor point coordinates are specified using the date and price values;
  • OBJPROP_CORNER – defines the chart corner relative to which the anchor point coordinates are specified. Can be one of the 4 values of the ENUM_BASE_CORNER enumeration;
  • OBJPROP_ANCHOR – defines the anchor point in object itself and can be one of the 9 values of the ENUM_ANCHOR_POINT enumeration. Coordinates in pixels are specified from this very point to selected chart corner;
  • OBJPROP_ANGLE – defines the object rotation angle counterclockwise.

La variante necessaria può essere specificata usando la funzione ObjectSetInteger(Chart_handle, object_name, OBJPROP_ANCHOR, Anchor_point_mode), dove anchor_point_mode è uno dei valori di ENUM_ANCHOR_POINT.

ENUM_ANCHOR_POINT

ID

Descrizione

ANCHOR_LEFT_UPPER

Punto di ancoraggio in alto a sinistra

ANCHOR_LEFT

Punto di ancoraggio a sinistra nel centro

ANCHOR_LEFT_LOWER

Punto di ancoraggio nell'angolo in basso a sinistra

ANCHOR_LOWER

Punto di ancoraggio sotto sotto nel centro

ANCHOR_RIGHT_LOWER

Punto di ancoraggio nell'angolo in basso a destra

ANCHOR_RIGHT

Punto di ancoraggio a destra al centro

ANCHOR_RIGHT_UPPER

Punto di ancoraggio in alto a destra

ANCHOR_UPPER

Punto di ancoraggio sopra nel centro

ANCHOR_CENTER

Punto di ancoraggio strettamente nel centro dell'oggetto

The OBJ_BUTTON, OBJ_RECTANGLE_LABEL, OBJ_EDIT and OBJ_CHART objects have a fixed anchor point in the upper left corner (ANCHOR_LEFT_UPPER).

Esempio:

   string text_name="my_OBJ_TEXT_object";
   if(ObjectFind(0,text_name)<0)
     {
      Print("Object ",text_name," non trovato. Error code = ",GetLastError());
      //--- Ottiene il prezzo massimo del grafico
      double chart_max_price=ChartGetDouble(0,CHART_PRICE_MAX,0);
      //--- Crea etichetta dell'oggetto
      ObjectCreate(0,text_name,OBJ_TEXT,0,TimeCurrent(),chart_max_price);
      //--- Imposta colore del testo
      ObjectSetInteger(0,text_name,OBJPROP_COLOR,clrWhite);
      //--- Imposta colore background
      ObjectSetInteger(0,text_name,OBJPROP_BGCOLOR,clrGreen);
      //--- Imposta il testo per l'oggetto grafico Etichetta
      ObjectSetString(0,text_name,OBJPROP_TEXT,TimeToString(TimeCurrent()));
      //--- Imposta font del testo
      ObjectSetString(0,text_name,OBJPROP_FONT,"Trebuchet MS");
      //--- Imposta la grandezza del font
      ObjectSetInteger(0,text_name,OBJPROP_FONTSIZE,10);
      //--- Associazione all'angolo supriore destro
      ObjectSetInteger(0,text_name,OBJPROP_ANCHOR,ANCHOR_RIGHT_UPPER);
      //--- Ruota di 90 gradi in senso antiorario
      ObjectSetDouble(0,text_name,OBJPROP_ANGLE,90);
      //--- Proibisce la selezione dell'oggetto dal mouse
      ObjectSetInteger(0,text_name,OBJPROP_SELECTABLE,false);
      //--- ridisegna oggetto
      ChartRedraw(0);
     }

Gli oggetti grafici Freccia (OBJ_ARROW) hanno solo 2 modi di collegamento delle loro coordinate. Gli identificatori sono elencati in ENUM_ARROW_ANCHOR.

ENUM_ARROW_ANCHOR

ID

Descrizione

ANCHOR_TOP

Ancoraggio sul lato superiore

ANCHOR_BOTTOM

Ancoraggio sul lato inferiore

Esempio:

voidOnStart()
  {
//--- Array ausiliari
   double Ups[],Downs[];
   datetime Time[];
//--- Imposta gli array come timeseries
   ArraySetAsSeries(Ups,true);
   ArraySetAsSeries(Downs,true);
   ArraySetAsSeries(Time,true);
//--- Crea l'handle dell' Indicatore Fractals
   int FractalsHandle=iFractals(NULL,0);
   Print("FractalsHandle = ",FractalsHandle);
//-- Imposta il valore di Last error (ultimo errore) a Zero
   ResetLastError();
//--- Prova a copiare i valori dell'indicatore
   int copied=CopyBuffer(FractalsHandle,0,0,1000,Ups);
   if(copied<=0)
     {
      Print("Impossibile copiare i frattali superiori. Error = ",GetLastError());
      return;
     }
 
   ResetLastError();
//--- Prova a copiare i valori dell'indicatore
   copied=CopyBuffer(FractalsHandle,1,0,1000,Downs);
   if(copied<=0)
     {
      Print("Impossibile copiare i frattali inferiori. Error = ",GetLastError());
      return;
     }
 
   ResetLastError();
//--- Copia le timeseries contenenti le aperture delle ultime 1000
   copied=CopyTime(NULL,0,0,1000,Time);
   if(copied<=0)
     {
      Print("Impossibile copiare i valori Opening Time delle ultime 1000 barre");
      return;
     }
 
   int upcounter=0,downcounter=0; // conta li il numero di frecce 
   bool created;// riceve il risultato dei tentativi di creazione di un oggetto
   for(int i=2;i<copied;i++)// Esecuzione attraverso i valori dell'indicatore iFractals
     {
      if(Ups[i]!=EMPTY_VALUE)// Trova il frattale superiore
        {
         if(upcounter<10)// Crea non più di 10 frecce "Su"
           {
            //--- Prova a creare un oggetto "Su"
            created=ObjectCreate(0,string(Time[i]),OBJ_ARROW_THUMB_UP,0,Time[i],Ups[i]);
            if(created)// Se impostato - diamogli una regolata
              {
               //--- Il punto di ancoraggio è sotto per non coprire la barra
               ObjectSetInteger(0,string(Time[i]),OBJPROP_ANCHOR,ANCHOR_BOTTOM);
               //--- Tocco finale - disegnato
               ObjectSetInteger(0,string(Time[i]),OBJPROP_COLOR,clrBlue);
               upcounter++;
              }
           }
        }
      if(Downs[i]!=EMPTY_VALUE)// Trovato un frattale inferiore
        {
         if(downcounter<10)// Crea non più di 10 frecce "Giu"
           {
            //--- Prova a creare un oggetto "Giu"
            created=ObjectCreate(0,string(Time[i]),OBJ_ARROW_THUMB_DOWN,0,Time[i],Downs[i]);
            if(created)// Se impostato - diamogli una regolata
              {
               //--- Il punto di ancoraggio è sopra al fine di non coprire la barra
               ObjectSetInteger(0,string(Time[i]),OBJPROP_ANCHOR,ANCHOR_TOP);
               //--- Tocco finale - disegnato
               ObjectSetInteger(0,string(Time[i]),OBJPROP_COLOR,clrRed);
               downcounter++;
              }
           }
        }
     }
  }

Dopo l'esecuzione dello script il grafico sarà come in questa figura.

Piazza i marchi per valori frattali