Testo all'interno dell'indicatore

 

È possibile vedere un esempio di come inserire un testo all'interno di un indicatore (finestra separata)?

Grazie

 
supermagix   :

È possibile vedere un esempio di come inserire un testo all'interno di un indicatore (finestra separata)?

Grazie


Ho provato


if(ObjectFind(0,label_name)<0)
     {
      Print("Generating a label");
      ObjectCreate(0,label_name,OBJ_LABEL,0,0,0);           
      ObjectSetInteger(0,label_name,OBJPROP_XDISTANCE,10);
      ObjectSetInteger(0,label_name,OBJPROP_YDISTANCE,30);
      ObjectSetInteger(0,label_name,OBJPROP_COLOR,YellowGreen);
      ObjectSetString(0,label_name,OBJPROP_TEXT,"This is an example text inside chart window");
      ObjectSetString(0,label_name,OBJPROP_FONT,"Arial");
      ObjectSetInteger(0,label_name,OBJPROP_FONTSIZE,14);
      ObjectSetInteger(0,label_name,OBJPROP_SELECTABLE,false);
      ChartRedraw(0);                                      
     }
     
   int window=-1;
 
   if((ENUM_PROGRAM_TYPE)MQL5InfoInteger(MQL5_PROGRAM_TYPE)==PROGRAM_INDICATOR)
     {
      window=ChartWindowFind();
      Print(window);
     }
     
     if(ObjectFind(window,label2_name)<0)
     {
      Print("Generating a label2");
      ObjectCreate(window,label2_name,OBJ_LABEL,0,0,0);       
      Print(GetLastError());    
      ObjectSetInteger(window,label2_name,OBJPROP_XDISTANCE,10);
      ObjectSetInteger(window,label2_name,OBJPROP_YDISTANCE,30);
      ObjectSetInteger(window,label2_name,OBJPROP_COLOR,YellowGreen);
      ObjectSetString(window,label2_name,OBJPROP_TEXT,"This is an example text inside indicator, cool, huh?");
      ObjectSetString(window,label2_name,OBJPROP_FONT,"Arial");
      ObjectSetInteger(window,label2_name,OBJPROP_FONTSIZE,14);
      ObjectSetInteger(window,label2_name,OBJPROP_SELECTABLE,false);
      ChartRedraw(window);                                      
     }


ma

ObjectCreate(window,label2_name,OBJ_LABEL,0,0,0); 


restituisce l'errore 4101


qualche idea? (MT5 build 237)

 
investeo   :


Ho provato



ma


restituisce l'errore 4101


qualche idea? (MT5 build 237)


Questo è il risultato il testo appare:

http://clip2net.com/clip/m19204/1263295278-clip-38kb.png

solo nel grafico ma non nell'indicatore.

Se qualcuno vuole aiutarmi a caricare il codice dell'indicatore.

Accetto volentieri suggerimenti e modifiche.....

Grazie investeo

File:
mycci.mq5  6 kb
 
supermagix   :


Questo è il risultato che il testo appare:

http://clip2net.com/clip/m19204/1263295278-clip-38kb.png

solo nel grafico ma non nell'indicatore.

Se qualcuno vuole aiutarmi a caricare il codice dell'indicatore.

Accetto volentieri suggerimenti e modifiche.....

Grazie investeo


Ho provato diverse configurazioni è risultato che QUALSIASI OGGETTO non è consentito all'interno delle finestre dell'indicatore in MT5


vedi


https://www.mql5.com/en/docs/index


La sezione Indicatore personalizzato dice:


L'indicatore personalizzatoè un indicatore tecnico scritto in modo indipendente in aggiunta a quelli già integrati nel terminale client. Come gli indicatori integrati, non possono fare trading automatico e sono destinati esclusivamente all'implementazione di funzioni analitiche.

Gli indicatori personalizzati non possono usare funzioni per lavorare con grafici o oggetti grafici . Gliindicatori personalizzati sono memorizzati in terminal_directory\MQL5\Indicators


Pertanto, l'unico modo per inserire del testo nella finestra dell'indicatore è impostando la sua proprietà INDICATOR_SHORTNAME.


per esempio

IndicatorSetString(INDICATOR_SHORTNAME, "Hello "+label2_name+"...");


Correggimi se mi sbaglio.

i migliori saluti

MQL5 Documentation
  • www.mql5.com
MQL5 Documentation
 
investeo:

Gli indicatori personalizzati non possono usare funzioni per lavorare con gra fici o oggetti grafici . Gliindicatori personalizzati sono memorizzati in terminal_directory\MQL5\Indicators


Al momento è possibile. Prova per favore.
 

Ti chiedo un favore: potresti scrivere un esempio?

Grazie

 
Rosh:
Al momento è possibile. Prova per favore.


Rosh, ho provato a realizzarlo usando la build 238 ma ancora nessuna fortuna. Questo frammento di codice


#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
#property indicator_minimum 0
#property indicator_maximum 100


string label_name="mainwindow_label";
string label2_name="indicator_label";
int window=-1;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
//---
    
   return(0);
  }
//+------------------------------------------------------------------+
//| 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 value of prev_calculated for next call
   
   if(ObjectFind(0,label_name)<0)
     {
      Print("Generating a label");
      ObjectCreate(0,label_name,OBJ_LABEL,0,0,0);           
      ObjectSetInteger(0,label_name,OBJPROP_XDISTANCE,10);
      ObjectSetInteger(0,label_name,OBJPROP_YDISTANCE,30);
      ObjectSetInteger(0,label_name,OBJPROP_COLOR,YellowGreen);
      ObjectSetString(0,label_name,OBJPROP_TEXT,"This is an example text inside chart window");
      ObjectSetString(0,label_name,OBJPROP_FONT,"Arial");
      ObjectSetInteger(0,label_name,OBJPROP_FONTSIZE,14);
      ObjectSetInteger(0,label_name,OBJPROP_SELECTABLE,false);
      ChartRedraw(0);                                      
     }
     
   
 
   if((ENUM_PROGRAM_TYPE)MQL5InfoInteger(MQL5_PROGRAM_TYPE)==PROGRAM_INDICATOR)
     {
      window=ChartWindowFind();
      Print(window);
     }
     
     if(ObjectFind(window,label2_name)<0)
     {
      Print("Generating a label2");
      ObjectCreate(window,label2_name,OBJ_LABEL,0,0,0);       
      Print(GetLastError());    
      ObjectSetInteger(window,label2_name,OBJPROP_XDISTANCE,10);
      ObjectSetInteger(window,label2_name,OBJPROP_YDISTANCE,10);
      ObjectSetInteger(window,label2_name,OBJPROP_COLOR,YellowGreen);
      ObjectSetString(window,label2_name,OBJPROP_TEXT,"This is an example text inside indicator, cool, huh?");
      ObjectSetString(window,label2_name,OBJPROP_FONT,"Arial");
      ObjectSetInteger(window,label2_name,OBJPROP_FONTSIZE,14);
      ObjectSetInteger(window,label2_name,OBJPROP_SELECTABLE,false);
      ChartRedraw(window);                                      
     }
     
   IndicatorSetString(INDICATOR_SHORTNAME,"Hello "+label2_name+"...");
   
   return(rates_total);
}
  
void OnDeinit(const int reason)
{
   if(ObjectFind(0,label_name)>=0)
      ObjectDelete(0,label_name);
   if(ObjectFind(window,label2_name)>=0)
      ObjectDelete(window,label2_name);
      
}


cerca di mettere 2 oggetti (etichette), uno sulla finestra principale del grafico e il secondo sulla finestra dell'indicatore.


if((ENUM_PROGRAM_TYPE)MQL5InfoInteger(MQL5_PROGRAM_TYPE)==PROGRAM_INDICATOR)
     {
      window=ChartWindowFind();
      Print(window);
     }


La variabile window è impostata su 1 per la finestra dell'indicatore, e quello che vedo quando eseguo l'indicatore è



E


Print("Generating a label2");
      ObjectCreate(window,label2_name,OBJ_LABEL,0,0,0);       
      Print(GetLastError()); 


GetLastError restituisce il valore '4101'

 

Prova il mio indicatore di esempio

//+------------------------------------------------------------------+
//|                                       testObjectsInIndicator.mq5 |
//|                        Copyright 2009, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   1
//---- plot Bollinger
#property indicator_label1  "BB High; BB Low"
#property indicator_type1   DRAW_FILLING
#property indicator_color1  Magenta,LimeGreen
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- input parameters
input int      BBperiod=20;            // период BBands
input int      length=30;              // длина канала
input double   width=2.0;              // ширина BBands
input color    channelColor=Turquoise; // цвет канала
//--- indicator buffers
double         BollingerBuffer1[];
double         BollingerBuffer2[];
int handleBBands;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,BollingerBuffer1,INDICATOR_DATA);
   SetIndexBuffer(1,BollingerBuffer2,INDICATOR_DATA);
   handleBBands=iBands(NULL,0,BBperiod,0,width,PRICE_CLOSE);
//---
   Print("Function ",__FUNCTION__,"  Build ",__MQ5BUILD__);
   return(0);
  }
//+------------------------------------------------------------------+
//| 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[])
  {
//---
   static int prevbars=-1;
//int bars=Bars(NULL,0);
   int copied=CopyBuffer(handleBBands,1,0,rates_total,BollingerBuffer1);
   if(copied<=0)
     {
      Print("Copying of indicator values failed");
      return(0);
     }

   copied=CopyBuffer(handleBBands,2,0,rates_total,BollingerBuffer2);
   if(copied<=0)
     {
      Print("Copying of indicator values failed");
      return(0);
     }
   if(prevbars!=rates_total)
     {
      prevbars=rates_total;
      ArraySetAsSeries(time,true);
      SetupChannel(time[length],time[1]);
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void SetupChannel(datetime time1,datetime time2)
  {
   static string channelName="Channel";
   static string startLine="start";
   static string finishLine="finish";

   if(ObjectFind(0,channelName)<0)
     {
      Print("Channel not found, let's create it");
      if(!ObjectCreate(0,channelName,OBJ_STDDEVCHANNEL,0,0,0))
         Print("Channel creation failed error =",GetLastError());
      else
        {
         ObjectSetInteger(0,channelName,OBJPROP_COLOR,channelColor);
         Print("Set channel beginning at",time1);
         ObjectSetInteger(0,channelName,OBJPROP_TIME,0,time1);
         Print("Set channel finish at",time2);
         bool modified=ObjectSetInteger(0,channelName,OBJPROP_TIME,1,time2);
         if(!modified)
           {
            Print("Can not to set up time coordinates. Error",GetLastError());
           }
         Print("Move channel on background");
         ObjectSetInteger(0,channelName,OBJPROP_BACK,true);

        }
     }

   if(ObjectFind(0,startLine)<0)
     {
      Print("Линия start не найдена, создадим сами");
      if(!ObjectCreate(0,startLine,OBJ_VLINE,0,time1,0))
         Print("Не удалось создать линию startLine, error =",GetLastError());
     }
   if(ObjectFind(0,finishLine)<0)
     {
      Print("Линия finish не найдена, создадим сами");
      if(!ObjectCreate(0,finishLine,OBJ_VLINE,0,time2,0))
         Print("Не удалось создать линию finishLine, error =",GetLastError());
     }

  }
//+------------------------------------------------------------------+
 
Rosh:

Prova il mio indicatore di esempio



Il tuo indicatore funziona correttamente, ma traccia gli oggetti sul grafico principale, non sulla finestra separata (vogliamo avere un oggetto disegnato sulla finestra separata dell'indicatore). Quando uso


#property indicator_separate_window


invece di


#property indicator_chart_window


(come nel tuo esempio)


e imposto

ObjectCreate(1,startLine,OBJ_VLINE,0,time1,0)


ottengo i seguenti output di errore


2010.01.14 16:11:40     testObjectOnIndicator (EURUSD,M5)       Не удалось создать линию finishLine, error = 4101
2010.01.14 16:11:40     testObjectOnIndicator (EURUSD,M5)       Линия finish не найдена, создадим сами
2010.01.14 16:11:40     testObjectOnIndicator (EURUSD,M5)       Не удалось создать линию startLine, error = 4101
2010.01.14 16:11:40     testObjectOnIndicator (EURUSD,M5)       Линия start не найдена, создадим сами
2010.01.14 16:11:40     testObjectOnIndicator (EURUSD,M5)       Channel creation failed error = 4101
2010.01.14 16:11:40     testObjectOnIndicator (EURUSD,M5)       Channel not found, let's create it
2010.01.14 16:11:40     testObjectOnIndicator (EURUSD,M5)       Function  OnInit   Build  223


il primo parametro ("1") nel metodo Object Create è un valore restituito da ChartWindowFind():



if((ENUM_PROGRAM_TYPE)MQL5InfoInteger(MQL5_PROGRAM_TYPE)==PROGRAM_INDICATOR)
     {
      window=ChartWindowFind();
     }

):


come suggerito qui : https://www.mql5.com/en/docs/chart_operations/chartwindowfind

Documentation on MQL5: Chart Operations / ChartWindowFind
  • www.mql5.com
Chart Operations / ChartWindowFind - Documentation on MQL5
 
è possibile vedere un esempio che funzioni?...... applicato a un indicatore separato qualsiasi ? grazie
 
supermagix:
è possibile vedere un esempio che funzioni?...... applicato a un indicatore separato qualsiasi ? grazie
//+------------------------------------------------------------------+
//|                                       testObjectsInIndicator.mq5 |
//|                        Copyright 2009, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2009, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots   1
//---- plot Bollinger
#property indicator_label1  "BB High; BB Low"
#property indicator_type1   DRAW_FILLING
#property indicator_color1  Magenta,LimeGreen
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- input parameters
input int      BBperiod=20;            // период BBands
input int      length=30;              // длина канала
input double   width=2.0;              // ширина BBands
input color    channelColor=Turquoise; // цвет канала
//--- indicator buffers
double         BollingerBuffer1[];
double         BollingerBuffer2[];
int            handleBBands;
//---
int            window=1;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- get window number
   window=ChartWindowFind();
//--- indicator buffers mapping
   SetIndexBuffer(0,BollingerBuffer1,INDICATOR_DATA);
   SetIndexBuffer(1,BollingerBuffer2,INDICATOR_DATA);
   handleBBands=iBands(NULL,0,BBperiod,0,width,PRICE_CLOSE);
//---
   Print("Function ",__FUNCTION__,"  Build ",__MQ5BUILD__);
   return(0);
  }
//+------------------------------------------------------------------+
//| 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[])
  {
//---
   static int prevbars=-1;
//int bars=Bars(NULL,0);
   int copied=CopyBuffer(handleBBands,1,0,rates_total,BollingerBuffer1);
   if(copied<=0)
     {
      Print("Copying of indicator values failed");
      return(0);
     }

   copied=CopyBuffer(handleBBands,2,0,rates_total,BollingerBuffer2);
   if(copied<=0)
     {
      Print("Copying of indicator values failed");
      return(0);
     }
   if(prevbars!=rates_total)
     {
      prevbars=rates_total;
      ArraySetAsSeries(time,true);
      SetupChannel(time[length],time[1]);
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void SetupChannel(datetime time1,datetime time2)
  {
   static string channelName="Channel";
   static string startLine="start";
   static string finishLine="finish";

   if(ObjectFind(0,channelName)<0)
     {
      Print("Channel not found, let's create it");
      if(!ObjectCreate(0,channelName,OBJ_STDDEVCHANNEL,window,0,0))
         Print("Channel creation failed error =",GetLastError());
      else
        {
         ObjectSetInteger(0,channelName,OBJPROP_COLOR,channelColor);
         Print("Set channel beginning at",time1);
         ObjectSetInteger(0,channelName,OBJPROP_TIME,0,time1);
         Print("Set channel finish at",time2);
         bool modified=ObjectSetInteger(0,channelName,OBJPROP_TIME,1,time2);
         if(!modified)
           {
            Print("Can not to set up time coordinates. Error",GetLastError());
           }
         Print("Move channel on background");
         ObjectSetInteger(0,channelName,OBJPROP_BACK,true);

        }
     }

   if(ObjectFind(0,startLine)<0)
     {
      Print("Линия start не найдена, создадим сами");
      if(!ObjectCreate(0,startLine,OBJ_VLINE,window,time1,0))
         Print("Не удалось создать линию startLine, error =",GetLastError());
     }
   if(ObjectFind(0,finishLine)<0)
     {
      Print("Линия finish не найдена, создадим сами");
      if(!ObjectCreate(0,finishLine,OBJ_VLINE,window,time2,0))
         Print("Не удалось создать линию finishLine, error =",GetLastError());
     }

  }
//+------------------------------------------------------------------+

Motivazione: