초보자의 질문 MQL5 MT5 MetaTrader 5 - 페이지 1319

 
SanAlex :

독학해서 설명할 수 없습니다. 필요한 기능만 선택했습니다. 여기 저기 저쪽으로 압니다.

기본적으로 Vladimir Karputov 의 코드에서 모든 기능을 복사합니다. 정말 감사합니다!!! - 질문이 있으면 그가 당신에게 말할 것입니다.

당신은 독학이지만 프로그래밍을 막 시작했고 내 머리에는 질문만 있습니다.  

나는 내 머리 속에 이 고문의 알고리즘을 상상하고 있으며, 그 과정에서 지표를 변경해야 하는 경우 질문이 아닙니다. 결국 두 가지 작업만 가능합니다(방향 휠이 위로 향하고 방향점이 아래로 있음).

현재 저는 가장 단순한 것이 최고라는 고전부터 시작하고 있습니다. 그래서 예배당으로 단순화하고 ...... 동시에 내가 만들고 싶은 것을 최대한 활용하고 싶습니다. 나는 내 알고리즘에 대해 함께 작업할 것을 제안합니다. 두 가지 모두에 흥미로울 것이라고 생각합니다.
관심이 있는 경우 개인에 씁니다.
 
Vladimir Karputov :

상속은 클래스를 만드는 것을 의미합니다.

그래서 나는 쓰고 있습니다 - 표준 라이브러리에서 이러한 메소드를 사용하기 위해 어떤 클래스에서 귀하의 클래스 를 상속합니까?

 
SanAlex :

여기에 또 다른 옵션이 있습니다 - 테이크가 작동한 방식 - 동일한 방향으로 다시 열립니다.

바로, 이익으로 !!!

언뜻보기에는 모든 것이 맞습니다.

그리고 손절매 가 - 또한 되어서도 안 된다는 - 사실은 맞습니다.

그러나 가격 움직임의 방향이 변할 때 ..... 가격 움직임의 방향이 변할 때 .... (그것은 기본적으로 닫힙니다. 즉, 추세 변화 지표) ? 그렇다면 그것은 내 생각이 아닙니다.

그리고 내 생각에 따르면 - 순서는 유지되어야 하지만 설정이 포함된 마틴이 작동해야 합니다.

 input group "======== МАРТИН ========" ; 
input int       MMType        = 1 ;         // 1 - вкл. , 2 - выкл.
input double    Multiplikator = 1.667 ;     // множитель следующего лота
input double    Step          = 150.0 ;     // Расстояние между ордерами

저것들. 로트의 증가와 테이크 이익의 평균으로 추세와 반대 방향으로 주문하십시오. 간단히 말해서, 간단한 Martin처럼 작업하십시오. 예를 들어 (Advisor Autoprofit 3) 인터넷의 오픈 소스이지만 mql4로 작성되었습니다.

그건 그렇고, 당신이 올바르게 쓴 추세에 따라 작동하는 원본 버전은 Martin과 작업 할 때 누구도 취소하지 않았습니다.

요컨대, 트렌드 작업은 부분적으로 훌륭하게 시연한 작업 중 하나이며 두 번째 작업은 마틴입니다.

이 두 작업이 상호 연결될 필요는 없습니다. 제 생각에는 완전히 독립적으로 작동할 수 있습니다.

 
Sprut 185 :

바로, 이익으로 !!!

언뜻보기에는 모든 것이 맞습니다.

그리고 손절매 가 - 또한 되어서도 안 된다는 - 사실은 맞습니다.

그러나 나는 이익 실현으로 마감되지 않은 주문이 어디로 가는지 이해하지 못했습니다 ....... 가격 움직임의 방향이 바뀔 때 .... (기본적으로 닫힙니다. 즉, 추세의 신호에 의해) 변경 표시기) ? 그렇다면 그것은 내 생각이 아닙니다.

그리고 내 생각에 따르면 - 순서는 유지되어야 하지만 설정이 포함된 마틴이 작동해야 합니다.

저것들. 로트의 증가와 테이크 이익의 평균으로 추세와 반대 방향으로 주문하십시오. 간단히 말해서, 간단한 Martin처럼 작업하십시오. 예를 들어 (Advisor Autoprofit 3) 인터넷의 오픈 소스이지만 mql4로 작성되었습니다.

참고로 "주문"이 아니라 "위치"입니다.

 
Vladimir Karputov :

단 하나의 언급: "주문"이 아니라 "위치"입니다.

실수에 대해 사과드립니다.
참고해서 앞으로 개선하도록 노력하겠습니다.
 
Sprut 185 :

내가 찾을 수 있는 모든 옵션 - 더 이상 옵션이 없습니다.

4 스프루트 185

 //+------------------------------------------------------------------+
//|                                                  4 Sprut 185.mq5 |
//|                                  Copyright 2021, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Ltd."
#property link        " https://www.mql5.com "
#property version    "1.00"
//---
#define MACD_MAGIC 1234502
//---
#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>
#include <Trade\PositionInfo.mqh>
#include <Trade\AccountInfo.mqh>
//---
double             m_adjusted_point;             // point value adjusted for 3 or 5 points
CTrade            m_trade;                       // trading object
CSymbolInfo       m_symbol;                     // symbol info object
CPositionInfo     m_position;                   // trade position object
CAccountInfo      m_account;                     // account info wrapper
//---
input double InpLots          = 0.1 ;   // Lots
input int     InpTakeProfit    = 50 ;     // Take Profit (in pips)
input bool    InpVariant       = false ; // Option
input int     InpBar           = 1 ;     // Bar
input bool    InpClOp          = false ; // Close opposite
//---
double m_macd_current;
double m_signal_current;
double m_take_profit;
int     price_uno;
int     m_handle_macd; // MACD indicator handle
int     ExtTimeOut= 10 ; // time out in seconds between trade operations
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit ()
  {
//--- initialize common information
   m_symbol.Name( Symbol ());                   // symbol
   m_trade.SetExpertMagicNumber(MACD_MAGIC); // magic
   m_trade.SetMarginMode();
   m_trade.SetTypeFillingBySymbol( Symbol ());
//--- tuning for 3 or 5 digits
   int digits_adjust= 1 ;
   if (m_symbol. Digits ()== 3 || m_symbol. Digits ()== 5 )
      digits_adjust= 10 ;
   m_adjusted_point=m_symbol. Point ()*digits_adjust;
//--- set default deviation for trading in adjusted points
   m_take_profit     =InpTakeProfit*m_adjusted_point;
//--- set default deviation for trading in adjusted points
   m_trade.SetDeviationInPoints( 3 *digits_adjust);
//--- create StepMA_NRTR indicator
   m_handle_macd= iCustom ( NULL , 0 , "StepMA_NRTR" );
   if (m_handle_macd== INVALID_HANDLE )
     {
       printf ( "Error creating StepMA_NRTR indicator" );
       return ( false );
     }
//---
   return ( INIT_SUCCEEDED );
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit ( const int reason)
  {
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick ( void )
  {
   static datetime limit_time= 0 ; // last trade processing time + timeout
//--- don't process if timeout
   if ( TimeCurrent ()>=limit_time)
     {
       //--- check for data
       if ( Bars ( Symbol (), Period ())> 2 )
        {
         //--- change limit time by timeout in seconds if processed
         if (!InpVariant && Processing())
            limit_time= TimeCurrent ()+ExtTimeOut;
         //--- change limit time by timeout in seconds if processed
         if (InpVariant && Processing_1())
            limit_time= TimeCurrent ()+ExtTimeOut;
        }
     }
  }
//+------------------------------------------------------------------+
//| main function returns true if any position processed             |
//+------------------------------------------------------------------+
bool Processing( void )
  {
//--- refresh rates
   if (!m_symbol.RefreshRates())
       return ( false );
   double m_buff_MACD_main[],m_buff_MACD_signal[];
   ArraySetAsSeries (m_buff_MACD_main, true );
   ArraySetAsSeries (m_buff_MACD_signal, true );
   int start_pos=InpBar,count= 3 ;
   if (!iGetArray(m_handle_macd, 0 ,start_pos,count,m_buff_MACD_main)||
      !iGetArray(m_handle_macd, 1 ,start_pos,count,m_buff_MACD_signal))
     {
       return ( false );
     }
//---
   m_macd_current   =m_buff_MACD_main[ 0 ];
   m_signal_current =m_buff_MACD_signal[ 0 ];
//---
   if (m_position.Select( Symbol ()))
     {
       //--- try to close or modify long position
       if (LongClosed())
         return ( true );
       //--- try to close or modify short position
       if (ShortClosed())
         return ( true );
     }
   else
     {
       //--- check for long position (BUY) possibility
       if (LongOpened())
         return ( true );
       //--- check for short position (SELL) possibility
       if (ShortOpened())
         return ( true );
     }
//--- exit without position processing
   return ( false );
  }
//+------------------------------------------------------------------+
//| main function returns true if any position processed             |
//+------------------------------------------------------------------+
bool Processing_1( void )
  {
//--- refresh rates
   if (!m_symbol.RefreshRates())
       return ( false );
   double m_buff_MACD_main[],m_buff_MACD_signal[];
   bool StNRUp,StNRDn;
   ArraySetAsSeries (m_buff_MACD_main, true );
   ArraySetAsSeries (m_buff_MACD_signal, true );
   int start_pos=InpBar,count= 3 ;
   if (!iGetArray(m_handle_macd, 0 ,start_pos,count,m_buff_MACD_main)||
      !iGetArray(m_handle_macd, 1 ,start_pos,count,m_buff_MACD_signal))
     {
       return ( false );
     }
//---
   m_macd_current   =m_buff_MACD_main[ 0 ];
   m_signal_current =m_buff_MACD_signal[ 0 ];
//---
   StNRUp=m_buff_MACD_main[ 0 ]<m_buff_MACD_signal[ 0 ];
   StNRDn=m_buff_MACD_main[ 0 ]>m_buff_MACD_signal[ 0 ];
//--- BUY Signal
   if (StNRUp)
     {
       if (InpClOp)
         if (ShortClosed())
             Sleep ( 1000 );
       if (price_uno< 0 )
         LongOpened();
      price_uno=+ 1 ;
       return ( true );
     }
//--- SELL Signal
   if (StNRDn)
     {
       if (InpClOp)
         if (LongClosed())
             Sleep ( 1000 );
       if (price_uno> 0 )
         ShortOpened();
      price_uno=- 1 ;
       return ( true );
     }
//--- exit without position processing
   return ( false );
  }
//+------------------------------------------------------------------+
//| Check for long position closing                                  |
//+------------------------------------------------------------------+
bool LongClosed( void )
  {
   bool res= false ;
//--- should it be closed?
   if (m_macd_current>m_signal_current)
     {
       //--- close position
       if (InpClOp)
         ClosePositions( POSITION_TYPE_BUY );
       //--- processed and cannot be modified
      res= true ;
     }
//--- result
   return (res);
  }
//+------------------------------------------------------------------+
//| Check for short position closing                                 |
//+------------------------------------------------------------------+
bool ShortClosed( void )
  {
   bool res= false ;
//--- should it be closed?
   if (m_macd_current<m_signal_current)
     {
       //--- close position
       if (InpClOp)
         ClosePositions( POSITION_TYPE_SELL );
       //--- processed and cannot be modified
      res= true ;
     }
//--- result
   return (res);
  }
//+------------------------------------------------------------------+
//| Check for long position opening                                  |
//+------------------------------------------------------------------+
bool LongOpened( void )
  {
   bool res= false ;
//--- check for long position (BUY) possibility
   if (m_macd_current<m_signal_current)
     {
       double price=m_symbol.Ask();
       double tp   =m_symbol.Bid()+m_take_profit;
       //--- check for free money
       if (m_account.FreeMarginCheck( Symbol (), ORDER_TYPE_BUY ,InpLots,price)< 0.0 )
         printf ( "We have no money. Free Margin = %f" ,m_account.FreeMargin());
       else
        {
         //--- open position
         if (m_trade.PositionOpen( Symbol (), ORDER_TYPE_BUY ,InpLots,price, 0.0 ,tp))
             printf ( "Position by %s to be opened" , Symbol ());
         else
           {
             printf ( "Error opening BUY position by %s : '%s'" , Symbol (),m_trade.ResultComment());
             printf ( "Open parameters : price=%f,TP=%f" ,price,tp);
           }
         PlaySound ( "ok.wav" );
        }
       //--- in any case we must exit from expert
      res= true ;
     }
//--- result
   return (res);
  }
//+------------------------------------------------------------------+
//| Check for short position opening                                 |
//+------------------------------------------------------------------+
bool ShortOpened( void )
  {
   bool res= false ;
//--- check for short position (SELL) possibility
   if (m_macd_current>m_signal_current)
     {
       double price=m_symbol.Bid();
       double tp   =m_symbol.Ask()-m_take_profit;
       //--- check for free money
       if (m_account.FreeMarginCheck( Symbol (), ORDER_TYPE_SELL ,InpLots,price)< 0.0 )
         printf ( "We have no money. Free Margin = %f" ,m_account.FreeMargin());
       else
        {
         //--- open position
         if (m_trade.PositionOpen( Symbol (), ORDER_TYPE_SELL ,InpLots,price, 0.0 ,tp))
             printf ( "Position by %s to be opened" , Symbol ());
         else
           {
             printf ( "Error opening SELL position by %s : '%s'" , Symbol (),m_trade.ResultComment());
             printf ( "Open parameters : price=%f,TP=%f" ,price,tp);
           }
         PlaySound ( "ok.wav" );
        }
       //--- in any case we must exit from expert
      res= true ;
     }
//--- result
   return (res);
  }
//+------------------------------------------------------------------+
//| Refreshes the symbol quotes data                                 |
//+------------------------------------------------------------------+
bool RefreshRates()
  {
//--- refresh rates
   if (!m_symbol.RefreshRates())
     {
       return ( false );
     }
//--- protection against the return value of "zero"
   if (m_symbol.Ask()== 0 || m_symbol.Bid()== 0 )
     {
       return ( false );
     }
//---
   return ( true );
  }
//+------------------------------------------------------------------+
//| Check Freeze and Stops levels                                    |
//+------------------------------------------------------------------+
void FreezeStopsLevels( double &freeze, double &stops)
  {
//--- check Freeze and Stops levels
   double coeff=( double ) 1 ;
   if (!RefreshRates() || !m_symbol.Refresh())
       return ;
//--- FreezeLevel -> for pending order and modification
   double freeze_level=m_symbol.FreezeLevel()*m_symbol. Point ();
   if (freeze_level== 0.0 )
       if ( 1 > 0 )
         freeze_level=(m_symbol.Ask()-m_symbol.Bid())*coeff;
//--- StopsLevel -> for TakeProfit and StopLoss
   double stop_level=m_symbol.StopsLevel()*m_symbol. Point ();
   if (stop_level== 0.0 )
       if ( 1 > 0 )
         stop_level=(m_symbol.Ask()-m_symbol.Bid())*coeff;
//---
   freeze=freeze_level;
   stops=stop_level;
//---
   return ;
  }
//+------------------------------------------------------------------+
//| Close positions                                                  |
//+------------------------------------------------------------------+
void ClosePositions( const ENUM_POSITION_TYPE pos_type)
  {
   double freeze= 0.0 ,stops= 0.0 ;
   FreezeStopsLevels(freeze,stops);
   for ( int i= PositionsTotal ()- 1 ; i>= 0 ; i--) // returns the number of current positions
       if (m_position.SelectByIndex(i)) // selects the position by index for further access to its properties
         if (m_position. Symbol ()==m_symbol.Name() && m_position.Magic()==MACD_MAGIC)
             if (m_position.PositionType()==pos_type)
              {
               if (m_position.PositionType()== POSITION_TYPE_BUY )
                 {
                   bool take_profit_level=((m_position.TakeProfit()!= 0.0 && m_position.TakeProfit()-m_position.PriceCurrent()>=freeze) || m_position.TakeProfit()== 0.0 );
                   bool stop_loss_level=((m_position.StopLoss()!= 0.0 && m_position.PriceCurrent()-m_position.StopLoss()>=freeze) || m_position.StopLoss()== 0.0 );
                   if (take_profit_level && stop_loss_level)
                     if (!m_trade.PositionClose(m_position.Ticket())) // close a position by the specified m_symbol
                         Print ( __FILE__ , " " , __FUNCTION__ , ", ERROR: " , "BUY PositionClose " ,m_position.Ticket(), ", " ,m_trade.ResultRetcodeDescription());
                 }
               if (m_position.PositionType()== POSITION_TYPE_SELL )
                 {
                   bool take_profit_level=((m_position.TakeProfit()!= 0.0 && m_position.PriceCurrent()-m_position.TakeProfit()>=freeze) || m_position.TakeProfit()== 0.0 );
                   bool stop_loss_level=((m_position.StopLoss()!= 0.0 && m_position.StopLoss()-m_position.PriceCurrent()>=freeze) || m_position.StopLoss()== 0.0 );
                   if (take_profit_level && stop_loss_level)
                     if (!m_trade.PositionClose(m_position.Ticket())) // close a position by the specified m_symbol
                         Print ( __FILE__ , " " , __FUNCTION__ , ", ERROR: " , "SELL PositionClose " ,m_position.Ticket(), ", " ,m_trade.ResultRetcodeDescription());
                 }
               PlaySound ( "ok.wav" );
              }
  }
//+------------------------------------------------------------------+
//| Filling the indicator buffers from the indicator                 |
//+------------------------------------------------------------------+
bool iGetArray( const int handle, const int buffer, const int start_pos,
               const int count, double &arr_buffer[])
  {
   bool result= true ;
   if (! ArrayIsDynamic (arr_buffer))
     {
       return ( false );
     }
   ArrayFree (arr_buffer);
//--- reset error code
   ResetLastError ();
//--- fill a part of the iBands array with values from the indicator buffer
   int copied= CopyBuffer (handle,buffer,start_pos,count,arr_buffer);
   if (copied!=count)
     {
       return ( false );
     }
   return (result);
  }
//+------------------------------------------------------------------+
 
SanAlex :

내가 찾을 수 있는 모든 옵션 - 더 이상 옵션이 없습니다.


EA에서 2개의 독립 블록을 사용하려고 하면 어떻게 될까요? 그러면 이미 추세에 대해 작업하고 있으므로(지표 사용) 자체적으로 작동합니다.............
그리고 두 번째 는 첫 번째 블록에 의해 설정된 신호에 따라 - 위치에 따라 - 추세에 따라가 아니라 .......


나는 이미 위에서 썼습니다.

이 두 작업이 서로 연결될 필요는 없습니다. 제 생각에는 완전히 독립적으로 작동할 수 있습니다 .

내가 제안하는 그러한 알고리즘은 (내 의견으로는) 아직 프로그래머가 사용하지 않았습니다. 어쨌든 인터넷에서 그러한 솔루션을 찾지 못했습니다.

 
Sprut 185 : 내가 제안한 그러한 알고리즘은 (내 의견으로는) 아직 프로그래머가 사용하지 않았습니다. 어쨌든 인터넷에서 그러한 솔루션을 찾지 못했습니다.

구현이 불가능할 가능성이 높음

이것은 작동하지 않습니다 - 기호에 하나의 위치가 있어야 합니다(이는 해당 위치 가 닫혔다가 이익을 위해 다시 열린 경우)(반대 신호가 주어지면 다른 방향으로 열릴 수 없습니다)

   if (m_position.Select( Symbol ()))

신호(한 지점에서)만 있으면 문제가 없습니다. (그리고 이것은 코드에 존재하지 않아야 합니다(위의 줄)))

 
SanAlex :

구현이 불가능할 가능성이 높음

이것은 작동하지 않습니다 - 기호에 하나의 위치가 있어야 합니다(이는 해당 위치 가 닫혔다가 이익을 위해 다시 열린 경우)(반대 신호가 주어지면 다른 방향으로 열릴 수 없습니다)

신호(한 지점에서)만 있으면 문제가 없습니다. (그리고 이것은 코드에 존재하지 않아야 합니다(위의 줄)))

이해했습니다. 그래서 아마도 인터넷에서 그러한 솔루션을 찾지 못했을 것입니다. 그러나 제 생각에는 이 문제에 대한 해결책이 있어야 합니다.
감사합니다-이 문제에 대한 해결책을 찾을 것입니다 .....
그럼 잠시 멈칫합시다.
 

버전 2981로 업데이트한 후 다음 줄에 오류가 표시되기 시작했습니다.

 MqlTradeRequest request = { 0 }
cannot convert 0 to enum 'ENUM_TRADE_REQUEST_ACTIONS'   OrderaiPosicii.mqh      11      34
이 줄을 교체하는 방법을 알려주세요.