MQL4 ve MQL5 ile ilgili herhangi bir acemi sorusu, algoritmalar ve kodlar hakkında yardım ve tartışma - sayfa 1539

 
//+------------------------------------------------------------------+
//|                                                  MACD Sample.mq4 |
//|                   Copyright 2005-2014, MetaQuotes Software Corp. |
//|                                               http://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright    "2005-2014, MetaQuotes Software Corp."
#property link          " http://www.mql4.com "
input double TakeProfit    = 2190 ;
input double Lots          = 0.5 ;
input double TrailingStop  = 650 ;
input int OpenLevel = 70 ;
input int CloseLevel= 23 ;
input int      Period = 86 ;
input int     Period1 = 87 ;
int LastBars= 0 ;
extern int Magic1 = 110721 ;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick ( void )
  {
   
 
   int     cnt,ticket,total;
//---
// initial data checks
// it is important to make sure that the expert works with a normal
// chart and the user did not make any mistakes setting external 
// variables (Lots, StopLoss, TakeProfit, 
// TrailingStop) in our case, we check TakeProfit
// on a chart of less than 100 bars
//---
//--- Trade only if new bar has arrived
   if (LastBars!= Bars ) LastBars= Bars ;
   else return ( 0 );
   if ( Bars < 100 )
     {
       Print ( "bars less than 100" );
       return ;
     }
   if (TakeProfit< 10 )
     {
       Print ( "TakeProfit less than 10" );
       return ;
     }
//--- to simplify the coding and speed up access data are put into internal variables
   if (CountOrders( "" , - 1 ,Magic1)< 1 )
     
   total= OrdersTotal ();
   if (total< 1 )
     {
       //--- no opened orders identified
       if (AccountFreeMargin()<( 1000 *Lots))
        {
         Print ( "We have no money. Free Margin = " ,AccountFreeMargin());
         return ;
        }
       //--- check for long position (BUY) possibility
     if ( iRSI ( NULL , 0 ,OpenLevel, PRICE_LOW , Period )> iRSI ( NULL , 0 ,CloseLevel, PRICE_HIGH ,Period1)) 
        {
         ticket= OrderSend ( Symbol (),OP_BUY,Lots,Ask, 3 ,Bid-TakeProfit* Point ,Bid+TakeProfit* Point , "GBPCADD" ,Magic1, 0 ,Green);
         if (ticket> 0 )
           {
             if ( OrderSelect (ticket,SELECT_BY_TICKET,MODE_TRADES))
               Print ( "BUY order opened : " ,OrderOpenPrice());
           }
         else
             Print ( "Error opening BUY order : " , GetLastError ());
         return ;
        }
       //--- check for short position (SELL) possibility
       if ( iRSI ( NULL , 0 ,OpenLevel, PRICE_LOW ,Period1)< iRSI ( NULL , 0 ,CloseLevel, PRICE_HIGH , Period )) 
        {
         ticket= OrderSend ( Symbol (),OP_SELL,Lots,Bid, 3 ,Ask+TakeProfit* Point ,Ask-TakeProfit* Point , "GBPCADD" ,Magic1, 0 ,Red);
         if (ticket> 0 )
           {
             if ( OrderSelect (ticket,SELECT_BY_TICKET,MODE_TRADES))
               Print ( "SELL order opened : " ,OrderOpenPrice());
           }
         else
             Print ( "Error opening SELL order : " , GetLastError ());
        }
       //--- exit from the "no opened orders" block
       return ;
     }
//--- it is important to enter the market correctly, but it is more important to exit it correctly...   
   for (cnt= 0 ;cnt<total;cnt++)
     {
       if (! OrderSelect (cnt,SELECT_BY_POS,MODE_TRADES))
         continue ;
       if (OrderType()<=OP_SELL &&   // check for opened position 
         OrderSymbol()== Symbol ()&& OrderMagicNumber()==Magic1)   // check for symbol
        {
         //--- long position is opened
         if (OrderType()==OP_BUY)
           {
             //--- should it be closed?
               if ( iRSI ( NULL , 0 ,OpenLevel, PRICE_LOW ,Period1)< iRSI ( NULL , 0 ,CloseLevel, PRICE_HIGH , Period )) 
              {
               //--- close order and exit
               if (!OrderClose(OrderTicket(),OrderLots(),Bid, 3 ,Violet))
                   Print ( "OrderClose error " , GetLastError ());
               return ;
              }
             //--- check for trailing stop
             if (TrailingStop> 0 )
              {
               if (Bid-OrderOpenPrice()> Point *TrailingStop)
                 {
                   if (OrderStopLoss()<Bid- Point *TrailingStop)
                    {
                     //--- modify order and exit
                     if (!OrderModify(OrderTicket(),OrderOpenPrice(),Bid- Point *TrailingStop,OrderTakeProfit(), 0 ,Green))
                         Print ( "OrderModify error " , GetLastError ());
                     return ;
                    }
                 }
              }
           }
         else // go to short position
           {
             //--- should it be closed?
           if ( iRSI ( NULL , 0 ,OpenLevel, PRICE_LOW , Period )> iRSI ( NULL , 0 ,CloseLevel, PRICE_HIGH ,Period1)) 
              {
               //--- close order and exit
               if (!OrderClose(OrderTicket(),OrderLots(),Ask, 3 ,Violet))
                   Print ( "OrderClose error " , GetLastError ());
               return ;
              }
             //--- check for trailing stop
             if (TrailingStop> 0 )
              {
               if ((OrderOpenPrice()-Ask)>( Point *TrailingStop))
                 {
                   if ((OrderStopLoss()>(Ask+ Point *TrailingStop)) || (OrderStopLoss()== 0 ))
                    {
                     //--- modify order and exit
                     if (!OrderModify(OrderTicket(),OrderOpenPrice(),Ask+ Point *TrailingStop,OrderTakeProfit(), 0 ,Red))
                         Print ( "OrderModify error " , GetLastError ());
                     return ;
                    }
                 }
              }
           }
        }
     }
//---
  }
//+------------------------------------------------------------------+
//+----------------------------------------------------------------------------+
//| Подсчет ордеров                                                            |
//+----------------------------------------------------------------------------+
//| -1 - Все типы ордеров                                                      |
//|  0 - ордера типа BUY                                                       |
//|  1 - ордера типа SELL                                                      |
//|  2 - ордера типа BUYLIMIT                                                  |
//|  3 - ордера типа SELLLIMIT                                                 |
//|  4 - ордера типа BUYSTOP                                                   |
//|  5 - ордера типа SELLSTOP                                                  |
//+----------------------------------------------------------------------------+
int CountOrders( string symb= "" , int or_ty=- 1 , int magiс=- 1 ) 
  {
   int cnt= 0 ;
   if (symb== "0" ) symb= _Symbol ;
   for ( int pos= OrdersTotal ()- 1 ;pos>= 0 ;pos--)
     {
       if ( OrderSelect (pos,SELECT_BY_POS)== true )
        {
         if ((OrderSymbol()==symb || symb== "" )&&(or_ty< 0 || or_ty==OrderType()))
           {
             if (magiс< 0 || OrderMagicNumber()==magiс) cnt++;
           }
        }
     }
   return (cnt);
  }

Peki doğru olacak mı?

 
darirunu1 :

Peki doğru olacak mı?

 //--- to simplify the coding and speed up access data are put into internal variables
   if (CountOrders( "" , - 1 ,Magic1)< 1 )
     
   total= OrdersTotal ();
   if (total< 1 )
 
MakarFX :

Teşekkür ederim Bu zor bir seçenek Her şeyi daha basit hale getirdim, sadece birkaç satır.

 
darirunu1 :

Teşekkür ederim Bu zor bir seçenek Her şeyi daha basit hale getirdim, sadece birkaç satır.

sakıncası yoksa görmek ilginç
 
MakarFX :
sakıncası yoksa görmek ilginç

for(i=k; i>=0; i--) {

if( OrderSelect (i,SELECT_BY_POS,MODE_TRADES)) {

if(OrderSymbol()==Symbol()) {

if(OrderMagicNumber() == Sihirli) {

if(OrderType()>1) devam ediyor;

if(OrderType()==OP_BUY || OrderType()==OP_SELL) toplam++;

}}}}

//---

// toplam=SiparişToplam();

if(toplam<1)

{

 

Merhaba! Kendi işlev kitaplığımı oluşturmak istedim çünkü robotlarımda genellikle aynı işlevleri kullanıyorum. Her şey doğru yapılmış gibiydi. Bir kitaplık oluşturdu, Kitaplıklar klasörüne attı, göstergedeki kitaplığı #import ile bağladı

#import "andylib.ex4"

bool KeyPr(uzun l, k dizisi);

string TestFunc();

#içe aktarmak

Bir açıklama ile kitaplıkta belirtilen işlevler. Ancak kütüphanedeki işlevler çağrılmaz. İncil'i göstergeler klasörüne ve hatta doğrudan İncil ile iletişim kuran göstergenin bulunduğu yere atmaya çalıştım, sonuçsuz. Ne yanlış olabilir?

 
Евгений Гуцу :

Merhaba! Kendi işlev kitaplığımı oluşturmak istedim çünkü robotlarımda genellikle aynı işlevleri kullanıyorum. Her şey doğru yapılmış gibiydi. Bir kitaplık oluşturdu, Kitaplıklar klasörüne attı, göstergedeki kitaplığı #import ile bağladı

#import "andylib.ex4"

bool KeyPr(uzun l, k dizisi);

string TestFunc();

#içe aktarmak

Bir açıklama ile kitaplıkta belirtilen işlevler. Ancak kütüphanedeki işlevler çağrılmaz. İncil'i göstergeler klasörüne ve hatta doğrudan İncil ile iletişim kuran göstergenin bulunduğu yere atmaya çalıştım, sonuçsuz. Ne yanlış olabilir?

Dahil etmek

Документация по MQL5: Основы языка / Препроцессор / Включение файлов (#include)
Документация по MQL5: Основы языка / Препроцессор / Включение файлов (#include)
  • www.mql5.com
Включение файлов (#include) - Препроцессор - Основы языка - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
darirunu1 :

for(i=k; i>=0; i--) {

if(OrderSelect (i,SELECT_BY_POS,MODE_TRADES)) {

if(OrderSymbol()==Symbol()) {

if(OrderMagicNumber() == Sihirli) {

if(OrderType()>1) devam ediyor;

if(OrderType()==OP_BUY || OrderType()==OP_SEL) toplam++;

}}}}

//---

// toplam=SiparişToplam();

if(toplam<1)

{

Yazdıklarınız işe yaramayabilir.

Önce "toplam++" hesaplayın ve ardından sıfırlayın ve "OrdersTotal()" değerini ayarlayın, yani. tüm siparişler

 
Евгений Гуцу :

Merhaba! Kendi işlev kitaplığımı oluşturmak istedim çünkü robotlarımda genellikle aynı işlevleri kullanıyorum. Her şey doğru yapılmış gibiydi. Bir kitaplık oluşturdu, Kitaplıklar klasörüne attı, göstergedeki kitaplığı #import ile bağladı

#import "andylib.ex4"

bool KeyPr(uzun l, k dizisi);

string TestFunc();

#içe aktarmak

Bir açıklama ile kitaplıkta belirtilen işlevler. Ancak kütüphanedeki işlevler çağrılmaz. İncil'i gösterge klasörüne ve hatta doğrudan İncil ile iletişim kuran göstergenin bulunduğu yere atmaya çalıştım, sonuçsuz. Ne yanlış olabilir?

Kütüphanede fonksiyon adından sonra export yazmayı unuttunuz mu?

Ve bir kitaplık değil, bir sınıf olmadan bile işlevlerin sıkıştırılacağı bir .mqh dosyası yapmak daha iyidir ve derleme sırasında yalnızca EA/göstergeden erişilebilen gerekli olanlar alınacaktır.
 
Her bir çift için ayrı ayrı MT5'te açık siparişler için komisyon nasıl hesaplanır? çözümü olan var mı
Neden: