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

 
Vladimir Pastushak :

ZeroMemory(...)는 문자열 유형의 배열을 NULL로 초기화합니다.


안녕하세요. 질문은 다음입니다. 나는 Expert Advisor를 썼고, 뒤에 마침표를 붙이고 컴파일했습니다. ....... 작동하지 않습니다 :))))). 컴퓨터를 재부팅하고 소스를 수정하고 시작했습니다. 입력 매개변수를 통해 구성을 시작했는데 다시 작동하지 않거나 한 번만 변경되었습니다. .................. Windows가 버그가 있거나 어딘가에서 다시 망쳤을 수 있습니다. 소스코드를 첨부합니다.

//+------------------------------------------------------------------+
//|                                                        test8.mq4 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//-------------------------------------------------------------------
extern double lots            = 0.1;
extern int    TakeProfit      = 100;
extern int    StopLoss        = 50;
extern int    Magic           = 777; 
extern int    Slippage        = 3;

//-------------------------------------------------------------------
extern string TMA             = "Параметры индикатора TMA";
extern string TimeFrame       = "current time frame";
extern int    HalfLength      = 56; 
extern int    Price           = PRICE_CLOSE;
extern double ATRMultiplier   = 2.0;
extern int    ATRPeriod       = 100;
extern bool   Interpolate     = true;
extern int    TrailingStop    = 50; 
extern int    TrailingStep    = 20;
int    timeprev        = 0;
//-------------------------------------------------------------------
double PriceHigh, PriceLow, SL ,TP;
int ticket;


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   if (Digits == 3 || Digits == 5);
   {
       TakeProfit   *=10;
       Slippage     *=10;
       TrailingStop *=10;
       TrailingStep *=10;
     
       
   }  
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
    if (timeprev == Time [0])return;
         timeprev = Time [0];
  
    PriceHigh = iCustom(NULL, 0, "TMA_Fair", TimeFrame, HalfLength, Price, ATRMultiplier, ATRPeriod, Interpolate, 1, 0);  
    PriceLow  = iCustom(NULL, 0, "TMA_Fair", TimeFrame, HalfLength, Price, ATRMultiplier, ATRPeriod, Interpolate, 2, 0);  
    
    if (CountSell() == 0 && Bid >= PriceHigh)
    {
        ticket = OrderSend(Symbol(), OP_SELL, lots, Bid, Slippage, 0, 0, "TMA robot", Magic, 0, Red);  
        if (ticket > 0)
        {
            TP = NormalizeDouble(Bid - TakeProfit*Point, Digits);
            SL = NormalizeDouble(Bid + StopLoss*Point, Digits);
            if (OrderSelect(ticket, SELECT_BY_TICKET)) 
                if(!OrderModify(ticket, OrderOpenPrice(), SL, TP, 0));
                    Print("Ошибк амодификации ордера на продажу!");
        } else Print("Ошибка открытия ордера на продаду!"); 
    }
  

    if (CountBuy() == 0 && Ask <= PriceLow)
    
      {
         ticket = OrderSend(Symbol(), OP_BUY, lots, Ask, Slippage, 0, 0, "TMA robot", Magic, 0, Blue);  
         if (ticket > 0)
           { 
                SL = NormalizeDouble(Ask - StopLoss*Point, Digits);
                TP = NormalizeDouble(Ask + TakeProfit*Point, Digits);
                if (OrderSelect(ticket, SELECT_BY_TICKET)) 
                if(!OrderModify(ticket, OrderOpenPrice(), SL, TP, 0));
                  Print ("Ошибка модификации ордера на покупку!");
           }      else Print("Ошибка открытия ордера на покупкку!");
      }
     
     Trailing();    
    }
//+------------------------------------------------------------------+
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)
            {
               if (Bid - OrderOpenPrice() > TrailingStop*Point || OrderStopLoss() == 0)
               {
                   if (OrderStopLoss() < Bid-(TrailingStop+TrailingStep)*Point || OrderStopLoss() == 0)
                   {
                      if (!OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble (Bid-TrailingStop*Point, Digits), 0, 0))
                         Print ("Ошибка модификации ордера на покупку!");
                   } 
               }
            }
            
            if (OrderType() == OP_SELL)
            {
                if (OrderOpenPrice() - Ask > TrailingStop*Point || OrderStopLoss() == 0)
                {
                    if (OrderStopLoss() > Ask + (TrailingStop+TrailingStep)*Point || OrderStopLoss() == 0)
                    {
                        if (!OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble( Ask + TrailingStop*Point, Digits), 0, 0))
                             Print ("Ошибка модификации ордера на родажу!"); 
                    }
                    
                }
            }
         
         }
      }
    }
}
  
//+------------------------------------------------------------------+


int CountSell() 
  {
    int count = 0;
    for (int trade = OrdersTotal()-1; trade>=0; trade--)
    {
       if (OrderSelect(trade, SELECT_BY_POS, MODE_TRADES))
       {
          if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_SELL)
             count++;
       }   
    }
    return(count);
  }
//-----------------------------------------------------------------------------------------------  
  int CountBuy() 
  {
    int count = 0;

    for (int trade = OrdersTotal()-1; trade>=0; trade--)
    {
       if (OrderSelect(trade, SELECT_BY_POS, MODE_TRADES))
       {
          if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_BUY)
             count++;
       }   
    }
    return(count);
  }
//-----------------------------------------------------------------------------------------------  
  
       
       
  
 

안녕하세요. 질문은 다음입니다. 나는 Expert Advisor 를 썼고, 뒤에 마침표를 붙이고 컴파일했습니다.......... 작동하지 않습니다. :))))). 더 정확히는 후행은 되는데 기존에 등록된 수익이 안 나는데 그 이유는 무엇일까요?

Как самому создать советника или индикатор - Алгоритмический трейдинг, торговые роботы - Справка по MetaTrader 5
Как самому создать советника или индикатор - Алгоритмический трейдинг, торговые роботы - Справка по MetaTrader 5
  • www.metatrader5.com
Для разработки торговых систем в платформу встроен собственный язык программирования MetaQuotes Language 5 ( MQL5 ), среда разработки MetaEditor и...
 
danil77783 :

안녕하세요. 질문은 다음입니다. 나는 Expert Advisor 를 썼고, 뒤에 마침표를 붙이고 컴파일했습니다.......... 작동하지 않습니다. :))))). 컴퓨터를 재부팅하고 소스를 수정하고 시작했습니다. 입력 매개변수를 통해 구성을 시작했는데 다시 작동하지 않거나 한 번만 변경되었습니다. .................. Windows가 버그가 있거나 어딘가에서 다시 망쳤을 수 있습니다. 소스코드를 첨부합니다.


 if (timeprev == Time [0])
{
         timeprev = Time [0];
return;

}

 
Vladimir Pastushak :


taikprofit은 여전히 노출되지 않습니다.... 다시 봐주세요.

 
danil77783 :

taikprofit은 여전히 노출되지 않습니다.... 다시 봐주세요.


후행 함수의 모든 주문에 대해 take 0을 설정하고 열 때 올바른 주문을 설정합니다.

논리를 한 줄씩 읽고,

주문을 열었습니다 중지 및 가져

0으로 설정된 후행 정지 시작

후행 0을 OrderTakeProfit()으로 교체

 

이제 그는 손절매를 하지 않습니다

 
danil77783 :

이제 그는 손절매를 하지 않습니다


새 코드 표시

 
Vladimir Pastushak :

새 코드 표시





 //+------------------------------------------------------------------+
//|                                                        test8.mq4 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link        "https://www.mql5.com"
#property version    "1.00"
#property strict
//-------------------------------------------------------------------
extern double lots            = 0.1 ;
extern int     TakeProfit      = 50 ;
extern int     StopLoss        = 50 ;
extern int     Magic           = 777 ; 
extern int     Slippage        = 3 ;

//-------------------------------------------------------------------
extern string TMA             = "Параметры индикатора TMA" ;
extern string TimeFrame       = "current time frame" ;
extern int     HalfLength      = 56 ; 
extern int     Price           = PRICE_CLOSE ;
extern double ATRMultiplier   = 2.0 ;
extern int     ATRPeriod       = 100 ;
extern bool    Interpolate     = true ;
extern int     TrailingStop    = 50 ; 
extern int     TrailingStep    = 20 ;
int     timeprev        = 0 ;
//-------------------------------------------------------------------
double PriceHigh, PriceLow, SL ,TP;
int ticket;


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit ()
  {
   if ( Digits == 3 || Digits == 5 );
   {
       TakeProfit   *= 10 ;
       Slippage     *= 10 ;
       TrailingStop *= 10 ;
       TrailingStep *= 10 ;
     
       
   }  
   return ( INIT_SUCCEEDED );
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit ( const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick ()
  {
     if (timeprev == Time [ 0 ])
    {
         timeprev = Time [ 0 ];
         return ;
  }
    PriceHigh = iCustom ( NULL , 0 , "TMA_Fair" , TimeFrame, HalfLength, Price, ATRMultiplier, ATRPeriod, Interpolate, 1 , 0 );  
    PriceLow  = iCustom ( NULL , 0 , "TMA_Fair" , TimeFrame, HalfLength, Price, ATRMultiplier, ATRPeriod, Interpolate, 2 , 0 );  
    
     if (CountSell() == 0 && Bid >= PriceHigh)
    {
        ticket = OrderSend ( Symbol (), OP_SELL , lots, Bid , Slippage, 0 , 0 , "TMA robot" , Magic, 0 , Red);  
         if (ticket > 0 )
        {
            TP = NormalizeDouble ( Bid - TakeProfit* Point , Digits );
           
             if ( OrderSelect (ticket, SELECT_BY_TICKET )) 
                 if (! OrderModify (ticket, OrderOpenPrice (), SL, TP, 0 ));
                     Print ( "Ошибк амодификации ордера на продажу!" );
        } else Print ( "Ошибка открытия ордера на продаду!" ); 
    }
  

     if (CountBuy() == 0 && Ask <= PriceLow)
    
      {
         ticket = OrderSend ( Symbol (), OP_BUY , lots, Ask , Slippage, 0 , 0 , "TMA robot" , Magic, 0 , Blue);  
         if (ticket > 0 )
           { 
               
                TP = NormalizeDouble ( Ask + TakeProfit* Point , Digits );
                 if ( OrderSelect (ticket, SELECT_BY_TICKET )) 
                 if (! OrderModify (ticket, OrderOpenPrice (), SL, TP, 0 ));
                   Print ( "Ошибка модификации ордера на покупку!" );
           }       else Print ( "Ошибка открытия ордера на покупкку!" );
      }
     
     Trailing();    
    }
//+------------------------------------------------------------------+
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 )
            {
               if ( Bid - OrderOpenPrice () > TrailingStop* Point || OrderStopLoss () == 0 )
               {
                   if ( OrderStopLoss () < Bid -(TrailingStop+TrailingStep)* Point || OrderStopLoss () == OrderTakeProfit () )
                   {
                       if (! OrderModify ( OrderTicket (), OrderOpenPrice (), NormalizeDouble ( Bid -TrailingStop* Point , Digits ), 0 , 0 ))
                         Print ( "Ошибка модификации ордера на покупку!" );
                   } 
               }
            }
            
             if ( OrderType () == OP_SELL )
            {
                 if ( OrderOpenPrice () - Ask > TrailingStop* Point || OrderStopLoss () == 0 )
                {
                     if ( OrderStopLoss () > Ask + (TrailingStop+TrailingStep)* Point || OrderStopLoss () == OrderTakeProfit ( ) )
                    {
                         if (! OrderModify ( OrderTicket (), OrderOpenPrice (), NormalizeDouble ( Ask + TrailingStop* Point , Digits ), 0 , 0 ))
                             Print ( "Ошибка модификации ордера на родажу!" ); 
                    }
                    
                }
            }
         
         }
      }
    }
}
  
//+------------------------------------------------------------------+


int CountSell() 
  {
     int count = 0 ;
     for ( int trade = OrdersTotal ()- 1 ; trade>= 0 ; trade--)
    {
       if ( OrderSelect (trade, SELECT_BY_POS , MODE_TRADES ))
       {
           if ( OrderSymbol () == Symbol () && OrderMagicNumber () == Magic && OrderType () == OP_SELL )
             count++;
       }   
    }
     return (count);
  }
//-----------------------------------------------------------------------------------------------  
   int CountBuy() 
  {
     int count = 0 ;

     for ( int trade = OrdersTotal ()- 1 ; trade>= 0 ; trade--)
    {
       if ( OrderSelect (trade, SELECT_BY_POS , MODE_TRADES ))
       {
           if ( OrderSymbol () == Symbol () && OrderMagicNumber () == Magic && OrderType () == OP_BUY )
             count++;
       }   
    }
     return (count);
  }
//-----------------------------------------------------------------------------------------------  
  
       
       
  
 
danil77783 :





나는 0 대신에 당신의 후행 베팅에서 분명히 당신에게 썼습니다.

이 옵션을 확인하십시오

//+------------------------------------------------------------------+
//|                                                        test8.mq4 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link        "https://www.mql5.com"
#property version    "1.00"
#property strict
//-------------------------------------------------------------------
extern double lots            = 0.1 ;
extern int     TakeProfit      = 100 ;
extern int     StopLoss        = 50 ;
extern int     Magic           = 777 ; 
extern int     Slippage        = 3 ;

//-------------------------------------------------------------------
extern string TMA             = "Параметры индикатора TMA" ;
extern string TimeFrame       = "current time frame" ;
extern int     HalfLength      = 56 ; 
extern int     Price           = PRICE_CLOSE ;
extern double ATRMultiplier   = 2.0 ;
extern int     ATRPeriod       = 100 ;
extern bool    Interpolate     = true ;
extern int     TrailingStop    = 50 ; 
extern int     TrailingStep    = 20 ;
int     timeprev        = 0 ;
//-------------------------------------------------------------------
double PriceHigh, PriceLow, SL ,TP;
int ticket;


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit ()
  {
   if ( Digits == 3 || Digits == 5 );
   {
       TakeProfit   *= 10 ;
       Slippage     *= 10 ;
       TrailingStop *= 10 ;
       TrailingStep *= 10 ;
     
       
   }  
   return ( INIT_SUCCEEDED );
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit ( const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick ()
  {
     if (timeprev == Time [ 0 ]) return ;
         timeprev = Time [ 0 ];
  
    PriceHigh = iCustom ( NULL , 0 , "TMA_Fair" , TimeFrame, HalfLength, Price, ATRMultiplier, ATRPeriod, Interpolate, 1 , 0 );  
    PriceLow  = iCustom ( NULL , 0 , "TMA_Fair" , TimeFrame, HalfLength, Price, ATRMultiplier, ATRPeriod, Interpolate, 2 , 0 );  
    
     if (CountSell() == 0 && Bid >= PriceHigh)
    {
        ticket = OrderSend ( Symbol (), OP_SELL , lots, Bid , Slippage, 0 , 0 , "TMA robot" , Magic, 0 , Red);  
         if (ticket > 0 )
        {
            TP = NormalizeDouble ( Bid - TakeProfit* Point , Digits );
            SL = NormalizeDouble ( Bid + StopLoss* Point , Digits );
             if ( OrderSelect (ticket, SELECT_BY_TICKET )) 
                 if (! OrderModify (ticket, OrderOpenPrice (), SL, TP, 0 ));
                     Print ( "Ошибк амодификации ордера на продажу!" );
        } else Print ( "Ошибка открытия ордера на продаду!" ); 
    }
  

     if (CountBuy() == 0 && Ask <= PriceLow)
    
      {
         ticket = OrderSend ( Symbol (), OP_BUY , lots, Ask , Slippage, 0 , 0 , "TMA robot" , Magic, 0 , Blue);  
         if (ticket > 0 )
           { 
                SL = NormalizeDouble ( Ask - StopLoss* Point , Digits );
                TP = NormalizeDouble ( Ask + TakeProfit* Point , Digits );
                 if ( OrderSelect (ticket, SELECT_BY_TICKET )) 
                 if (! OrderModify (ticket, OrderOpenPrice (), SL, TP, 0 ));
                   Print ( "Ошибка модификации ордера на покупку!" );
           }       else Print ( "Ошибка открытия ордера на покупкку!" );
      }
     
     Trailing();    
    }
//+------------------------------------------------------------------+
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 )
            {
               if ( Bid - OrderOpenPrice () > TrailingStop* Point || OrderStopLoss () == 0 )
               {
                   if ( OrderStopLoss () < Bid -(TrailingStop+TrailingStep)* Point || OrderStopLoss () == 0 )
                   {
                       if (! OrderModify ( OrderTicket (), OrderOpenPrice (), NormalizeDouble ( Bid -TrailingStop* Point , Digits ), OrderTakeProfit () , 0 ))  //          --------------------------
                         Print ( "Ошибка модификации ордера на покупку!" );
                   } 
               }
            }
            
             if ( OrderType () == OP_SELL )
            {
                 if ( OrderOpenPrice () - Ask > TrailingStop* Point || OrderStopLoss () == 0 )
                {
                     if ( OrderStopLoss () > Ask + (TrailingStop+TrailingStep)* Point || OrderStopLoss () == 0 )
                    {
                         if (! OrderModify ( OrderTicket (), OrderOpenPrice (), NormalizeDouble ( Ask + TrailingStop* Point , Digits ), OrderTakeProfit () , 0 ))   //          --------------------------
                             Print ( "Ошибка модификации ордера на родажу!" ); 
                    }
                    
                }
            }
         
         }
      }
    }
}
  
//+------------------------------------------------------------------+


int CountSell() 
  {
     int count = 0 ;
     for ( int trade = OrdersTotal ()- 1 ; trade>= 0 ; trade--)
    {
       if ( OrderSelect (trade, SELECT_BY_POS , MODE_TRADES ))
       {
           if ( OrderSymbol () == Symbol () && OrderMagicNumber () == Magic && OrderType () == OP_SELL )
             count++;
       }   
    }
     return (count);
  }
//-----------------------------------------------------------------------------------------------  
   int CountBuy() 
  {
     int count = 0 ;

     for ( int trade = OrdersTotal ()- 1 ; trade>= 0 ; trade--)
    {
       if ( OrderSelect (trade, SELECT_BY_POS , MODE_TRADES ))
       {
           if ( OrderSymbol () == Symbol () && OrderMagicNumber () == Magic && OrderType () == OP_BUY )
             count++;
       }   
    }
     return (count);
  }
//-----------------------------------------------------------------------------------------------  
 
안녕하세요.
첫 번째 막대의 MA 가격과 이전 네 막대의 MA 가격을 비교하는 데 도움을 주세요. 가격이 상승하고 차이가 N보다 크면 버퍼를 채웁니다. 이런 노력
    
    MA_1  = iMA ( NULL , 0 , ma_period, 0 , ma_method,applied_price, i+ 1 );
    MA_2  = iMA ( NULL , 0 , ma_period, 0 , ma_method,applied_price, i+ 2 );
    MA_3  = iMA ( NULL , 0 , ma_period, 0 , ma_method,applied_price, i+ 3 );
     if (MA_1>MA_2)
    {
    double N_=0.005;
    BarCount= 4 ;
    BUL=false;
   for ( int il=i+1;il<=BarCount;il++)
     {
       if ( iMA ( NULL , 0 , ma_period, 0 , ma_method,applied_price, i)- iMA ( NULL , 0 , ma_period, 0 , ma_method,applied_price, i+il)>=N_ )
      {BUL= true ; break ;}
     }
     RefreshRates ();
       if (BUL)
       {
      BufferUP[i+ 1 ]=low[i+ 1 ]-distance*MyPoint;
      BUL= false ;
    
       }
       }