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

 
Alexey Viktorov :

Martin은 표시기 신호가 반대일 때만 켜야 합니까 아니면 이것에 관계 없이 켜야 합니까?

예: 지표에 따라 매수 포지션이 열립니다. 가격은 주어진 거리만큼 떨어졌고 표시기는 이미 매도를 표시하고 있습니다. 매수 포지션을 열어야 합니까?

요컨대 - 동시에 ..... Martin은 빨간색 주문으로 추세에 대해서만 작업하고 지표에 따르면 추세에만 작업합니다.

내일은 포토샵으로 그림을 그리고 파일을 올려보도록 하겠습니다

 
Sprut 185 :

요컨대 - 동시에 ..... Martin은 빨간색 주문으로 추세에 대해서만 작업하고 지표에 따르면 추세에만 작업합니다.

내일은 포토샵으로 그림을 그리고 파일을 올려보도록 하겠습니다

나는 여기서 100,000 루블로 이해하지 못하는 무언가를했습니다. 최대 200만

2000000

 //+------------------------------------------------------------------+
//|                                                  6 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 group   "---- : Parameters:  ----"
input int     InpTProfit       = 100000 ;   // : Take Profit --> (In currency the amount)
input double InpLotsRisk      = 0.1 ;     // : Maximum Risk in percentage
input group   "---- : Parameters:  ----"
input bool    InpClOp          = false ;     // : Close opposite
//---
int m_price_uno;
int m_handle_macd; // MACD indicator handle
int ExtTimeOut= 10 ; // time out in seconds between trade operations
//+------------------------------------------------------------------+
//| Calculate optimal lot size                                       |
//+------------------------------------------------------------------+
double OptimizedBuy( void )
  {
   double PROFIT_BUY= 0.00 ;
   int total= PositionsTotal ();
   for ( int i=total- 1 ; i>= 0 ; i--) // returns the number of open positions
     {
       string    position_GetSymbol= PositionGetSymbol (i); // GetSymbol позиции
       if (position_GetSymbol==m_symbol.Name())
        {
         if (m_position.PositionType()== POSITION_TYPE_BUY )
           {
            PROFIT_BUY=PROFIT_BUY+m_position.Select( Symbol ());
           }
        }
     }
   double Lots=InpLotsRisk;
   double ab=PROFIT_BUY;
   if (ab> 0 && ab<= 1 )
      Lots=InpLotsRisk* 2 ;
   if (ab> 1 && ab<= 2 )
      Lots=InpLotsRisk* 4 ;
   if (ab> 2 && ab<= 3 )
      Lots=InpLotsRisk* 8 ;
   if (ab> 3 )
      Lots=InpLotsRisk* 16 ;
   return (Lots);
  }
//+------------------------------------------------------------------+
//| Calculate optimal lot size                                       |
//+------------------------------------------------------------------+
double OptimizedSell( void )
  {
   double PROFIT_SELL= 0.00 ;
   int total= PositionsTotal ();
   for ( int i=total- 1 ; i>= 0 ; i--) // returns the number of open positions
     {
       string    position_GetSymbol= PositionGetSymbol (i); // GetSymbol позиции
       if (position_GetSymbol==m_symbol.Name())
        {
         if (m_position.PositionType()== POSITION_TYPE_SELL )
           {
            PROFIT_SELL=PROFIT_SELL+m_position.Select( Symbol ());
           }
        }
     }
   double Lots=InpLotsRisk;
   double ab=PROFIT_SELL;
   if (ab> 0 && ab<= 1 )
      Lots=InpLotsRisk* 2 ;
   if (ab> 1 && ab<= 2 )
      Lots=InpLotsRisk* 4 ;
   if (ab> 2 && ab<= 3 )
      Lots=InpLotsRisk* 8 ;
   if (ab> 3 )
      Lots=InpLotsRisk* 16 ;
   return (Lots);
  }
//+------------------------------------------------------------------+
//| 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_trade.SetDeviationInPoints( 3 *digits_adjust);
//--- create MACD indicator
   m_handle_macd= iCustom ( NULL , 0 , "StepMA_NRTR" );
   if (m_handle_macd== INVALID_HANDLE )
     {
       printf ( "Error creating MACD indicator" );
       return ( false );
     }
//---
   return ( INIT_SUCCEEDED );
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit ( const int reason)
  {
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick ( void )
  {
//---
   if (ProfitBuy() || ProfitSell())
     {
       return ;
     }
   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 (Processing())
            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[];
   bool StNRUp,StNRDn;
   ArraySetAsSeries (m_buff_MACD_main, true );
   ArraySetAsSeries (m_buff_MACD_signal, true );
   int start_pos= 1 ,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 );
     }
//---
   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 (m_price_uno< 0 )
         LongOpened();
      m_price_uno=+ 1 ;
       return ( true );
     }
//--- SELL Signal
   if (StNRDn)
     {
       if (InpClOp)
         if (LongClosed())
             Sleep ( 1000 );
       if (m_price_uno> 0 )
         ShortOpened();
      m_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?
   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?
   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
   double price=m_symbol.Ask();
//--- check for free money
   if (m_account.FreeMarginCheck( Symbol (), ORDER_TYPE_BUY ,OptimizedBuy(),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 ,OptimizedBuy(),price, 0.0 , 0.0 ))
         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" ,price);
        }
       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
   double price=m_symbol.Bid();
//--- check for free money
   if (m_account.FreeMarginCheck( Symbol (), ORDER_TYPE_SELL ,OptimizedSell(),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 ,OptimizedSell(),price, 0.0 , 0.0 ))
         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" ,price);
        }
       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);
  }
//+------------------------------------------------------------------+
//| ProfitOnTick closing                                             |
//+------------------------------------------------------------------+
bool ProfitBuy( void )
  {
   bool res= false ;
   double PROFIT_BUY= 0.00 ;
   int total= PositionsTotal ();
   for ( int i=total- 1 ; i>= 0 ; i--)
     {
       string    position_GetSymbol= PositionGetSymbol (i);
       if (position_GetSymbol==m_symbol.Name())
        {
         if (m_position.PositionType()== POSITION_TYPE_BUY )
           {
            PROFIT_BUY=PROFIT_BUY+ PositionGetDouble ( POSITION_PROFIT );
           }
        }
       if (PROFIT_BUY>=InpTProfit)
        {
         if (LongClosed())
            res= true ;
         if (ShortOpened())
            res= true ;
        }
     }
   return (res);
  }
//+------------------------------------------------------------------+
//| ProfitOnTick closing                                             |
//+------------------------------------------------------------------+
bool ProfitSell( void )
  {
   bool res= false ;
   double PROFIT_SELL= 0.00 ;
   int total= PositionsTotal ();
   for ( int i=total- 1 ; i>= 0 ; i--)
     {
       string    position_GetSymbol= PositionGetSymbol (i);
       if (position_GetSymbol==m_symbol.Name())
        {
         if (m_position.PositionType()== POSITION_TYPE_SELL )
           {
            PROFIT_SELL=PROFIT_SELL+ PositionGetDouble ( POSITION_PROFIT );
           }
        }
       if (PROFIT_SELL>=InpTProfit)
        {
         if (ShortClosed())
            res= true ;
         if (LongOpened())
            res= true ;
        }
     }
   return (res);
  }
//+------------------------------------------------------------------+
 

이제 이름을 바꿀 필요가 있습니다. 이러한 테스트를 통해 올바르게 수행하는 방법을 모르는 문어 또는 문어가 될 것입니다.

 //+------------------------------------------------------------------+
//|                                                 6 Сопрут 185.mq5 |
//|                                  Copyright 2021, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
 
Vitaly Muzichenko :

이제 이름을 바꿀 필요가 있습니다. 이러한 테스트를 통해 올바르게 수행하는 방법을 모르는 문어 또는 문어가 될 것입니다.

아마도 적어도 누군가는 부자가 될 것입니다. 그것은 나에게 주어지지 않았습니다. 나는 겸손하게 살고 싶습니다.

 
SanAlex :

아마도 적어도 누군가는 부자가 될 것입니다. 그것은 나에게 주어지지 않았습니다. 나는 겸손하게 살고 싶습니다.

지난 2년 이상 테스터에 런칭된 최초의 Expert Advisor입니다.

나는 테스터와 함께 앉아 있고 모든 것이 너무 많이 바뀌었고 많은 다른 버튼이 나타났습니다.

지금까지 데모를 하고 몇 주 동안 구동해야 한다는 결론에 도달했습니다.

요컨대, 이미 훔쳤습니다 ;)

 
Aleksei Stepanenko :

작동하지 않습니까?

나는 똑같이했지만 버퍼는 0으로 남아 있으므로 직접 시도 할 수 있습니다. 내가 이해하지 못한 유일한 것은 어떤 종류의 함수 IndicatorBuffers() mt5가 있고 #property i ndicatorbuffers를 사용했는지입니다 .
 
SanAlex :

나는 여기서 100,000 루블로 이해하지 못하는 무언가를했습니다. 최대 200만

헛되이, 바로 지금 그들은 시장에서 그것을 출시할 것입니다.

 
Fast235 :

헛되이, 바로 지금 그들은 시장에서 그것을 출시할 것입니다.

글쎄, 내버려 두십시오. 적어도 내 연구에서 약간의 의미가있을 것입니다. 내 보관함에 몇 가지 아이디어가 더 있습니다.

\\\\\\\\\\\\\\\\\\\\

두 가지 기능만 필요합니다. 그리고 프로그래밍 전문가인 올바르게 다시 작성해야 합니다. 나는 학생이고 찔러 그들을 눈멀게 하기 때문이다.

이것들은 기능들이다

1. - 이것은 제비를 곱합니다. 첫 번째 위치가 열린 다음 두 번째 위치가 곱해진 다음 계속됩니다. 판매는 자체 주문이 있습니다

 //+------------------------------------------------------------------+
//| Calculate optimal lot size                                       |
//+------------------------------------------------------------------+
double OptimizedBuy( void )
  {
   double PROFIT_BUY= 0.00 ;
   int total= PositionsTotal ();
   for ( int i=total- 1 ; i>= 0 ; i--) // returns the number of open positions
     {
       string    position_GetSymbol= PositionGetSymbol (i); // GetSymbol позиции
       if (position_GetSymbol==m_symbol.Name())
        {
         if (m_position.PositionType()== POSITION_TYPE_BUY )
           {
            PROFIT_BUY=PROFIT_BUY+m_position.Select( Symbol ());
           }
        }
     }
   double Lots=InpLotsRisk;
   double ab=PROFIT_BUY;
   if (ab> 0 && ab<= 1 )
      Lots=InpLotsRisk* 2 ;
   if (ab> 1 && ab<= 2 )
      Lots=InpLotsRisk* 4 ;
   if (ab> 2 && ab<= 3 )
      Lots=InpLotsRisk* 8 ;
   if (ab> 3 )
      Lots=InpLotsRisk* 16 ;
   return (Lots);
  }
//+------------------------------------------------------------------+

및 2 - 매수에서 열린 포지션 의 통화로 총 금액을 마감합니다.

 //+------------------------------------------------------------------+
//| ProfitOnTick closing                                             |
//+------------------------------------------------------------------+
bool ProfitBuy( void )
  {
   bool res= false ;
   double PROFIT_BUY= 0.00 ;
   int total= PositionsTotal ();
   for ( int i=total- 1 ; i>= 0 ; i--)
     {
       string    position_GetSymbol= PositionGetSymbol (i);
       if (position_GetSymbol==m_symbol.Name())
        {
         if (m_position.PositionType()== POSITION_TYPE_BUY )
           {
            PROFIT_BUY=PROFIT_BUY+ PositionGetDouble ( POSITION_PROFIT );
           }
        }
       if (PROFIT_BUY>=InpTProfit)
        {
         if (LongClosed())
            res= true ;
         if (ShortOpened())
            res= true ;
        }
     }
   return (res);
  }
//+------------------------------------------------------------------+

그리고 물론 나머지 반쪽

 
SanAlex :

글쎄, 내버려 두십시오. 적어도 내 연구에서 약간의 의미가있을 것입니다. 내 보관함에 몇 가지 아이디어가 더 있습니다.

그런 다음 코드가 괜찮은 경우 코드베이스에 던져야 합니다.

 
Vitaly Muzichenko :

지난 2년 이상 테스터에 런칭된 최초의 Expert Advisor입니다.

나는 테스터와 함께 앉아 있고 모든 것이 너무 많이 바뀌었고 많은 다른 버튼이 나타났습니다.

지금까지 데모를 하고 몇 주 동안 구동해야 한다는 결론에 도달했습니다.

요컨대, 이미 훔쳤습니다 ;)

나는 또한 전문가와 함께 테스트했습니다. 어떻게 든 마감 금액에 따라 다릅니다. 금액보다 적게 베팅하면 병합되고 더 많으면 병합됩니다.

나는 100,000 문지름. 테스트 및 100,000 루블. 이익 마감. 그리고 그는 200만 달러에 도달했습니다(작년에는 1시간 유로에

사유: