uzman danışman - çeşitli sorular - sayfa 21

 
Marco vd Heijden :

Veya sürükleme algılandığında bir sayaç başlatabilirsiniz , bunu yapmanın birçok yolu vardır .,

( Şimdilik bunu benim için yapmanın bir yolu var - son yorumunuzda bu şekilde)
Bay Marco günümü kurtardın, çok teşekkürler dostum.

Şimdilik değil ama bu ' SL ve TP ' işlevlerine ek olarak birkaç işlev eklemek istediğimi daha sonra deneyeceğim. Bunun için senaryo yazmaya başlamadan önce gerçekten bununla ilgili birçok şeyi araştırmam gerekiyor.

Senin için en iyisi adamım!

 

Doğru hatırlıyorsam - uzun zaman önce bir tane " Order Modifier " EA'nın şu şekilde çalıştığını görmüştüm: hangisi sürüklerken güncellenmiyordu, "Sürükle KAPAT" dediğimde çizgiyi sürükledikten sonra " Zararı Durdur Kar Al ". değerler sadece bir kez değişebilir.
Bu yüzden, en son yorumunuzu üç ve daha fazla kez okudum ve ayrıca sürüklerken güncellemeleri durdurabilmem için biraz daha değiştirmeyi denedim.

S: Yani mümkün değil mi, lütfen?

Şimdiden teşekkürler.

 

Boole bayrağı sürükle == 1 olduğu sürece, güncellemeleri devre dışı bırakmak için aynı bayrağı kullanabilirsiniz.

Dediğim gibi bir sayaç da başlatabilirsiniz işte buna bir örnek:

//+------------------------------------------------------------------+
//|                                                  Drag Hline2.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

double price;
bool drag;
int cnt= 0 ;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit ()
  {
//--- create timer
   EventSetTimer ( 1 );
   ObjectCreate ( 0 , "line" , OBJ_HLINE , 0 , 0 , Ask );
   price= ObjectGetDouble ( 0 , "line" , OBJPROP_PRICE , 0 );
//---
   return ( INIT_SUCCEEDED );
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit ( const int reason)
  {
//--- destroy timer
   EventKillTimer ();

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick ()
  {
//---

  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer ()
  {
//---
   if (price!= ObjectGetDouble ( 0 , "line" , OBJPROP_PRICE , 0 ))
     {
      drag= 1 ;
     }

   if (drag== 1 )
     {
      cnt++;       // increase counter
        {
         if (cnt>= 2 ) // if counter == 2 seconds
           {
            price= ObjectGetDouble ( 0 , "line" , OBJPROP_PRICE , 0 ); // store new value
             Print ( " New price: " , DoubleToString (price));
             PlaySound ( "ok.wav" );
            cnt= 0 ;   // reset counter
            drag= 0 ; // reset drag
           }
        }
     }
  }
//+------------------------------------------------------------------+

Veya sadece bir while döngüsü kullanın, bu çok iyi çalışıyor:

//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer ()
  {
//---
   while (price!= ObjectGetDouble ( 0 , "line" , OBJPROP_PRICE , 0 ))
    {
     PlaySound ( "ok.wav" );
     price= ObjectGetDouble ( 0 , "line" , OBJPROP_PRICE , 0 );
     Comment (price);
    }
  }
//+------------------------------------------------------------------+
Sadece (sürüklediğimde) fiyatı ikisi eşit olana kadar güncelle (sürüklemeyi bıraktığımda) söylüyor
 
Marco vd Heijden :

Boole bayrağı sürükle == 1 olduğu sürece, güncellemeleri devre dışı bırakmak için aynı bayrağı kullanabilirsiniz.
Dediğim gibi bir sayaç da başlatabilirsiniz işte buna bir örnek:
Veya sadece bir while döngüsü kullanın, bu çok iyi çalışıyor:
Sadece (sürüklediğimde) fiyatı ikisi eşit olana kadar güncelle (sürüklemeyi bıraktığımda) söylüyor

(ve kodlarınız)

Ne parlak örnekler adamım?! Gerçekten çok çok faydalı bir yorum , çok teşekkürler. Ve şimdi bu satırlar için daha fazla şey eklemeye çalışıyorum (tasarımlar ve işlevler ).
(Lütfen bu sorum için beni suçlamayın: Grafik nesneler için kullandığım "graphics() " var ve onu Init() aracılığıyla arıyorum ve OnTimer() aracılığıyla çağırmam gerekiyor, bu yüzden Sorum şu: Yanlış mı yapıyorum lütfen? )

Senin için her şeyin en iyisini dilerim!

 

Zaten var olduğu için nesne oluşturamayan 4200 hatasıyla karşılaşabilirsiniz.

Bu nedenle, onu (yeniden) yaratmaya veya değiştirmeye çalışmadan önce nesnenin var olup olmadığını görmelisiniz.

Kullanabilirsiniz:

   if ( ObjectFind ( 0 , "Long" )< 0 )
     {
       //Object does not exist

     }
  
and/or

   if ( ObjectFind ( 0 , "Long" )>= 0 )
     {
       // Object already exists
    
     }
 
Marco vd Heijden :

Kullanabilirsiniz:

Hmm, bu benim için gerçekten yeni bir İşlev .
Bunu araştırdıktan sonra deneyebilirim. ( Çok kez gördüm ama benim için hiç kullanmadım. )

Çok teşekkürler.

 

#Fiyatı Piksele Dönüştür - Aç

Kâr Al işlevi için “HLine” kullanıyorum.
Birkaç nesnem var ( Label, RecLabel... vb ) ve nesnelerin "HLine" nesnesi ile hareket edebilmesini istiyorum. Bu yüzden fonksiyonun altında bulundum. Ama " X "i dönüştürmek istemem. Yalnızca Fiyatı Y'ye dönüştürmek istiyorum.
Aşağıdaki kodla hiçbir şey denemedim.
S:
Çünkü bu endişem için bana yardımcı olabileceğinden emin olmak istiyorum?
(Bana yardımcı olabileceğini biliyorsam, endişem için denemeye başlayacağım).
S: Ve bazı nesnelerin "HLine" ile hareket edebilmesi için herhangi bir yöntem var mı?

// this is just example for that what I am thinking
datetime time = 0 ; // I just want to ignore this because I just want to give to X = 20; fixed mode ( should not change ever )
double price = ObjectGetDouble ( 0 , "line" , OBJPROP_PRICE , 0 );

int x,y;

ChartTimePriceToXY ( long chart_id, int sub_window, datetime time, double price, int & x, int & y );

Şimdiden teşekkürler.

 

Biraz daha spesifik olmanız gerekecek, birçok şeyi birçok şekilde yapabilirsiniz.

Bu işlevler OnChartEvent() işlevinde kullanılır.

ChartPriceToXY - size fiyat zamanını koordinatlara dönüştürecek, gerçekten ihtiyacınız olan bu mu?

Belki ChartXYToTimePrice () demek istiyorsun?

https://www.mql5.com/en/docs/chart_operations/chartxytotimeprice

Değere ihtiyacınız yoksa, onu sıfır olarak iletebilirsiniz, aşağıdaki örneğe bakın.

//+------------------------------------------------------------------+
//|                                                    CrossHair.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 some lines
   ObjectCreate ( 0 , "X" , OBJ_HLINE , 0 , 0 , Ask );           // X = Horizontal Axis (time==0)
   ObjectCreate ( 0 , "Y" , OBJ_VLINE , 0 , TimeCurrent (), 0 ); // Y = Vertical Axis (price==0)      
//---
   return ( INIT_SUCCEEDED );
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit ( const int reason)
  {
//--- clean up  
   ObjectsDeleteAll ( 0 , 0 , EMPTY );  
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick ()
  {
//---
  
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent ( const int id,
                   const long &lparam,
                   const double &dparam,
                   const string &sparam)
  {
//--- If this is an event of a mouse click on the chart
   if (id== CHARTEVENT_CLICK )
     {
       //--- Prepare variables
       int       x     =( int )lparam;
       int       y     =( int )dparam;
       datetime time  = 0 ;
       double    price = 0 ;
       int       window= 0 ;
       //--- Convert the X and Y coordinates in terms of date/time
       if ( ChartXYToTimePrice ( 0 ,x,y,window,time,price))
        {
         ObjectMove ( 0 , "X" , 0 , 0 ,price); // notice time==0 because horizontal axis
         ObjectMove ( 0 , "Y" , 0 ,time, 0 );  // notice price==0 because vertical axis
        }
       else
         Print ( "ChartXYToTimePrice return error code: " , GetLastError ());
       Print ( "+--------------------------------------------------------------+" );
     }
  }  
//+------------------------------------------------------------------+



Documentation on MQL5: Chart Operations / ChartXYToTimePrice
Documentation on MQL5: Chart Operations / ChartXYToTimePrice
  • www.mql5.com
Chart Operations / ChartXYToTimePrice - Reference on algorithmic/automated trading language for MetaTrader 5
 

Bu belgeleri zaten okudum ama en son yorumunuza kadar net bir şekilde anlayamadım. Aslında ama henüz denemedim, çünkü kodun altında zorlanıyorum, zaten iyi sonuçlar için birkaç yol denedim ama yapamam.
Bay Marco
, en son harika yorumunuz için teşekkür ederim, ki bunu nesnelerimin hareket etme sorunu için kullanabileceğimi hissediyorum.

Gerçekten endişeme çözüm bulmak için çok zaman harcadım, iyi sonuçlar alamıyorum.
Ama yine de alabiliyorum ( şu anda açık olan pozisyonlar ) " Hline " yapmak istediğim Kar Al Fiyatlar, nesneler Kar Al fiyatları diyebilir ve bu işe yarıyor. Ve sadece ilk zamanlarda çalışır. Evet biliyorum çünkü " Init() " içinde. Ama onu " OnTimer() " içine koymayı denedim ama id düzgün çalışmıyor.

Lütfen ne öğrenebileceğimi anlamama ve bu sorunum için yapmama yardımcı olacak bir şey bildirin.
7 saat sonra bu konu hakkında tekrar araştırmaya başlayacağım.
İyi bir yorum alırsam benim için daha iyi olacak.

// init()------------------------------------------------------------

for ( i = OrdersTotal () - 1 ; i >= 0 ; i-- )
{
     if   ( ! OrderSelect ( i, SELECT_BY_POS , MODE_TRADES ) ) continue ;
     if   ( OrderSymbol () == Symbol () ) tpprice = OrderTakeProfit ();

     ObjectCreate     (
                         "#" + IntegerToString ( OrderTicket () ) + " -" + "tphline" , // name
                         OBJ_HLINE ,
                         0 ,       // subwindow
                         0 ,       // time
                        tpprice // price1
                    );
    tpprice =
     ObjectGetDouble (
                         0 ,
                         "#" + IntegerToString ( OrderTicket () ) + " -" + "tphline" , // name
                         OBJPROP_PRICE , 0
                    );

}
// ontimer() --------------------------------------------------------

if   ( tpprice != ObjectGetDouble ( 0 , "#" + IntegerToString ( OrderTicket () ) + " -" + "tphline" , OBJPROP_PRICE , 0 ) )
{
    tpdrag = 1 ;
}

if   ( tpdrag == 1 )
{
    tpprice = ObjectGetDouble ( 0 , "#" + IntegerToString ( OrderTicket () ) + " -" + "tphline" , OBJPROP_PRICE , 0 );
     Print ( "tpdrag: " , tpdrag, " - Price: " , DoubleToString ( tpprice, Digits ) );

     // actually here is a graphical objects functin()
     // here one of them
     // also which one soon I will try to  below objects could moves together " tphline " - but I can't take a time to research about your latest comment and so...
     ObjectCreate ( "recl object" , OBJ_RECTANGLE , 0 , 0 , tpprice ); // I feel I could add something to " string name " - I already tried few things not good results

    tpdrag = 0 ;
}

//---
return ;

Şimdiden teşekkürler.
Senin için her şeyin en iyisini dilerim!

 

Lütfen Araçlar sekmesinin altındaki şekillendiriciyi kullanın.

Neyi başarmaya çalıştığın hakkında hiçbir fikrim yok, bu yüzden ne yapmak istediğini tahmin etmem gerekiyor, bu asla iyi değil.

Ancak buradaki örneğe bakabilirsiniz:

//+------------------------------------------------------------------+
//|                                                    Stealth 4.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

static input int takeprofit= 500 ; // Take Profit
static input int stoploss= 500 ;   // Stop Loss

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit ()
  {
//--- create timer
   EventSetTimer ( 1 );

//---
   return ( INIT_SUCCEEDED );
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit ( const int reason)
  {
//--- destroy timer
   EventKillTimer ();

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick ()
  {
//---

  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer ()
  {
   for ( int order= OrdersTotal (); order>= 0 ; order--)
     {
       bool selected= OrderSelect (order, SELECT_BY_POS );
        {
         if (selected== 1 )
           {
             if ( Symbol ()== OrderSymbol ()) // only for current chart symbol
              {
               switch ( OrderType ())
                 {
                   case OP_BUY : // for buy order
                    {
                     // if objects not found - create them
                     if ( ObjectFind ( 0 , "#" + IntegerToString ( OrderTicket ())+ "-TP" )< 0 )
                       {
                         ObjectCreate ( 0 , "#" + IntegerToString ( OrderTicket ())+ "-TP" , OBJ_HLINE , 0 , 0 , OrderOpenPrice ()+takeprofit* Point ());
                         ObjectSet ( "#" + IntegerToString ( OrderTicket ())+ "-TP" , 7 , 3 );
                       }
                     if ( ObjectFind ( 0 , "#" + IntegerToString ( OrderTicket ())+ "-SL" )< 0 )
                       {
                         ObjectCreate ( 0 , "#" + IntegerToString ( OrderTicket ())+ "-SL" , OBJ_HLINE , 0 , 0 , OrderOpenPrice ()-stoploss* Point ());
                         ObjectSet ( "#" + IntegerToString ( OrderTicket ())+ "-SL" , 7 , 3 );
                       }
                     // if objects exist
                     if ( ObjectFind ( 0 , "#" + IntegerToString ( OrderTicket ())+ "-TP" )>= 0 )
                       {
                         if ( Bid > ObjectGetDouble ( 0 , "#" + IntegerToString ( OrderTicket ())+ "-TP" , OBJPROP_PRICE , 0 ))
                          {
                           bool close= OrderClose ( OrderTicket (), OrderLots (), OrderClosePrice (), 3 , clrBlue );
                             {
                               if (close== 0 )
                                {
                                 Alert ( " Order Close Error! # " + IntegerToString ( OrderTicket ()));
                                }
                               if (close== 1 )
                                {
                                 Alert ( " Order: " + IntegerToString ( OrderTicket ())+ " Closed due to TP Profit = " + DoubleToString ( OrderProfit (), 2 ));
                                 ObjectDelete ( 0 , "#" + IntegerToString ( OrderTicket ())+ "-TP" );
                                 ObjectDelete ( 0 , "#" + IntegerToString ( OrderTicket ())+ "-SL" );
                                }
                             }
                          }
                       }
                     if ( ObjectFind ( 0 , "#" + IntegerToString ( OrderTicket ())+ "-SL" )>= 0 )
                       {
                         if ( Ask < ObjectGetDouble ( 0 , "#" + IntegerToString ( OrderTicket ())+ "-SL" , OBJPROP_PRICE , 0 ))
                          {
                           bool close= OrderClose ( OrderTicket (), OrderLots (), OrderClosePrice (), 3 , clrBlue );
                             {
                               if (close== 0 )
                                {
                                 Alert ( " Order Close Error! # " + IntegerToString ( OrderTicket ()));
                                }
                               if (close== 1 )
                                {
                                 Alert ( " Order: " + IntegerToString ( OrderTicket ())+ " Closed due to SL Profit = " + DoubleToString ( OrderProfit (), 2 ));
                                 ObjectDelete ( 0 , "#" + IntegerToString ( OrderTicket ())+ "-TP" );
                                 ObjectDelete ( 0 , "#" + IntegerToString ( OrderTicket ())+ "-SL" );
                                }
                             }
                          }
                       }
                    }
                   break ;

                   case OP_SELL : // for sell order
                    {
                     // if objects not found - create them
                     if ( ObjectFind ( 0 , "#" + IntegerToString ( OrderTicket ())+ "-TP" )< 0 )
                       {
                         ObjectCreate ( 0 , "#" + IntegerToString ( OrderTicket ())+ "-TP" , OBJ_HLINE , 0 , 0 , OrderOpenPrice ()-takeprofit* Point ());
                         ObjectSet ( "#" + IntegerToString ( OrderTicket ())+ "-TP" , 7 , 3 );
                       }
                     if ( ObjectFind ( 0 , "#" + IntegerToString ( OrderTicket ())+ "-SL" )< 0 )
                       {
                         ObjectCreate ( 0 , "#" + IntegerToString ( OrderTicket ())+ "-SL" , OBJ_HLINE , 0 , 0 , OrderOpenPrice ()+stoploss* Point ());
                         ObjectSet ( "#" + IntegerToString ( OrderTicket ())+ "-SL" , 7 , 3 );
                       }
                     // if objects exist
                     if ( ObjectFind ( 0 , "#" + IntegerToString ( OrderTicket ())+ "-TP" )>= 0 )
                       {
                         if ( Ask < ObjectGetDouble ( 0 , "#" + IntegerToString ( OrderTicket ())+ "-TP" , OBJPROP_PRICE , 0 ))
                          {
                           bool close= OrderClose ( OrderTicket (), OrderLots (), OrderClosePrice (), 3 , clrBlue );
                             {
                               if (close== 0 )
                                {
                                 Alert ( " Order Close Error! # " + IntegerToString ( OrderTicket ()));
                                }
                               if (close== 1 )
                                {
                                 Alert ( " Order: " + IntegerToString ( OrderTicket ())+ " Closed due to TP Profit = " + DoubleToString ( OrderProfit (), 2 ));
                                 ObjectDelete ( 0 , "#" + IntegerToString ( OrderTicket ())+ "-TP" );
                                 ObjectDelete ( 0 , "#" + IntegerToString ( OrderTicket ())+ "-SL" );
                                }
                             }
                          }
                       }
                     if ( ObjectFind ( 0 , "#" + IntegerToString ( OrderTicket ())+ "-SL" )>= 0 )
                       {
                         if ( Bid > ObjectGetDouble ( 0 , "#" + IntegerToString ( OrderTicket ())+ "-SL" , OBJPROP_PRICE , 0 ))
                          {
                           bool close= OrderClose ( OrderTicket (), OrderLots (), OrderClosePrice (), 3 , clrBlue );
                             {
                               if (close== 0 )
                                {
                                 Alert ( " Order Close Error! # " + IntegerToString ( OrderTicket ()));
                                }
                               if (close== 1 )
                                {
                                 Alert ( " Order: " + IntegerToString ( OrderTicket ())+ " Closed due to SL Profit = " + DoubleToString ( OrderProfit (), 2 ));
                                 ObjectDelete ( 0 , "#" + IntegerToString ( OrderTicket ())+ "-TP" );
                                 ObjectDelete ( 0 , "#" + IntegerToString ( OrderTicket ())+ "-SL" );
                                }
                             }
                          }
                       }
                    }
                   break ;
                 }
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+


Böylece ObjectGetDouble'ı doğrudan kullanabileceğinizi görebilirsiniz, değeri başka bir double'a kopyalamanıza gerek yoktur çünkü nesnenin kendisi değeri tutar ve satırı sürüklediğinizde bu değer otomatik olarak değişir ve bir sonraki okuduğunuzda görülecektir. O.