MQL4 및 MQL5에 대한 초보자 질문, 알고리즘 및 코드에 대한 도움말 및 토론 - 페이지 1644

 
Andrey Sokolov 터미널을 닫거나 표시기를 다시 시작할 때만 표시됩니다.
2개의 스크린샷은 첫 번째 스크린샷을 제외하고 이동하지 않습니다. 오류 5019(파일이 존재하지 않음)는 폴더에 표시되지만(타이머로 만든 첫 번째 스크린샷 제외).


시장이 닫히고 테스터에서 타이머가 작동하지 않습니다.
 
Andrey Sokolov 터미널을 닫거나 표시기를 다시 시작할 때만 표시됩니다.
2개의 스크린샷은 첫 번째 스크린샷을 제외하고 이동하지 않습니다. 오류 5019(파일이 존재하지 않음)는 폴더에 표시되지만(타이머로 만든 첫 번째 스크린샷 제외).


크립트의 모든 스크린샷을 확인했지만 이동 오류가 있습니다.

 2021.10 . 03 15 : 23 : 56.384 Scrin BTCUSD,M5: screen name_file 2021.10 . 03 15 - 23 - 56 .png
2021.10 . 03 15 : 23 : 56.367 Scrin BTCUSD,M5: FileMove ERR: 4051
2021.10 . 03 15 : 23 : 56.367 Scrin BTCUSD,M5: OnTimer () 
2021.10 . 03 15 : 23 : 51.391 Scrin BTCUSD,M5: screen name_file 2021.10 . 03 15 - 23 - 51 .png
2021.10 . 03 15 : 23 : 51.374 Scrin BTCUSD,M5: FileMove ERR: 4051
2021.10 . 03 15 : 23 : 51.374 Scrin BTCUSD,M5: OnTimer () 
2021.10 . 03 15 : 23 : 46.378 Scrin BTCUSD,M5: screen name_file 2021.10 . 03 15 - 23 - 46 .png
2021.10 . 03 15 : 23 : 46.360 Scrin BTCUSD,M5: FileMove ERR: 4051
2021.10 . 03 15 : 23 : 46.360 Scrin BTCUSD,M5: OnTimer () 
 
MakarFX # :

크립트의 모든 스크린샷을 확인했지만 이동 오류가 있습니다.

그것이 작동 방식입니다

 //+------------------------------------------------------------------+
bool Move(){
   string src_path=name_file; 
   string dst_path=name_folder+ "//" +name_file; 
   ResetLastError ();
   if ( FileMove (src_path, 0 ,dst_path, 0 )){
       Print ( "FileMove OK " );
       return true ;
   }   
   else {
       string err_text= "FileMove ERR: " +( string ) GetLastError ();
       if ( GetLastError ()== 5019 ) err_text+=( "  5019 name_file " +name_file);
       Print (err_text);
   }  
   return false ;
}
그리고 왜 전혀 움직이는 것을 귀찮게합니까?
 
MakarFX # :

기능을 분리하여 탐색하기 쉽도록 합니다.

다음은 OnTick()의 예입니다.

보시다시피 여기에는 함수 호출만 있습니다.

하루 중 좋은 시간 Makar는 코드를 재설계하여 오류 로그에서 평균 가격을 계산하는 기능을 가져왔지만 평균 가격에서 트롤이 없습니다.

 //+----------------------------------------------------------------------------+
//| Расчет среденй цены                                                        |
//+----------------------------------------------------------------------------+
double GetAveragePrice()
{
   order_lots = 0 ;
   price = 0 ;
   {
     for ( int i = OrdersTotal ()- 1 ; i>= 0 ; i--)
    {
     if ( OrderSelect (i, SELECT_BY_POS, MODE_TRADES))
       {
         if (OrderSymbol() == Symbol () && OrderMagicNumber() == Magic)
         {
         if (OrderType() == OP_BUY || OrderType() == OP_SELL)
           {
            price += OrderOpenPrice() * OrderLots();
            order_lots += OrderLots();
            avg_price = NormalizeDouble (price / order_lots, Digits );
             {
               ObjectDelete ( 0 , "AveragePriceLine" );
               ObjectCreate ( 0 , "AveragePriceLine" , OBJ_HLINE , 0 , 0 , avg_price);
               ObjectSet( "AveragePriceLine" , OBJPROP_COLOR , Magenta);
             }
           }
         }
       }
    }
   }
return (avg_price);
}
//+----------------------------------------------------------------------------+
//| Модификация групповых ордеров                                              |
//+----------------------------------------------------------------------------+
void ModifyOrders( int otype)
{
     for ( int i = OrdersTotal ()- 1 ; i>= 0 ; i--)
    {
       if ( OrderSelect (i, SELECT_BY_POS, MODE_TRADES))
       {
         if (OrderSymbol() == Symbol () && OrderMagicNumber() == Magic && OrderType() == otype)
          {
           if (otype == OP_BUY) tp = NormalizeDouble (GetAveragePrice() + TakeProfitGroupOrder* Point , Digits );
           if (otype == OP_SELL) tp = NormalizeDouble (GetAveragePrice() - TakeProfitGroupOrder* Point , Digits );
           if ((otype == OP_BUY || otype == OP_SELL) && (Drawdown > DrawdownClosingTakeprofitZero)) 
           tp = NormalizeDouble (GetAveragePrice(), Digits );
          }
       }
    }
     for ( int i = OrdersTotal ()- 1 ; i>= 0 ; i--) 
    {
       if ( OrderSelect (i, SELECT_BY_POS, MODE_TRADES))
       {
           if (OrderSymbol() == Symbol () && OrderMagicNumber() == Magic && OrderType() == otype)
           {
               if (OrderModify(OrderTicket(), OrderOpenPrice(), 0 , tp, 0 ))
                   Print ( "Ордера успешно модифицированы!" );
                 else Print ( "Ошибка модификации ордеров!" );
                TrailingGroupOrder();
           }
       }
    }
}
//+----------------------------------------------------------------------------+
//| Трейлинг стоп групповых ордеров                                            |
//+----------------------------------------------------------------------------+
void TrailingGroupOrder()
{
     for ( int i = OrdersTotal ()- 1 ; i>= 0 ; i--)
    {
     if ( OrderSelect (i, SELECT_BY_POS, MODE_TRADES))
       {
       if (OrderType() == OP_BUY && Bid - GetAveragePrice() > TrailingStopGroupOrder* Point )
        {
         if (Bid - GetAveragePrice() > TrailingStopGroupOrder* Point || OrderStopLoss() == 0 )
         {
         if (OrderStopLoss() < Bid - (TrailingStep + TrailingStopGroupOrder )* Point || OrderStopLoss() == 0 )
          {
           if (!OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble (Bid - TrailingStopGroupOrder* Point , Digits ), tp, 0 ))
                     Print ( "Ошибка модификации групповых ордеров на покупку!" );
          }
         }
        }
         if (OrderType() == OP_SELL && GetAveragePrice() - Ask > TrailingStopGroupOrder* Point )
         {
         if (GetAveragePrice() - Ask > TrailingStopGroupOrder* Point || OrderStopLoss() == 0 )
           {
             if (OrderStopLoss() > Ask + (TrailingStep + TrailingStopGroupOrder)* Point || OrderStopLoss() == 0 )
              {
               if (!OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble (Ask + TrailingStopGroupOrder* Point , Digits ), tp, 0 ))
                     Print ( "Ошибка модификации групповых ордеров на продажу!" );
              }
           }
         }
      } 
    }
}

나는 완벽하게 작동하는 단일 주문에 대해 이 기능에서 후행 원칙을 취했습니다.

 //+----------------------------------------------------------------------------+
//| Трейлинг стоп одиночных ордеров                                            |
//+----------------------------------------------------------------------------+
void Trailing()
{
   for ( int i = OrdersTotal ()- 1 ; i>= 0 ; i--)
   {
       if ( OrderSelect (i, SELECT_BY_POS, MODE_TRADES))
      {
         if (OrderSymbol() == Symbol () && OrderMagicNumber() == Magic)
         {
           if (OrderType() == OP_BUY && Bid - OrderOpenPrice() > TrailingStopFirstOrder* Point )
           {
             if (Bid - OrderOpenPrice() > TrailingStopFirstOrder* Point || OrderStopLoss() == 0 )
             {
                 if (OrderStopLoss() < Bid - (TrailingStep + TrailingStopFirstOrder)* Point || OrderStopLoss() == 0 )
                {
                   if (!OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble (Bid - TrailingStopFirstOrder* Point , Digits ), tp, 0 ))
                     Print ( "Ошибка модификации ордера на покупку!" );
                }
             }
           }
           if (OrderType() == OP_SELL && OrderOpenPrice() - Ask > TrailingStopFirstOrder* Point )
           {
             if (OrderOpenPrice() - Ask > TrailingStopFirstOrder* Point || OrderStopLoss() == 0 )
             {
                 if (OrderStopLoss() > Ask + (TrailingStep + TrailingStopFirstOrder)* Point || OrderStopLoss() == 0 )
               {
                   if (!OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble (Ask + TrailingStopFirstOrder* Point , Digits ), tp, 0 ))
                     Print ( "Ошибка модификации ордера на продажу!" );
               }
             }
           }
         }
      }
   }
}
 
EVGENII SHELIPOV # :

하루 중 좋은 시간 Makar는 코드를 재설계하여 오류 로그에서 평균 가격을 계산하는 기능을 가져왔지만 평균 가격에서 트롤이 없습니다.

나는 완벽하게 작동하는 단일 주문에 대해 이 기능에서 후행 원칙을 취했습니다.

대충 이정도...

 //+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick ()
   {
//---
   if (CountTrade()> 1 ) TrailingGroupOrder();
   }
//+----------------------------------------------------------------------------+
//| Расчет среденй цены                                                        |
//+----------------------------------------------------------------------------+
double GetAveragePrice()
   {
   order_lots = 0 ;
   price = 0 ;
      {
       for ( int i = OrdersTotal ()- 1 ; i>= 0 ; i--)
         {
         if ( OrderSelect (i, SELECT_BY_POS, MODE_TRADES))
            {
             if (OrderSymbol() == Symbol () && OrderMagicNumber() == Magic)
               {
               if (OrderType() == OP_BUY || OrderType() == OP_SELL)
                  {
                  price += OrderOpenPrice() * OrderLots();
                  order_lots += OrderLots();
                  avg_price = NormalizeDouble (price / order_lots, Digits );

                   ObjectDelete ( 0 , "AveragePriceLine" );
                   ObjectCreate ( 0 , "AveragePriceLine" , OBJ_HLINE , 0 , 0 , avg_price);
                  ObjectSet( "AveragePriceLine" , OBJPROP_COLOR , Magenta);
                  }
               }
            }
         }
      }
   return (avg_price);
   }
//+----------------------------------------------------------------------------+
//| Трейлинг стоп групповых ордеров                                            |
//+----------------------------------------------------------------------------+
void TrailingGroupOrder()
   {
   for ( int i = OrdersTotal ()- 1 ; i>= 0 ; i--)
      {
       if ( OrderSelect (i, SELECT_BY_POS, MODE_TRADES))
         {
         if (OrderType() == OP_BUY)
            {
             if (Bid - GetAveragePrice() > TrailingStopGroupOrder* Point || OrderStopLoss() == 0 )
               {
               if (OrderStopLoss() < Bid - (TrailingStep + TrailingStopGroupOrder )* Point || OrderStopLoss() == 0 )
                  {
                   if (!OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble (Bid - TrailingStopGroupOrder* Point , Digits ), tp, 0 ))
                     Print ( "Ошибка модификации групповых ордеров на покупку!" );
                  }
               }
            }
         if (OrderType() == OP_SELL)
            {
             if (GetAveragePrice() - Ask > TrailingStopGroupOrder* Point || OrderStopLoss() == 0 )
               {
               if (OrderStopLoss() > Ask + (TrailingStep + TrailingStopGroupOrder)* Point || OrderStopLoss() == 0 )
                  {
                   if (!OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble (Ask + TrailingStopGroupOrder* Point , Digits ), tp, 0 ))
                     Print ( "Ошибка модификации групповых ордеров на продажу!" );
                  }
               }
            }
         } 
      }
   }
//+----------------------------------------------------------------------------+
//| Модификация групповых ордеров                                              |
//+----------------------------------------------------------------------------+
void ModifyOrders( int otype)
   {
   for ( int i = OrdersTotal ()- 1 ; i>= 0 ; i--)
      {
       if ( OrderSelect (i, SELECT_BY_POS, MODE_TRADES))
         {
         if (OrderSymbol() == Symbol () && OrderMagicNumber() == Magic && OrderType() == otype)
            {
             if (otype == OP_BUY)
               {
               tp = NormalizeDouble (GetAveragePrice() + TakeProfitGroupOrder* Point , Digits );
               if (OrderModify(OrderTicket(), OrderOpenPrice(), 0 , tp, 0 ))
                   Print ( "Ордера успешно модифицированы!" );
               else Print ( "Ошибка модификации ордеров!" );
               }
             if (otype == OP_SELL)
               {
               tp = NormalizeDouble (GetAveragePrice() - TakeProfitGroupOrder* Point , Digits );
               if (OrderModify(OrderTicket(), OrderOpenPrice(), 0 , tp, 0 ))
                   Print ( "Ордера успешно модифицированы!" );
               else Print ( "Ошибка модификации ордеров!" );
               }
            }
         }
      }
   }

기능 수정 - 불필요한 부분 제거
 
MakarFX # :

그것이 작동 방식입니다

제대로 작동합니까? 이 옵션에는 모든 문제가 있습니다. 그리고 이것은 mt5입니다.

 
MakarFX # :
그리고 왜 전혀 움직이는 것을 귀찮게합니까?

정렬용

 
Andrey Sokolov # :

정렬용

또한 정렬하지만 추가 기능이 없습니다.

 #property strict
#property indicator_chart_window
#property indicator_plots 0

enum ENUM_FULL_MANUAL { full, //весь график
            manual, //указанный
            };
input int timer= 5 ; //время на шаг в секундах
input ENUM_FULL_MANUAL skr_mode=full; //размер скриншота   
input int width = 640 ; // ширина 
input int height = 320 ; // высота 
input string format = ".png" ;

ENUM_ALIGN_MODE align_mode= ALIGN_RIGHT ; // тип выравнивания

string name_folder, name_file;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit ()
{
EventSetTimer (timer);
Print ( "OnInit()" );
name_folder= Symbol ()+ "  " +StringPeriod();
ScreenShot();

return ( INIT_SUCCEEDED );
}
//===================================================================
void OnDeinit ( const int reason)
{
EventKillTimer ();
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate ( const int rates_total,
             const int prev_calculated,
             const datetime &time[],
             const double &open[],
             const double &high[],
             const double &low[],
             const double &close[],
             const long &tick_volume[],
             const long &volume[],
             const int &spread[])
{
//---

//--- return value of prev_calculated for next call
return (rates_total);
}
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer ()
{
   Print ( "OnTimer() " );
   ScreenShot();
}
//+------------------------------------------------------------------+
bool ScreenShot(){   
   name_file= TimeToString ( TimeLocal (), TIME_DATE | TIME_SECONDS )+format;
   StringReplace (name_file, ":" , "-" );
   if (skr_mode==full){
       if ( ChartScreenShot ( 0 , name_folder+ "//" +name_file, ( int ) ChartGetInteger ( 0 , CHART_WIDTH_IN_PIXELS , 0 )
      , ( int ) ChartGetInteger ( 0 , CHART_HEIGHT_IN_PIXELS , 0 ), ALIGN_RIGHT )){
         Print ( "screen name_file " , name_file);
         return true ;
      }
       else {
         Print ( "screen ERR: " , GetLastError ());
      }   
   }   
   if (skr_mode==manual){
       if ( ChartScreenShot ( 0 , name_file, width, height, align_mode)){
         return true ;
      }
   }      
   return false ;  
}
string StringPeriod(){
   if ( Period ()== 1 ) return "M1" ;
   if ( Period ()== 2 ) return "M2" ;
   if ( Period ()== 3 ) return "M3" ;
   if ( Period ()== 4 ) return "M4" ;
   if ( Period ()== 5 ) return "M5" ;
   if ( Period ()== 6 ) return "M6" ;
   if ( Period ()== 10 ) return "M10" ;
   if ( Period ()== 12 ) return "M12" ;
   if ( Period ()== 15 ) return "M15" ;
   if ( Period ()== 20 ) return "M20" ;
   if ( Period ()== 30 ) return "M30" ;
   if ( Period ()== 16385 ) return "H1" ;
   if ( Period ()== 16386 ) return "H2" ;
   if ( Period ()== 16387 ) return "H3" ;
   if ( Period ()== 16388 ) return "H4" ;
   if ( Period ()== 16390 ) return "H6" ;
   if ( Period ()== 16392 ) return "H8" ;
   if ( Period ()== 16396 ) return "H12" ;
   if ( Period ()== 16408 ) return "Daily" ;
   if ( Period ()== 32769 ) return "Weekly" ;
   if ( Period ()== 49153 ) return "Monthly" ;
   return "ERROR" ;
}
 
Andrey Sokolov # :

제대로 작동합니까? 이 옵션에는 모든 문제가 있습니다. 그리고 이것은 mt5입니다.

죄송합니다, 4에 대해 썼습니다 ...

5시에 확인! 모든 것이 작동합니다.

 2021.10 . 03 17 : 55 : 54.192 Scrin (BTCUSD,M5)       OnTimer () 
2021.10 . 03 17 : 55 : 54.195 Scrin (BTCUSD,M5)       screen name_file 2021.10 . 03 17 - 55 - 54 .png
2021.10 . 03 17 : 55 : 59.211 Scrin (BTCUSD,M5)       OnTimer () 
2021.10 . 03 17 : 55 : 59.213 Scrin (BTCUSD,M5)       screen name_file 2021.10 . 03 17 - 55 - 59 .png
2021.10 . 03 17 : 56 : 04.214 Scrin (BTCUSD,M5)       OnTimer () 
2021.10 . 03 17 : 56 : 04.217 Scrin (BTCUSD,M5)       screen name_file 2021.10 . 03 17 - 56 - 04 .png
2021.10 . 03 17 : 56 : 09.204 Scrin (BTCUSD,M5)       OnTimer () 
2021.10 . 03 17 : 56 : 09.236 Scrin (BTCUSD,M5)       screen name_file 2021.10 . 03 17 - 56 - 09 .png
2021.10 . 03 17 : 56 : 14.202 Scrin (BTCUSD,M5)       OnTimer () 
2021.10 . 03 17 : 56 : 14.205 Scrin (BTCUSD,M5)       screen name_file 2021.10 . 03 17 - 56 - 14 .png
파일:
Scrin.mq5  8 kb
 
MakarFX # :

대충 이정도...

기능 수정 - 불필요한 부분 제거

Makar, 코드의 어느 부분에서 함수에 대한 참조가 있는지 설명할 수 있습니까?

 //+----------------------------------------------------------------------------+
//| Модификация групповых ордеров                                              |
//+----------------------------------------------------------------------------+
void ModifyOrders( int otype)
{
     for ( int i = OrdersTotal ()- 1 ; i>= 0 ; i--)
    {
       if ( OrderSelect (i, SELECT_BY_POS, MODE_TRADES))
       {
         if (OrderSymbol() == Symbol () && OrderMagicNumber() == Magic && OrderType() == otype)
          {
           if (otype == OP_BUY) tp = NormalizeDouble (GetAveragePrice() + TakeProfitGroupOrder* Point , Digits );
           if (otype == OP_SELL) tp = NormalizeDouble (GetAveragePrice() - TakeProfitGroupOrder* Point , Digits );
           if ((otype == OP_BUY || otype == OP_SELL) && (Drawdown > DrawdownClosingTakeprofitZero)) 
           tp = NormalizeDouble (GetAveragePrice(), Digits );
          }
       }
    }
     for ( int i = OrdersTotal ()- 1 ; i>= 0 ; i--) 
    {
       if ( OrderSelect (i, SELECT_BY_POS, MODE_TRADES))
       {
           if (OrderSymbol() == Symbol () && OrderMagicNumber() == Magic && OrderType() == otype)
           {
               if (OrderModify(OrderTicket(), OrderOpenPrice(), 0 , tp, 0 ))
                   Print ( "Ордера успешно модифицированы!" );
                 else Print ( "Ошибка модификации ордеров!" );
                TrailingGroupOrder();
           }
       }
    }
}