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

 
Порт-моне тв : @MakarFX Ve sizinki nedense orada değil ve bu arada, daha önce denedim ve hatırlamıyorum! Her durumda, herkese teşekkürler. İyi ticaret!

Bir anlaşma açma kodunu gönderebilir misiniz, neden işe yaramadığını göreceğim

 
MakarFX :

Numara

parametre 0 bu çizelgeye ait olduğunu gösterir

işlevle karıştırdım özür dilerim

 StringFind 


  

 
MakarFX :

Bir anlaşma açma kodunu gönderebilir misiniz, neden işe yaramadığını göreceğim

 //+------------------------------------------------------------------+
//|                                         равноудаленный канал.mq4 |
//+------------------------------------------------------------------+
#property copyright ""
#property link        ""
#property version    "1.00"
#property strict

extern int Magic = 777701 ;
extern double Lot = 0.01 ;
extern int Slippage = 3 ;

 double pXa, pXb;
 int ticket;
 int OrderOfSymbol;



//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit ()
  {  
//---
   return ( INIT_SUCCEEDED );
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit ( const int reason)
  {
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick ()
  {
  
//---
   //Проверим что есть ли равноудаленный канал:
   if ( ObjectsTotal ( OBJ_RECTANGLE )== 0 )
   { Comment ( "Нарисуйте равноудаленный канал для открытия сделки по покупке!" );}

  
   //Получим ИМЯ прямоугольника:
   for ( int n= 0 ;n< ObjectsTotal ();n++)
     {
     
       string name= ObjectName (n);
       if (ObjectType(name)== OBJ_RECTANGLE )
       
        {
        
       if ( ObjectFind ( 0 , "BUY" )== 0 )
          {
          
         datetime t1a = ( datetime ) ObjectGet(name,OBJPROP_TIME1);
         datetime t2a = ( datetime ) ObjectGet(name,OBJPROP_TIME2);

         double p1a= NormalizeDouble (ObjectGet(name,OBJPROP_PRICE1), Digits );
         double p2a= NormalizeDouble (ObjectGet(name,OBJPROP_PRICE2), Digits );
 
         
     
      
 
         
    
         
         OrderOfSymbol=CounterOrderTradeType(- 1 ); 
           if (OrderOfSymbol< 1 )
           if (Close[ 1 ]>Open[ 1 ])    
         if ( TimeCurrent ()>t1a && TimeCurrent ()< t2a &&
            Bid < p1a  && Bid > p2a   )    
        {
         ticket = OrderSend ( Symbol (),OP_BUY, Lot, Ask, Slippage, 0 , 0 , "открыт ордер на покупку" , Magic, 0 , Blue);
        } 
       
           }
         
         
           }
           
           
           
        
           
           
           
     }
     
       //Проверим что есть ли уже равноудаленный канал и он в единственном экземпляре:
   if ( ObjectsTotal ( OBJ_RECTANGLE )== 1 )
   { Comment ( "Нарисуйте второй равноудаленный канал для закрытия сделки по покупке!" );}

     //Получим ИМЯ прямоугольника:
   for ( int n= 0 ;n< ObjectsTotal ();n++)
     {
       string name= ObjectName (n);
   
       if (ObjectType(name)== OBJ_RECTANGLE )
       
        {
          
          
     if ( ObjectFind ( 0 , "CLOSE" )== 0 )
          
          {
         datetime t1b = ( datetime ) ObjectGet(name,OBJPROP_TIME1);
         datetime t2b = ( datetime ) ObjectGet(name,OBJPROP_TIME2);

         double p1b= NormalizeDouble (ObjectGet(name,OBJPROP_PRICE1), Digits );
         double p2b= NormalizeDouble (ObjectGet(name,OBJPROP_PRICE2), Digits );

         
      
         
   
     
     
         if ( TimeCurrent ()>t1b && TimeCurrent ()< t2b &&
            Bid < p1b  && Bid > p2b   )   
         CloseBuyPositions1(); 
         
     
         }
         
         
         }
     }
     
   
         //Проверим что есть ли уже 2 равноудаленных канала:
   if ( ObjectsTotal ( OBJ_CHANNEL )== 2 )
   { Comment ( "Каналы по открытию и закрытию ордеров по покупке выставлены - идет торговля!" );}

    
    
     
     
 
  }
//+------------------------------------------------------------------+
void CloseBuyPositions1()
      {
      
       for ( int i = OrdersTotal () - 1 ; i >= 0 ; i--)
       if ( OrderSelect (i, SELECT_BY_POS, MODE_TRADES))
         if (OrderMagicNumber() == Magic)
             if (OrderSymbol() == Symbol ())
              {


          
           if (OrderType()==OP_BUY)
             {
               if (OrderClose(OrderTicket(), OrderLots(), Bid, 3 , NULL )){ Print ( "Order Close" );}
             }
          }
       } 
//+------------------------------------------------------------------+
//| Подсчет ордеров потекущему символу                               |
//+------------------------------------------------------------------+
int CounterOrderTradeType( ENUM_ORDER_TYPE order_type)
   {
   int cnt= 0 ;
   //----
   for ( int pos= OrdersTotal ()- 1 ;pos>= 0 ;pos--)
      {
       if ( OrderSelect (pos, SELECT_BY_POS, MODE_TRADES)== false ) continue ;
       if (OrderSymbol()!= _Symbol ) continue ;
       if (order_type == OrderType() || order_type == - 1 ) cnt++;
      }
   //----
   return (cnt);
   }   

İşte fonksiyonların

 
Порт-моне тв :

Buraya fonksiyonlarını ekledim

Birinci

OrderOfSymbol=CounterOrderTradeType(- 1 ); 

buraya getirilmeli

 void OnTick ()
  {
   OrderOfSymbol=CounterOrderTradeType(- 1 ); 
Gerisini şimdi düzelteceğim.
 
Порт-моне тв :

Buraya fonksiyonlarını ekledim

denemek

 //+------------------------------------------------------------------+
//|                                         равноудаленный канал.mq4 |
//+------------------------------------------------------------------+
#property copyright ""
#property link        ""
#property version    "1.00"
#property strict

extern int Magic = 777701 ;
extern double Lot = 0.01 ;
extern int Slippage = 3 ;

 double pXa, pXb;
 int ticket;
 int OrderOfSymbol;



//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit ()
  {  
//---
   return ( INIT_SUCCEEDED );
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit ( const int reason)
  {
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick ()
  {
//---
   OrderOfSymbol=CounterOrderTradeType(- 1 ); 
   //Проверим что есть ли равноудаленный канал:
   if ( ObjectFind ( 0 , "BUY" )!= 0 )
   { Comment ( "Нарисуйте равноудаленный канал для открытия сделки по покупке!" );}

   if ( ObjectFind ( 0 , "BUY" )== 0 )
     {
       datetime t1a = ( datetime ) ObjectGet( "BUY" ,OBJPROP_TIME1);
       datetime t2a = ( datetime ) ObjectGet( "BUY" ,OBJPROP_TIME2);

       double p1a= NormalizeDouble (ObjectGet( "BUY" ,OBJPROP_PRICE1), Digits );
       double p2a= NormalizeDouble (ObjectGet( "BUY" ,OBJPROP_PRICE2), Digits );

       if (OrderOfSymbol< 1 )
       if (Close[ 1 ]>Open[ 1 ])    
       if ( TimeCurrent ()>t1a && TimeCurrent ()< t2a && Bid < p1a  && Bid > p2a   )    
        {
         ticket = OrderSend ( Symbol (),OP_BUY, Lot, Ask, Slippage, 0 , 0 , "открыт ордер на покупку" , Magic, 0 , Blue);
        } 
       
      }
     
   //Проверим что есть ли уже равноудаленный канал и он в единственном экземпляре:
   if ( ObjectFind ( 0 , "CLOSE" )!= 0 )
   { Comment ( "Нарисуйте второй равноудаленный канал для закрытия сделки по покупке!" );}

     //Получим ИМЯ прямоугольника:
   if ( ObjectFind ( 0 , "CLOSE" )== 0 )
     {
       datetime t1b = ( datetime ) ObjectGet( "CLOSE" ,OBJPROP_TIME1);
       datetime t2b = ( datetime ) ObjectGet( "CLOSE" ,OBJPROP_TIME2);

       double p1b= NormalizeDouble (ObjectGet( "CLOSE" ,OBJPROP_PRICE1), Digits );
       double p2b= NormalizeDouble (ObjectGet( "CLOSE" ,OBJPROP_PRICE2), Digits );
      
       if ( TimeCurrent ()>t1b && TimeCurrent ()< t2b && Bid < p1b  && Bid > p2b   )   
         CloseBuyPositions1(); 
     }
   
         //Проверим что есть ли уже 2 равноудаленных канала:
   if ( ObjectsTotal ( OBJ_CHANNEL )== 2 )
   { Comment ( "Каналы по открытию и закрытию ордеров по покупке выставлены - идет торговля!" );}
  }
//+------------------------------------------------------------------+
void CloseBuyPositions1()
  {
   for ( int i = OrdersTotal () - 1 ; i >= 0 ; i--)
   if ( OrderSelect (i, SELECT_BY_POS, MODE_TRADES))
   if (OrderMagicNumber() == Magic)
   if (OrderSymbol() == Symbol ())
     {
       if (OrderType()==OP_BUY)
        {
         if (OrderClose(OrderTicket(), OrderLots(), Bid, 3 , NULL )){ Print ( "Order Close" );}
        }
     }
  } 
//+------------------------------------------------------------------+
//| Подсчет ордеров потекущему символу                               |
//+------------------------------------------------------------------+
int CounterOrderTradeType( ENUM_ORDER_TYPE order_type)
   {
   int cnt= 0 ;
   //----
   for ( int pos= OrdersTotal ()- 1 ;pos>= 0 ;pos--)
      {
       if ( OrderSelect (pos, SELECT_BY_POS, MODE_TRADES)== false ) continue ;
       if (OrderSymbol()!= _Symbol ) continue ;
       if (order_type == OrderType() || order_type == - 1 ) cnt++;
      }
   //----
   return (cnt);
   }
 
Biraz daha ince ayar ve güncelleme
 
MakarFX :
Biraz daha ince ayar ve güncelleme

Henüz evde değilim, yarın test edeceğim. Teşekkür ederim.

 
Порт-моне тв :

Henüz evde değilim, yarın test edeceğim. Teşekkür ederim.

İletişim
 

Hepinize iyi günler. Bir danışman var - trendin kesiştiğine dair sinyaller ve   yatay çizgiler   belirli renk. Belli bir stilin trend ve yatay çizgilerinin kesiştiği noktada bip sesi çıkaracak şekilde yeniden yapmaya karar verdim. Olmuş. Ancak, sadece sağda bir ışın olan trend çizgisi geçtiğinde sinyal vermem gerekiyor. ne yapılması gerektiğini anlıyorum

OBJPROP_RAY_RIGHT

ama ben yetişene kadar nerede ve nasıl. Şimdiden teşekkürler.
 //+------------------------------------------------------------------+
//|                                          TrendlineCrossAlert.mq5 |
//|                                             Copyright 2018, Strx |
//|                               https://www.mql5.com/en/users/strx |
//+------------------------------------------------------------------+
#define   EAName       "TrendlineCrossAlert"
#define   EAVersion   "1.01"

#property copyright    "Copyright 2018, Strx"
#property link          "https://www.mql5.com/en/users/strx"
#property version      EAVersion
#property description "Horizontal and Trendlines cross detection on any pair/timeframe"
#property description "good for scalping on small timeframes (M1 to M15) and trend following on bigger ones."
#property description "It send notifications when price crosses trendlines and horizontal lines"
#property description "of specified color and when it happens, it change its color to CrossedColor input parameter"
#property description "to be sure not to send multiple notifications for same line"

#include <Arrays\ArrayString.mqh>
#include <Trade\SymbolInfo.mqh>
#include <ChartObjects\ChartObject.mqh>
#include <ChartObjects\ChartObjectsLines.mqh>

//--- External inputs
sinput ENUM_LINE_STYLE    MonitoringStyle = STYLE_SOLID ;   //MonitoringColor, EA only monitors this lines style
sinput ENUM_LINE_STYLE    CrossedStyle = STYLE_DASH ;       //CrossedColor, EA changes crossed lines style to this value
sinput bool     EnableAlerts = true ;
sinput bool     EnableNotifications= true ;
sinput bool     EnableEmails= false ;

//+------------------------------------------------------------------+
//| Trendlines and Horizontal lines crossing notification expert
//+------------------------------------------------------------------+
class CTrendlineCrossAlertExpert
  {
protected :
   CSymbolInfo       m_symbol;                     // symbol info object

   //--- Logic vars
   CArrayString      m_objectNames;

public :
                     CTrendlineCrossAlertExpert( void );
                    ~CTrendlineCrossAlertExpert( void );
   bool               Init( void );

   void               Deinit( void );
   bool               Processing( void );

protected :

   //--- Inline functions 
   string               FormatPrice( double price){ return StringFormat ( "%." +( string )m_symbol. Digits ()+ "f" ,price); };
   bool                 IsNewBar(){ return iVolume ( NULL , 0 , 0 )== 1 ; };

   //--- Logic functions
   int                FindActiveObjects();
   bool               ActiveObject( string objName);
   bool               PriceCrossed( string objName);
   void               NotifyCrossing( string objName);

  };

//--- global expert
CTrendlineCrossAlertExpert ExtExpert;

//+------------------------------------------------------------------+
//| Constructor                                                      |
//+------------------------------------------------------------------+
CTrendlineCrossAlertExpert::CTrendlineCrossAlertExpert( void ){}

//+------------------------------------------------------------------+
//| Destructor                                                       |
//+------------------------------------------------------------------+
CTrendlineCrossAlertExpert::~CTrendlineCrossAlertExpert( void ){}
//+------------------------------------------------------------------+
//| Initialization and checking for input parameters                 |
//+------------------------------------------------------------------+
bool CTrendlineCrossAlertExpert::Init( void )
  {
//--- initialize common information
   m_symbol.Name( Symbol ());                   // symbol   

   return ( true );
  }
//+------------------------------------------------------------------+
//| main function returns true if any position processed             |
//+------------------------------------------------------------------+
bool CTrendlineCrossAlertExpert::Processing( void )
  {
   bool rv= false ;
   int i;
   string objName;

   if (m_symbol.RefreshRates())
     {
       if (FindActiveObjects())
        {
         for (i= 0 ; i<m_objectNames.Total(); i++)
           {
            objName=m_objectNames[i];
             if (PriceCrossed(objName))
              {
               ObjectSetInteger ( 0 ,objName, OBJPROP_STYLE ,CrossedStyle);
               NotifyCrossing(objName);
              }
           }
        }
     }

   Comment (EAName, " v." ,EAVersion, " parameters: MonitoringStyle=" ,MonitoringStyle, ", CrossedStyle=" ,CrossedStyle, ", EnableAlerts=" ,EnableAlerts, ", EnableNotifications=" ,EnableNotifications, ", EnableEmails=" ,EnableEmails, "\n" ,
           "Monitoring " ,m_objectNames.Total(), " lines" );

   return (rv);
  }
//+------------------------------------------------------------------+
//| Send Notifications function
//+------------------------------------------------------------------+
void CTrendlineCrossAlertExpert::NotifyCrossing( string objName)
  {
   string msg= "Price crossed line ''" +objName+ "' on " +m_symbol.Name();

   if (EnableAlerts) Alert (msg);
   if (EnableNotifications) SendNotification (msg);
   if (EnableEmails) SendMail (EAName+ " Event" ,msg);

   Print (msg);
  }
//+------------------------------------------------------------------+
//| Returns true if objName has been crossed up or down by current price
//+------------------------------------------------------------------+
bool CTrendlineCrossAlertExpert::PriceCrossed( string objName)
  {
   ENUM_OBJECT objType;
   double objPrice= 0.0 ,openPrice,curPrice;

   objType=( ENUM_OBJECT ) ObjectGetInteger ( 0 ,objName, OBJPROP_TYPE );
   if (objType== OBJ_HLINE )
     {
      objPrice= ObjectGetDouble ( 0 , objName, OBJPROP_PRICE );
        } else if (objType== OBJ_TREND ){
      objPrice= ObjectGetValueByTime ( 0 ,objName, TimeCurrent (), 0 );
     }

   if (objPrice)
     {
      openPrice= iOpen ( NULL , 0 , 0 );
      curPrice = iClose ( NULL , 0 , 0 );

       return (openPrice<=objPrice && curPrice>objPrice) || (openPrice>=objPrice && curPrice<objPrice);
     }

   return false ;
  }
//+------------------------------------------------------------------+
//| Returns true if object has to be monitored based on color and
//| previous crosses
//+------------------------------------------------------------------+
bool CTrendlineCrossAlertExpert::ActiveObject( string objName)
  {
   int objStyle=( int ) ObjectGetInteger ( 0 ,objName, OBJPROP_STYLE , 0 );
   return objStyle == MonitoringStyle;
  }
//+------------------------------------------------------------------+
//| Returns the list of object to be monitored
//+------------------------------------------------------------------+
int CTrendlineCrossAlertExpert::FindActiveObjects()
  {
   m_objectNames.Clear();

   int nHLines= ObjectsTotal ( 0 ,- 1 , OBJ_HLINE ),
   nTrendLines= ObjectsTotal ( 0 ,- 1 , OBJ_TREND ),
   i;

   string objName;

   for (i= 0 ; i<nHLines; i++)
     {
      objName= ObjectName ( 0 ,i, 0 , OBJ_HLINE );
       if (ActiveObject(objName))
        {
         m_objectNames.Add(objName);
        }
     }
   for (i= 0 ; i<nTrendLines; i++)
     {
      objName= ObjectName ( 0 ,i, 0 , OBJ_TREND );
       if (ActiveObject(objName))
        {
         m_objectNames.Add(objName);
        }
     }

   return m_objectNames.Total();
  }
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit ( void )
  {
   if (!ExtExpert.Init())
       return ( INIT_FAILED );

   return ( INIT_SUCCEEDED );
  }
//+------------------------------------------------------------------+
//| Expert new tick handling function                                |
//+------------------------------------------------------------------+
void OnTick ( void )
  {
   ExtExpert.Processing();
  }
//+------------------------------------------------------------------+
Документация по MQL5: Константы, перечисления и структуры / Константы объектов / Типы объектов
Документация по MQL5: Константы, перечисления и структуры / Константы объектов / Типы объектов
  • www.mql5.com
Типы объектов - Константы объектов - Константы, перечисления и структуры - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 

Tünaydın.
Fikire göre, danışman yeni bir çubuk göründüğünde koşulları kontrol etmeli ve siparişleri açmalıdır.

"Yalnızca global, ad alanı veya sınıf kapsamında işlev bildirimlerine izin verilir" hatası veriyor. Translated: "İşlev bildirimlerine yalnızca genel kapsamda, ad alanında veya sınıfta izin verilir."
Hala anlamıyorum, aptal. Lütfen bana söyle ya da nerede okuyacağımı söyle. Şimdiden teşekkürler!)

***

Документация по MQL5: Программы MQL5 / Ошибки выполнения
Документация по MQL5: Программы MQL5 / Ошибки выполнения
  • www.mql5.com
Ошибки выполнения - Программы MQL5 - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5