consulente esperto - domande varie - pagina 25

 

Provo a dopo il trascinamento finitoOBJPROP_SELECTED potrebbe essere "falso" con il codice seguente, nessun effetto.

Come posso risolvere, per favore?

if(id==CHARTEVENT_OBJECT_DRAG)
  {
   SL_TPdrags();

   Sleep(1000);
   drag_onoff=false; // OBJPROP_SELECTED
  }

Grazie in anticipo.

 
Mi dispiace di non aver mai usato CHARTEVENT_OBJECT_DRAG.
 
Marco vd Heijden:
Mi dispiace di non aver mai usato CHARTEVENT_OBJECT_DRAG.
OK! Grazie comunque!
 

Alla fine della giornata, ho trovato "OBJ_RECTANGLE e OBJ_TEXT", che sto pensando che posso usare entrambi invece di "OBJ_LABEL e OBJ_RECTANGLE_LABEL" che entrambi muovono insieme la linea di offerta.

D: Quindi, quali oggetti sono molto utili per muovere insieme le linee di offerta, per favore?

Ho davvero bisogno di un commento informativo.
Buon fine settimana.

 

ID

Descrizione

OBJ_VLINE

Linea verticale

OBJ_HLINE

Linea orizzontale

OBJ_TREND

Linea di tendenza

OBJ_TRENDBYANGLE

Linea di tendenza per angolo

OBJ_CICLI

Linee del ciclo

OBJ_ARROWED_LINE

Linea a freccia

OBJ_CHANNEL

Canale equidistante

OBJ_STDDEVCHANNEL

Canale della deviazione standard

OBJ_REGRESSIONE

Canale di regressione lineare

OBJ_PITCHFORK

Andrews Pitchfork

OBJ_GANNLINE

Linea di Gann

OBJ_GANNFAN

Ventilatore di Gann

OBJ_GANNGRID

Griglia di Gann

OBJ_FIBO

Ritracciamento di Fibonacci

OBJ_FIBOTIMES

Zone temporali di Fibonacci

OBJ_FIBOFAN

Ventaglio di Fibonacci

OBJ_FIBOARC

Archi di Fibonacci

OBJ_FIBOCHANNEL

Canale di Fibonacci

OBJ_EXPANSION

Espansione di Fibonacci

OBJ_ELLIOTWAVE5

Onda motrice di Elliott

OBJ_ELLIOTWAVE3

Onda di correzione di Elliott

OBJ_RECTANGLE

Rettangolo

OBJ_TRIANGOLO

Triangolo

OBJ_ELLIPSE

Ellisse

FRECCIA IN ALTO

Pollice in su

OBJ_ARROW_THUMB_DOWN

Pollice giù

OBJ_ARROW_UP

Freccia su

OBJ_ARROW_DOWN

Freccia giù

OBJ_ARROW_STOP

Segno di stop

FRECCIA_CHECK

Segno di controllo

OBJ_ARROW_LEFT_PRICE

Etichetta del prezzo a sinistra

OBJ_ARROW_RIGHT_PRICE

Etichetta del prezzo di destra

OBJ_ARROW_BUY

Segno di acquisto

OBJ_ARROW_SELL

Segno di vendita

OBJ_ARROW

Freccia

OBJ_TEXT

Testo

OBJ_LABEL

Etichetta

OBJ_BUTTON

Pulsante

OBJ_CHART

Grafico

OBJ_BITMAP

Bitmap

ETICHETTA BITMAP

Etichetta bitmap

OBJ_EDIT

Modifica

OBJ_EVENTO

L'oggetto "Evento" corrispondente a un evento nel calendario economico

OBJ_RECTANGLE_LABEL

L'oggetto "Etichetta rettangolare" per creare e disegnare l'interfaccia grafica personalizzata.


Cosa intendevi per spostare insieme?

 
Max Enrik:

Provo a dopo il trascinamento finitoOBJPROP_SELECTED potrebbe essere "falso" con il codice seguente, nessun effetto.

Come posso risolvere, per favore?

if(id==CHARTEVENT_OBJECT_DRAG)
  {
   SL_TPdrags();

   Sleep(1000);
   drag_onoff=false; // OBJPROP_SELECTED
  }

Grazie in anticipo.

A meno che tu non stia testando sparam più in alto, quel codice si attiva quando qualsiasi l'oggetto viene trascinato.

Il mio codice originale:

void OnChartEvent(const int id, const long& lparam, const double& dparam, const string& sparam)
  {
   if(id==CHARTEVENT_OBJECT_DRAG && sparam=="line") // the chart event of dragging the line
 
@Marco vd Heijden

Conosco già / leggo il tuo uno dei grandi esempi CrossHair.mq4.
Ma sto lottando per dare il prezzo di Bid a Label, RectLabel Objects. Cioè sto cercando di Label, RectLabel Objects si muove con Bid Line insieme.

Ho solo bisogno di un'immagine, si prega di trovare il file allegato.

Tutto il meglio.

 

Per gli oggetti a dimensione fissa: OBJ_BUTTON, OBJ_RECTANGLE_LABEL e OBJ_EDIT, le proprietà OBJPROP_XDISTANCE e OBJPROP_YDISTANCE impostano la posizione del punto in alto a sinistra dell'oggetto rispetto all'angolo del grafico (OBJPROP_CORNER), dal quale le coordinate X e Y saranno contate in pixel.

//+------------------------------------------------------------------+
//|                                                    rectangle.mq4 |
//|      Copyright 2017, Marco vd Heijden, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, Marco vd Heijden, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer
   EventSetTimer(1);
//--- create rectangle
   RectangleCreate(0,"Rectangle",0,0,0);  
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
   EventKillTimer();
      
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   RectanglePointChange(0,"Rectangle",0,TimeCurrent(),Ask);
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
  
  }
//+------------------------------------------------------------------+
//| Create rectangle by the given coordinates                        |
//+------------------------------------------------------------------+
bool RectangleCreate(const long            chart_ID=0,        // chart's ID
                     const string          name="Rectangle",  // rectangle name
                     const int             sub_window=0,      // subwindow index
                     datetime              time1=0,           // first point time
                     double                price1=0,          // first point price
                     datetime              time2=0,           // second point time
                     double                price2=0,          // second point price
                     const color           clr=clrRed,        // rectangle color
                     const ENUM_LINE_STYLE style=STYLE_SOLID, // style of rectangle lines
                     const int             width=1,           // width of rectangle lines
                     const bool            fill=false,        // filling rectangle with color
                     const bool            back=false,        // in the background
                     const bool            selection=true,    // highlight to move
                     const bool            hidden=true,       // hidden in the object list
                     const long            z_order=0)         // priority for mouse click
  {
//--- set anchor points' coordinates if they are not set
   ChangeRectangleEmptyPoints(time1,price1,time2,price2);
//--- reset the error value
   ResetLastError();
//--- create a rectangle by the given coordinates
   if(!ObjectCreate(chart_ID,name,OBJ_RECTANGLE,sub_window,time1,price1,time2,price2))
     {
      Print(__FUNCTION__,
            ": failed to create a rectangle! Error code = ",GetLastError());
      return(false);
     }
//--- set rectangle color
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//--- set the style of rectangle lines
   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);
//--- set width of the rectangle lines
   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);
//--- display in the foreground (false) or background (true)
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
//--- enable (true) or disable (false) the mode of highlighting the rectangle for moving
//--- when creating a graphical object using ObjectCreate function, the object cannot be
//--- highlighted and moved by default. Inside this method, selection parameter
//--- is true by default making it possible to highlight and move the object
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
//--- hide (true) or display (false) graphical object name in the object list
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
//--- set the priority for receiving the event of a mouse click in the chart
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
//--- successful execution
   return(true);
  }
//+------------------------------------------------------------------+
//| Move the rectangle anchor point                                  |
//+------------------------------------------------------------------+
bool RectanglePointChange(const long   chart_ID=0,       // chart's ID
                          const string name="Rectangle", // rectangle name
                          const int    point_index=0,    // anchor point index
                          datetime     time=0,           // anchor point time coordinate
                          double       price=0)          // anchor point price coordinate
  {
//--- if point position is not set, move it to the current bar having Bid price
   if(!time)
      time=TimeCurrent();
   if(!price)
      price=SymbolInfoDouble(Symbol(),SYMBOL_BID);
//--- reset the error value
   ResetLastError();
//--- move the anchor point
   if(!ObjectMove(chart_ID,name,point_index,time,price))
     {
      Print(__FUNCTION__,
            ": failed to move the anchor point! Error code = ",GetLastError());
      return(false);
     }
//--- successful execution
   return(true);
  }
//+------------------------------------------------------------------+
//| Check the values of rectangle's anchor points and set default    |
//| values for empty ones                                            |
//+------------------------------------------------------------------+
void ChangeRectangleEmptyPoints(datetime &time1,double &price1,
                                datetime &time2,double &price2)
  {
//--- if the first point's time is not set, it will be on the current bar
   if(!time1)
      time1=TimeCurrent();
//--- if the first point's price is not set, it will have Bid value
   if(!price1)
      price1=SymbolInfoDouble(Symbol(),SYMBOL_BID);
//--- if the second point's time is not set, it is located 9 bars left from the second one
   if(!time2)
     {
      //--- array for receiving the open time of the last 10 bars
      datetime temp[10];
      CopyTime(Symbol(),Period(),time1,10,temp);
      //--- set the second point 9 bars left from the first one
      time2=temp[0];
     }
//--- if the second point's price is not set, move it 300 points lower than the first one
   if(!price2)
      price2=price1-300*SymbolInfoDouble(Symbol(),SYMBOL_POINT);
  }
//+------------------------------------------------------------------+
 
honest_knave:

A meno che tu non stia testando sparam più in alto, quel codice si attiva quando qualsiasi oggetto viene trascinato.
Il mio codice originale:

void OnChartEvent(const int id, const long& lparam, const double& dparam, const string& sparam)
  {
   if(id==CHARTEVENT_OBJECT_DRAG && sparam=="line") // the chart event of dragging the line
Ho già provato come sotto il codice.
if(id==CHARTEVENT_OBJECT_DRAG && sparam=="#"+IntegerToString(OrderTicket())+"-TP")
  {
// here was my functions
  }

Questa non era una risposta a me.

---

Ma io uso come sotto il codice che è io piccolo cambiamento il tuo codice per me - e funziona perfettamente per me che voglio. Finora non ho affrontato alcun problema.
Sto facendo male, per favore?

if(id==CHARTEVENT_OBJECT_DRAG){}

Tutto il meglio.

 

Forse questo vi aiuterà.

Aggiungete questo a un grafico e vedrete:

  • Un allarme ogni volta che la linea è stata spostata (con il nuovo prezzo).
  • Nessun ritardo tra lo spostamento della linea e l'allarme.
  • Nessun allarme quando si muove qualcos'altro.
  • Nessun allarme mentre la linea viene effettivamente spostata.

#property strict
#property indicator_chart_window

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   ObjectCreate(0,"MyLine",OBJ_HLINE,0,0,Bid);
   ObjectSetInteger(0,"MyLine",OBJPROP_SELECTED,true);
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   ObjectDelete(0,"MyLine");  
  }

//+------------------------------------------------------------------+
//| OnChartEvent()                                                   |

//+------------------------------------------------------------------+
void
OnChartEvent(const int id,
                  const long& lparam,
                  const double& dparam,
                  const string& sparam)
  {
   if(id==CHARTEVENT_OBJECT_DRAG && sparam=="MyLine")
     {
      double price=ObjectGetDouble(0,"MyLine",OBJPROP_PRICE,0);
      Alert("MyLine moved! New price is " + DoubleToStr(price,_Digits));
     }
  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {

   return(rates_total);
  }
Motivazione: