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

 
missha689 :
프로그래밍 방식으로 어제 날짜와 시간을 얻는 방법

따라서 필요한 모든 것이 있으므로 읽기만 하면 됩니다. 예를 들어 이것은

iTime ( "USDCHF" , PERIOD_H1 , 0 )
지정된 기호를 _Symbol로 바꾸고 PERIOD_H1을 PERIOD_D1로 바꾸면 다음과 같이 영업 시간이 표시 됩니다. 0을 1로 바꾸면 어제의 영업 시간이 됩니다.

 
missha689 :
프로그래밍 방식으로 어제 날짜와 시간을 얻는 방법

어제 달력:

datetime tim=TimeCurrent()‌-24*60*60;

MqlDateTime ts;

TimeToStruct(tim,ts);

ts.hour=0;ts.min=0;ts.sec=0;

tim=StructToTime(ts);

now in tim - 어제의 시작일(!! 이전 막대 D1 의 여는 시간이 아님)

선행 바 개방 시간 D1 - iTime(0,PERIOD_D1,1); 약간 수정 - 토요일인 경우 일요일인 경우 24시간을 추가합니다. 그럼 48시간.

 
Alexey Viktorov :

따라서 필요한 모든 것이 있으므로 읽기만 하면 됩니다. 예를 들어 이것은

iTime ( "USDCHF" , PERIOD_H1 , 0 )
지정된 기호를 _Symbol로 바꾸고 PERIOD_H1을 PERIOD_D1로 바꾸면 다음과 같이 영업 시간이 표시 됩니다. 0을 1로 바꾸면 어제의 영업 시간이 됩니다.

어제부터 이미 방법을 알아 내려고 노력하고 있지만 작동하지 않아이 사업이 처음이기 때문에 도움을 요청합니다.

어제의 막대 지수(예: 15:00)와 오늘의 막대 지수(예: 7:00)를 찾도록 도와주세요. 예제와 같이 날짜를 명시적으로 지정하지 않고만

 
Maxim Kuznetsov :

어제 달력:

datetime tim=TimeCurrent()‌-24*60*60;

MqlDateTime ts;

TimeToStruct(tim,ts);

ts.hour=0;ts.min=0;ts.sec=0;

tim=StructToTime(ts);

now in tim - 어제의 시작일(!! 이전 막대 D1 의 여는 시간이 아님)

선행 바 개방 시간 D1 - iTime(0,PERIOD_D1,1); 약간 수정 - 토요일인 경우 일요일인 경우 24시간을 추가합니다. 그럼 48시간.

감사해요
 
Sergey Gritsay :


stband를 손익분기점으로 전환하는 기능, 주문 티켓 및 전환할 거리(핍 단위)가 함수에 전달됩니다.

void zero_profit( int ticket, int distance)
  {
   double sl= 0.0 ;

   if ( OrderSelect (ticket, SELECT_BY_TICKET ))
     {
       if ( OrderType ()== OP_BUY )
        {
         if ( Bid >= OrderOpenPrice () && Bid - OrderOpenPrice ()>=distance* _Point ) sl= OrderOpenPrice ();
         if ( OrderStopLoss ()!= 0 && OrderStopLoss ()>= OrderOpenPrice ()) return ;
        }
       if ( OrderType ()== OP_SELL )
        {
         if ( Ask <= OrderOpenPrice () && OrderOpenPrice ()- Ask >=distance* _Point ) sl= OrderOpenPrice ();
         if ( OrderStopLoss ()!= 0 && OrderStopLoss ()<= OrderOpenPrice ()) return ;
        }
       ResetLastError ();

       if (sl<= 0 ) return ;
       if (! OrderModify ( OrderTicket (), OrderOpenPrice (),sl, OrderTakeProfit (), 0 ))
        {
         int error= GetLastError ();
         rezult= StringConcatenate ( OrderSymbol (), ": error modifying StopLoss order " , OrderTicket (), " " ,TypeToStr( OrderType ()), " №- " ,error);
         Print (rezult);
        }

     }
  }


... 감사합니다 세르게이!!!!!

 
Vitaly Muzichenko :

좋습니다. 어드바이저에서 기능을 꺼내려고 합니다. 결과는 나중에 올리겠습니다.

감사해요!!!

두 번째 검색 방법을 추가했습니다.

//+------------------------------------------------------------------+
//|                                             iFreeNumFractals.mq4 |
//|              Copyright 2017, Artem A. Trishkin, Skype artmedia70 |
//|                       https://login.mql5.com/ru/users/artmedia70 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, Artem A. Trishkin, Skype artmedia70"
#property link        "https://login.mql5.com/ru/users/artmedia70"
#property version    "3.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots    2
//--- plot UpperFractal
#property indicator_label1   "Upper Fractal"
#property indicator_type1   DRAW_ARROW
#property indicator_color1   clrRed
#property indicator_style1   STYLE_SOLID
#property indicator_width1   1
//--- plot LowerFractal
#property indicator_label2   "Lower Fractal"
#property indicator_type2   DRAW_ARROW
#property indicator_color2   clrSteelBlue
#property indicator_style2   STYLE_SOLID
#property indicator_width2   1
//---
enum ENUM_TYPE_FRACTAL
  {
   TYPE_FRACTAL_ACCURATE   =   0 ,     // Accurate fractal
   TYPE_FRACTAL_INACCURATE =   1 ,     // Inaccurate fractal
  };
//--- input parameters
input ENUM_TYPE_FRACTAL TypeFractals   =  TYPE_FRACTAL_ACCURATE;   // Type of fractal
input int                LeftNumUp      =   2 ;                       // The number of bars on the left for upper fractals
int leftNumUp;     // Количество баров слева для верхнего фрактала
input int                RightNumUp     =   2 ;                       // The number of bars on the right for upper fractals
int rightNumUp;   // Количество баров справа для верхнего фрактала
input int                LeftNumDn      =   2 ;                       // The number of bars on the left for lower fractals
int leftNumDn;     // Количество баров слева для нижнего фрактала
input int                RightNumDn     =   2 ;                       // The number of bars on the right for lower fractals
int rightNumDn;   // Количество баров справа для нижнего фрактала
//--- indicator buffers
double          BufferUpperFractal[];
double          BufferLowerFractal[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit ()
  {
//--- indicator buffers mapping
   SetIndexBuffer ( 0 ,BufferUpperFractal);
   SetIndexBuffer ( 1 ,BufferLowerFractal);
//--- setting a code from the Wingdings charset as the property of PLOT_ARROW
   PlotIndexSetInteger ( 0 , PLOT_ARROW , 217 );
   PlotIndexSetInteger ( 1 , PLOT_ARROW , 218 );
   SetIndexArrow ( 0 , 217 );
   SetIndexArrow ( 1 , 218 );
   SetIndexEmptyValue ( 0 , EMPTY_VALUE );
   SetIndexEmptyValue ( 1 , EMPTY_VALUE );
//---
   leftNumUp=(LeftNumUp< 1 ? 1 :LeftNumUp);
   rightNumUp=(RightNumUp< 1 ? 1 :RightNumUp);
   leftNumDn=(LeftNumDn< 1 ? 1 :LeftNumDn);
   rightNumDn=(RightNumDn< 1 ? 1 :RightNumDn);
   string short_name= MQLInfoString ( MQL_PROGRAM_NAME )+ "(" +( string )leftNumUp+ "," +( string )rightNumUp+ ")(" +( string )leftNumDn+ "," +( string )rightNumDn+ ")" ;
   IndicatorSetString ( INDICATOR_SHORTNAME ,short_name);
   IndicatorSetInteger ( INDICATOR_DIGITS , Digits ());
//---
   return ( INIT_SUCCEEDED );
  }
//+------------------------------------------------------------------+
//| 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[])
  {
//---
   if (rates_total< fmax (leftNumUp+rightNumUp,leftNumDn+rightNumDn)) return ( 0 );
   int limit=rates_total-prev_calculated;
   if (limit> 0 ) {
       ArrayInitialize (BufferUpperFractal, 0.0 );
       ArrayInitialize (BufferUpperFractal, 0.0 );
      limit=rates_total- fmax (leftNumUp,leftNumDn)- 1 ;
      }
   //---
   for ( int i=limit; i> fmin (rightNumUp,rightNumDn); i--) {
       if (GetFreeUpperFractal( Symbol (), PERIOD_CURRENT ,i,leftNumUp,rightNumUp)> 0 ) BufferUpperFractal[i]=high[i];
       if (GetFreeLowerFractal( Symbol (), PERIOD_CURRENT ,i,leftNumDn,rightNumDn)> 0 ) BufferLowerFractal[i]=low[i];
      }
//--- return value of prev_calculated for next call
   return (rates_total);
  }
//+----------------------------------------------------------------------------+
double GetFreeLowerFractal( const string symbol_name, ENUM_TIMEFRAMES timeframe, int shift, int left_dimension= 2 , int right_dimension= 2 ) {
   int bars= Bars (symbol_name,timeframe);
   if (left_dimension< 1 )  left_dimension= 1 ;
   if (right_dimension< 1 ) right_dimension= 1 ;
   if (shift-right_dimension< 1 || shift+left_dimension>bars- 1 ) return (- 1 );
   if (TypeFractals==TYPE_FRACTAL_ACCURATE) {
       for ( int i=shift- 1 ; i>=shift-right_dimension; i--) if (GetPriceLow(symbol_name,timeframe,i)<GetPriceLow(symbol_name,timeframe,i+ 1 )) return (- 1 );
       for ( int i=shift+ 1 ; i<=shift+left_dimension; i++)   if (GetPriceLow(symbol_name,timeframe,i)<GetPriceLow(symbol_name,timeframe,i- 1 )) return (- 1 );
      }
   else {
       for ( int i=shift- 1 ; i>=shift-right_dimension; i--) if (GetPriceLow(symbol_name,timeframe,i)<GetPriceLow(symbol_name,timeframe,shift)) return (- 1 );
       for ( int i=shift+ 1 ; i<=shift+left_dimension; i++)   if (GetPriceLow(symbol_name,timeframe,i)<GetPriceLow(symbol_name,timeframe,shift)) return (- 1 );
      }
   return (GetPriceLow(symbol_name,timeframe,shift));
}
//+----------------------------------------------------------------------------+
double GetFreeUpperFractal( const string symbol_name, ENUM_TIMEFRAMES timeframe, int shift, int left_dimension= 2 , int right_dimension= 2 ) {
   int bars= Bars (symbol_name,timeframe);
   if (left_dimension< 1 )  left_dimension= 1 ;
   if (right_dimension< 1 ) right_dimension= 1 ;
   if (shift-right_dimension< 1 || shift+left_dimension>bars- 1 ) return (- 1 );
   if (TypeFractals==TYPE_FRACTAL_ACCURATE) {
       for ( int i=shift- 1 ; i>=shift-right_dimension; i--) if (GetPriceHigh(symbol_name,timeframe,i)>GetPriceHigh(symbol_name,timeframe,i+ 1 )) return (- 1 );
       for ( int i=shift+ 1 ; i<=shift+left_dimension; i++)   if (GetPriceHigh(symbol_name,timeframe,i)>GetPriceHigh(symbol_name,timeframe,i- 1 )) return (- 1 );
      }
   else {
       for ( int i=shift- 1 ; i>=shift-right_dimension; i--) if (GetPriceHigh(symbol_name,timeframe,i)>GetPriceHigh(symbol_name,timeframe,shift)) return (- 1 );
       for ( int i=shift+ 1 ; i<=shift+left_dimension; i++)   if (GetPriceHigh(symbol_name,timeframe,i)>GetPriceHigh(symbol_name,timeframe,shift)) return (- 1 );
      }
   return (GetPriceHigh(symbol_name,timeframe,shift));
}
//+----------------------------------------------------------------------------+
double GetPriceHigh( const string symbol_name, ENUM_TIMEFRAMES timeframe, int shift){
   double array[ 1 ];
   if ( CopyHigh (symbol_name,timeframe,shift, 1 ,array)== 1 ) return (array[ 0 ]);
   return (- 1 );
}
//+----------------------------------------------------------------------------+
double GetPriceLow( const string symbol_name, ENUM_TIMEFRAMES timeframe, int shift){
   double array[ 1 ];
   if ( CopyLow (symbol_name,timeframe,shift, 1 ,array)== 1 ) return (array[ 0 ]);
   return (- 1 );
}
//+----------------------------------------------------------------------------+

파일:
 
Artyom Trishkin :

두 번째 검색 방법을 추가했습니다.


감사합니다.

O‌코드베이스에 업로드하기 위해 떠남)

 
Vitaly Muzichenko :

감사합니다.

O‌코드베이스에 업로드하기 위해 떠남)

이미 :)) 확인을 위해 보냈습니다.
 

안녕하세요.

‌저는 Linux를 사용 중입니다. 여러 통화 쌍이 MT4에서 열려 있습니다(최대 10개). MQL4 언어를 사용하여 특정 순서로 차트 탭을 정렬하려면 어떻게 해야 합니까?

프로필 작업, 1_MQL4.pdf 공부, 인터넷은 아무 소용이 없었다.‌

안부 인사를 전합니다. 블라디미르

 
DVlad :

안녕하세요.

‌저는 Linux를 사용 중입니다. 여러 통화 쌍이 MT4에서 열려 있습니다(최대 10개). MQL4 언어를 사용하여 특정 순서로 차트 탭을 정렬하려면 어떻게 해야 합니까?

프로필 작업, 1_MQL4.pdf 공부, 인터넷은 아무 소용이 없었다.‌

안부 인사를 전합니다. 블라디미르

Windows에서도 mql4를 사용하여 탭을 정렬할 수 없습니다.

필요한 순서대로 차트를 열고 원하는 템플릿을 설치할 수 있습니다.‌