Gösterge içindeki metin - sayfa 5

 

Teşekkürler wald99 : deniyorum.

Metaquotes'a mq5'e özgü, mümkünse bazı videolarla birlikte, tabanlardan (sözdiziminden) başlayan bir kurs oluşturmasını öneririm: bu, programlamaya yeni başlayanlar için çok yararlıdır.

Birçok kişinin MT5 ile ilgilendiğini ancak programlamayı bilmediğini düşünüyorum.
 
walb99 :

Merhaba Investeo

çok teşekkürler, kodunuz çalışıyor, yani etiket görünüyor, ancak değer güncellenmiyor. Bir hata mı yaptım?

İşte kodum.


valb99,


Bunu dene. Sorun, değeri yalnızca etiket nesnesi mevcut değilse güncellemeye çalışmanızdır. Etikete zaman damgası ekledim, böylece her tik ile zamanın güncellendiğini görebilirsiniz.


 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[])
{
         int limit;
         if (CountBars >= rates_total) limit = 0 ; else limit = rates_total - CountBars; 
        

         CopyBuffer (ma1_handle, 0 , 0 , rates_total, MA1TempBuffer);
        

         for ( int i = rates_total - 1 ; i > limit; i--)
        {
                MA1Buffer[i] = MA1TempBuffer[i];
           double myMA_now = MA1TempBuffer[i];
                 double myMA_previous = MA1TempBuffer[i - 1 ]; //MA One bar ago
                
                
                 
                 if (myMA_now >= myMA_previous) MA1ColorBuffer[i] = 0 ;
                 else if (myMA_now < myMA_previous) MA1ColorBuffer[i] = 1 ;
                        
        }
                

        myMAnow=MA1TempBuffer[rates_total- 1 -MA1_Shift]; 
       // myMAnow=MA1TempBuffer[rates_total - 1]; 
        


          
   myPrice = SymbolInfoDouble ( _Symbol , SYMBOL_BID );
   
   if (myPrice>myMAnow)label_color= Lime ;   else label_color= Red ; 

   
   


   // check if label object does not already exist and create it
 
   if ( ObjectFind ( 0 ,label_info)< 0 )
  {
       // Create label in indicator's window 
       ObjectCreate ( 0 ,label_info, OBJ_LABEL ,window, 0 , 0 ); 
         // Set X and Y distance from UPPER RIGHT CORNER      
       ObjectSetInteger ( 0 ,label_info, OBJPROP_XDISTANCE , 200 );
       ObjectSetInteger ( 0 ,label_info, OBJPROP_YDISTANCE , 20 );
       ObjectSetInteger ( 0 ,label_info, OBJPROP_CORNER , CORNER_RIGHT_UPPER ); 
          
       // Set text properties: colour, font and font size
       ObjectSetInteger ( 0 ,label_info, OBJPROP_COLOR ,label_color);
       ObjectSetString ( 0 ,label_info, OBJPROP_FONT , "Arial" );
       ObjectSetInteger ( 0 ,label_info, OBJPROP_FONTSIZE , 14 );   
    
       // Set text to display
       ObjectSetString ( 0 ,label_info, OBJPROP_TEXT , DoubleToString (myMAnow,nDigits));

      
     
  } else 
  {
       ObjectSetString ( 0 ,label_info, OBJPROP_TEXT , TimeToString ( TimeCurrent (), TIME_SECONDS)+ " " + DoubleToString (myMAnow,nDigits));
  }; 
  

 
         return (rates_total);
}
  
 
investeo :


valb99,


Bunu dene. Sorun, değeri yalnızca etiket nesnesi mevcut değilse güncellemeye çalışmanızdır. Etikete zaman damgası ekledim, böylece her tik ile zamanın güncellendiğini görebilirsiniz.


Teşekkürler, bu işe yarıyor

parantez içine etiket rengi hakkında da bilgi koyarsam, etiket rengi de düzgün bir şekilde güncellenir.

 } else 
  {
       ObjectSetInteger ( 0 ,label_info, OBJPROP_COLOR ,label_color);
       ObjectSetString ( 0 ,label_info, OBJPROP_TEXT , TimeToString ( TimeCurrent (), TIME_SECONDS)+ " " + DoubleToString (myMAnow,nDigits));
  }; 
  
 

Yukarıdaki rsi örneğinde bu nesne adını nereye atarsınız? kodun tamamını okudum ama anlamadım

Sadece gösterge pencerelerine basit bir metin koymak istiyorum, yukarıdaki RSI örneğindeki gibi aynı sonucu alamıyorum

Kodum:

 //+------------------------------------------------------------------+
//|                                                    text win .mq5 |
//|                                           Copyright CREATE BY DK |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "CREATE BY DK"
#property link       "http://www.mql5.com"
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot mv1
#property indicator_label1   "mv1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  Red
#property indicator_style1  STYLE_SOLID
#property indicator_width1   1
//--- input parameters
input int       mv1= 20 ;
//--- indicator buffers
double          mv1Buffer[];
int       mahandle;

string objectname = "text" ;
int windows;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit ()
  {
//--- indicator buffers mapping
   SetIndexBuffer ( 0 ,mv1Buffer, INDICATOR_DATA );
   windows = ChartWindowFind ( 0 ,objectname);
  
   // IndicatorSetString(INDICATOR_SHORTNAME,"Text window");

//---
   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[])
  {
//---
int i ;
i=rates_total;
mahandle = iMA ( NULL , PERIOD_CURRENT ,mv1, 0 , MODE_SMA , PRICE_CLOSE );
if ( CopyBuffer (mahandle, 0 , 0 ,rates_total,mv1Buffer)<= 0 )
{
Print ( "getting errors somewhere" , GetLastError ());
return ( 0 );
}

ObjectCreate ( 0 ,objectname, OBJ_TEXT ,windows, 0 , 0 );
ObjectSetString ( 0 ,objectname, OBJPROP_TEXT , "check it out" );
ObjectSetInteger ( 0 ,objectname, OBJPROP_COLOR , Red );
//ObjectSetInteger(0,objectname,OBJPROP_XDISTANCE,1480);
//ObjectSetInteger(0,objectname,OBJPROP_YDISTANCE,100);
ObjectSetString ( 0 , "Name" , OBJPROP_FONT , "Arial" );
   ObjectSetInteger ( 0 , "Name" , OBJPROP_FONTSIZE , 20 );
   ObjectSetInteger ( 0 , "Name" , OBJPROP_XDISTANCE , 1480 );
   ObjectSetInteger ( 0 , "Name" , OBJPROP_YDISTANCE , 450 );

//--- return value of prev_calculated for next call
   return (rates_total);
  }
//+------------------------------------------------------------------+

sonuç :

 

tamam, sanırım sadece metni göstererek işe yaradım, sonra göstergeyle çalışacağım. ama biri bana metni göstermek için neden obj_text yerine obj_label kullanamadığımı söyleyebilir mi?

 //+------------------------------------------------------------------+
//|                                                   text win 2.mq5 |
//|                                           Copyright CREATE BY DK |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "CREATE BY DK"
#property link       "http://www.mql5.com"
#property version   "1.00"
#property indicator_separate_window
#property indicator_plots 1

string ddock = "try it out" ;
int windows = - 1 ;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit ()
  {
//--- indicator buffers mapping
/*
if ((ENUM_PROGRAM_TYPE)MQL5InfoInteger(MQL5_PROGRAM_TYPE)==PROGRAM_INDICATOR)
windows=ChartWindowFind();


if (ObjectFind(0,ddock)<0)
{
   ObjectCreate(0,ddock,OBJ_LABEL,windows,0,0);
   ObjectSetInteger(0,ddock,OBJPROP_XDISTANCE,200);
   ObjectSetInteger(0,ddock,OBJPROP_YDISTANCE,20);
   ObjectSetInteger(0,ddock,OBJPROP_CORNER, CORNER_RIGHT_UPPER);
   ObjectSetInteger(0,ddock,OBJPROP_COLOR,LightBlue);
   ObjectSetString(0,ddock,OBJPROP_FONT,"Arial");
   ObjectSetInteger(0,ddock,OBJPROP_FONTSIZE,14);
   ObjectSetString(0,ddock,OBJPROP_TEXT, "TRYING VERY HARD");
}
else
Print("ddock already exists");
*/

/*
  if((ENUM_PROGRAM_TYPE)MQL5InfoInteger(MQL5_PROGRAM_TYPE)==PROGRAM_INDICATOR)
     windows=ChartWindowFind();
*/

   // check if label object does not already exist and create it
   if ( ObjectFind ( 0 ,ddock)< 0 )
  {
       // Create label in indicator's window
       ObjectCreate ( 0 ,ddock, OBJ_TEXT ,windows, 0 , 0 );        
       // Set X and Y distance from UPPER RIGHT CORNER
       ObjectSetInteger ( 0 ,ddock, OBJPROP_XDISTANCE , 200 );
       ObjectSetInteger ( 0 ,ddock, OBJPROP_YDISTANCE , 20 );
       ObjectSetInteger ( 0 ,ddock, OBJPROP_CORNER , CORNER_RIGHT_UPPER );
       // Set text properties: colour, font and font size
       ObjectSetInteger ( 0 ,ddock, OBJPROP_COLOR , LightPink );
       ObjectSetString ( 0 ,ddock, OBJPROP_FONT , "Arial" );
       ObjectSetInteger ( 0 ,ddock, OBJPROP_FONTSIZE , 14 );
       // Set text to display
       ObjectSetString ( 0 ,ddock, OBJPROP_TEXT , "TRYING VERY HARD" );
  } else Print ( "ddock already exists" );
  

//---
   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
   return (rates_total);
  }
//+------------------------------------------------------------------+
/* void OnDeinit(const int reason)
{
if (!ObjectFind(0,ddock)<0)
ObjectDelete(0,ddock);
}
/* void OnDeinit(const int reason)
  {
//---
  if(!ObjectFind(0,ddock)<0)
      ObjectDelete(0, ddock);
  } */