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

 
Sergey Gritsay :
마감 주문 수정을 위해 블록에 잼이있었습니다.
정말 감사합니다 지금 확인하겠습니다!
 

주문이 열리지 않는 이유를 알려주세요. 오류 130 을 제공합니다.

input double RSIperiod= 14 ;
input double Urov_70= 70 ;
input double Urov_30= 30 ;
input double Lot= 0.01 ;
input int     TakeProfit= 100 ;
input int     StopLoss= 100 ;
input int     MagicNumber= 523 ;
input int     slippage= 30 ;

double tp= 0 ,sl= 0 ,OrderBuy= 0 ,OrderSell= 0 ;
int tiket;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit ()
  {
//---
   tp= NormalizeDouble (TakeProfit* _Point , _Digits );
   sl= NormalizeDouble (StopLoss* _Point , _Digits );
   return ( INIT_SUCCEEDED );
//---
   return ( INIT_SUCCEEDED );
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit ( const int reason)
  {

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick ()
  {

   for ( int i= 0 ; i< OrdersTotal (); i++)
     {
       if ( OrderSelect (i, SELECT_BY_POS , MODE_TRADES ))
         if ( OrderSymbol ()== _Symbol && OrderMagicNumber ()==MagicNumber)
           {
             if ( OrderType ()== OP_BUY ){}
             if ( OrderType ()== OP_SELL ){}
           }
     }
   double rsi= iRSI ( _Symbol , 0 ,RSIperiod, PRICE_CLOSE , 0 );
   double rsi1= iRSI ( _Symbol , 0 ,RSIperiod, PRICE_CLOSE , 1 );
//+------------------------------------------------------------------+
   if (OrderBuy< 1 && rsi>Urov_70 && rsi1<Urov_70)
     {
     tiket= OrderSend ( _Symbol , OP_BUY ,Lot, Ask ,slippage,sl,tp, NULL ,MagicNumber, 0 , clrBlue );
     }
   if (OrderSell< 1 && rsi<Urov_30 && rsi1>Urov_30)
     {
      tiket= OrderSend ( _Symbol , OP_SELL ,Lot, Bid ,slippage,sl,tp, NULL ,MagicNumber, 0 , clrRed );
     }
  }
//+------------------------------------------------------------------+

 

나는 전문가가 아닙니다. 틀릴 수 있습니다!

여기 라인이 있습니다

tp= NormalizeDouble (TakeProfit* _Point , _Digits );

sl= NormalizeDouble (StopLoss* _Point , _Digits );

하면 더 명확해질 것입니다.

tp= NormalizeDouble ( 묻기 + TakeProfit* _Point , _Digits );

sl= NormalizeDouble ( 입찰가 - 손절매* _Point , _Digits );

또한 전역 변수 tp 및 sl에서 재설정할 필요가 없습니다. 발표하기에 충분합니다.

 
Ibragim Dzhanaev :

주문이 열리지 않는 이유를 알려주세요. 오류 130 을 제공합니다.

...

오류 130 - 중지를 닫습니다. 최소 정지 거리의 크기를 확인하십시오 - StopLevel

그리고 예, 위에서 이미 눈치 챘습니다. 잘못 계산하고 있습니다.

 

했어 - 아무것도 바뀌지 않았어

예, 방금 발표했습니다.

input double RSIperiod= 14 ;
input double Urov_70= 70 ;
input double Urov_30= 30 ;
input double Lot= 0.01 ;
input int     TakeProfit= 100 ;
input int     StopLoss= 100 ;
input int     MagicNumber= 523 ;
input int     slippage= 30 ;

double tp= 0 ,sl= 0 ,OrderBuy= 0 ,OrderSell= 0 ;
int tiket;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit ()
  {
   tp= NormalizeDouble ( Ask +TakeProfit* _Point , _Digits );
   sl= NormalizeDouble ( Bid -StopLoss* _Point , _Digits );
   return ( INIT_SUCCEEDED );
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit ( const int reason)
  {

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick ()
  {

   for ( int i= 0 ; i< OrdersTotal (); i++)
     {
       if ( OrderSelect (i, SELECT_BY_POS , MODE_TRADES ))
         if ( OrderSymbol ()== _Symbol && OrderMagicNumber ()==MagicNumber)
           {
             if ( OrderType ()== OP_BUY ){}
             if ( OrderType ()== OP_SELL ){}
           }
     }
   double rsi= iRSI ( _Symbol , 0 ,RSIperiod, PRICE_CLOSE , 0 );
   double rsi1= iRSI ( _Symbol , 0 ,RSIperiod, PRICE_CLOSE , 1 );
//+------------------------------------------------------------------+

   double StopLossLevel;
   double TakeProfitLevel;
   if (StopLoss> 0 ) StopLossLevel= Bid -StopLoss* Point ; else StopLossLevel= 0.0 ;
   if (TakeProfit> 0 ) TakeProfitLevel= Ask +TakeProfit* Point ; else TakeProfitLevel= 0.0 ;
///---
  
   if (OrderBuy< 1 && rsi>Urov_70 && rsi1<Urov_70)
     {
      tiket= OrderSend ( _Symbol , OP_BUY ,Lot, Ask ,slippage,sl,tp, NULL ,MagicNumber, 0 , clrBlue );
     }
   if (OrderSell< 1 && rsi<Urov_30 && rsi1>Urov_30)
     {
      tiket= OrderSend ( _Symbol , OP_SELL ,Lot, Bid ,slippage,sl,tp, NULL ,MagicNumber, 0 , clrRed );
     }
  }
//+------------------------------------------------------------------+
 
Ibragim Dzhanaev :

했어 - 아무것도 바뀌지 않았어

input double RSIperiod= 14 ;
input double Urov_70= 70 ;
input double Urov_30= 30 ;
input double Lot= 0.01 ;
input int     TakeProfit= 100 ;
input int     StopLoss= 100 ;
input int     MagicNumber= 523 ;
input int     slippage= 30 ;

double tp= 0 ,sl= 0 ,OrderBuy= 0 ,OrderSell= 0 ;
int tiket;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit ()
  {
   tp= NormalizeDouble ( Ask +TakeProfit* _Point , _Digits );
   sl= NormalizeDouble ( Bid -StopLoss* _Point , _Digits );
   return ( INIT_SUCCEEDED );
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit ( const int reason)
  {

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick ()
  {

   for ( int i= 0 ; i< OrdersTotal (); i++)
     {
       if ( OrderSelect (i, SELECT_BY_POS , MODE_TRADES ))
         if ( OrderSymbol ()== _Symbol && OrderMagicNumber ()==MagicNumber)
           {
             if ( OrderType ()== OP_BUY ){}
             if ( OrderType ()== OP_SELL ){}
           }
     }
   double rsi= iRSI ( _Symbol , 0 ,RSIperiod, PRICE_CLOSE , 0 );
   double rsi1= iRSI ( _Symbol , 0 ,RSIperiod, PRICE_CLOSE , 1 );
//+------------------------------------------------------------------+

   double StopLossLevel;
   double TakeProfitLevel;
   if (StopLoss> 0 ) StopLossLevel= Bid -StopLoss* Point ; else StopLossLevel= 0.0 ;
   if (TakeProfit> 0 ) TakeProfitLevel= Ask +TakeProfit* Point ; else TakeProfitLevel= 0.0 ;
///---
  
   if (OrderBuy< 1 && rsi>Urov_70 && rsi1<Urov_70)
     {
      tiket= OrderSend ( _Symbol , OP_BUY ,Lot, Ask ,slippage,sl,tp, NULL ,MagicNumber, 0 , clrBlue );
     }
   if (OrderSell< 1 && rsi<Urov_30 && rsi1>Urov_30)
     {
      tiket= OrderSend ( _Symbol , OP_SELL ,Lot, Bid ,slippage,sl,tp, NULL ,MagicNumber, 0 , clrRed );
     }
  }
//+------------------------------------------------------------------+


정지 계산을 온틱으로 전송

   tp= NormalizeDouble ( Ask +TakeProfit* _Point , _Digits );
   sl= NormalizeDouble ( Bid -StopLoss* _Point , _Digits );


..

 

tp= NormalizeDouble ( +TakeProfit* _Point , _Digits 묻기 ) ;
sl= NormalizeDouble ( 입찰가 -StopLoss* _Point , _Digits );

OP_BUY를 위한 옵션입니다.

OP_SELL용

tp= NormalizeDouble ( 입찰가 -TakeProfit* _Point , _Digits );

sl= NormalizeDouble ( + StopLoss * _Point , _Digits 요청 );
 

오류 148. 매 틱마다 열립니다.

input double RSIperiod= 14 ;
input double Urov_70= 70 ;
input double Urov_30= 30 ;
input double Lot= 0.01 ;
input int     TakeProfit= 100 ;
input int     StopLoss= 100 ;
input int     MagicNumber= 523 ;
input int     slippage= 30 ;

double tp,sl,OrderBuy= 0 ,OrderSell= 0 ;
int tiket;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit ()
  {
return ( INIT_SUCCEEDED );
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit ( const int reason)
  {

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick ()
  {

   for ( int i= 0 ; i< OrdersTotal (); i++)
     {
       if ( OrderSelect (i, SELECT_BY_POS , MODE_TRADES ))
         if ( OrderSymbol ()== _Symbol && OrderMagicNumber ()==MagicNumber)
           {
             if ( OrderType ()== OP_BUY ){}
             if ( OrderType ()== OP_SELL ){}
           }
     }
   double rsi= iRSI ( _Symbol , 0 ,RSIperiod, PRICE_CLOSE , 0 );
   double rsi1= iRSI ( _Symbol , 0 ,RSIperiod, PRICE_CLOSE , 1 );
//+------------------------------------------------------------------+

   double StopLossLevel;
   double TakeProfitLevel;
   if (StopLoss> 0 ) StopLossLevel= Bid -StopLoss* Point ; else StopLossLevel= 0.0 ;
   if (TakeProfit> 0 ) TakeProfitLevel= Ask +TakeProfit* Point ; else TakeProfitLevel= 0.0 ;

   tp= NormalizeDouble ( Ask +TakeProfit* _Point , _Digits );
   sl= NormalizeDouble ( Bid -StopLoss* _Point , _Digits );

   tp= NormalizeDouble ( Bid -TakeProfit* _Point , _Digits );
   sl= NormalizeDouble ( Ask +StopLoss* _Point , _Digits );

///---

   if (OrderBuy< 1 && rsi>Urov_70 && rsi1<Urov_70)
     {
      tiket= OrderSend ( _Symbol , OP_BUY ,Lot, Ask ,slippage,sl,tp, NULL ,MagicNumber, 0 , clrBlue );
     }
   if (OrderSell< 1 && rsi<Urov_30 && rsi1>Urov_30)
     {
      tiket= OrderSend ( _Symbol , OP_SELL ,Lot, Bid ,slippage,sl,tp, NULL ,MagicNumber, 0 , clrRed );
     }
  }
//+------------------------------------------------------------------+
 

두 개의 다른 값 sl tp

slSell , slBuy, tpSell, tpBuy 등의 이름을 다르게 지정합니다.

 
RichLux :

두 개의 다른 값 sl tp

slSell , slBuy, tpSell, tpBuy 등의 이름을 다르게 지정합니다.

도움이되지 않았습니다 (

double tp,sl,OrderBuy= 0 ,OrderSell= 0 ;
double slSell,slBuy,tpSell,tpBuy;
int tiket;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit ()
  {
return ( INIT_SUCCEEDED );
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit ( const int reason)
  {

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick ()
  {

   for ( int i= 0 ; i< OrdersTotal (); i++)
     {
       if ( OrderSelect (i, SELECT_BY_POS , MODE_TRADES ))
         if ( OrderSymbol ()== _Symbol && OrderMagicNumber ()==MagicNumber)
           {
             if ( OrderType ()== OP_BUY ){}
             if ( OrderType ()== OP_SELL ){}
           }
     }
   double rsi= iRSI ( _Symbol , 0 ,RSIperiod, PRICE_CLOSE , 0 );
   double rsi1= iRSI ( _Symbol , 0 ,RSIperiod, PRICE_CLOSE , 1 );
//+------------------------------------------------------------------+

   double StopLossLevel;
   double TakeProfitLevel;
   if (StopLoss> 0 ) StopLossLevel= Bid -StopLoss* Point ; else StopLossLevel= 0.0 ;
   if (TakeProfit> 0 ) TakeProfitLevel= Ask +TakeProfit* Point ; else TakeProfitLevel= 0.0 ;

   tpBuy= NormalizeDouble ( Ask +TakeProfit* _Point , _Digits );
   slBuy= NormalizeDouble ( Bid -StopLoss* _Point , _Digits );

   tpSell= NormalizeDouble ( Bid -TakeProfit* _Point , _Digits );
   slSell= NormalizeDouble ( Ask +StopLoss* _Point , _Digits );
///---
   if (OrderBuy< 1 && rsi>Urov_70 && rsi1<Urov_70)
     {
      tiket= OrderSend ( _Symbol , OP_BUY ,Lot, Ask ,slippage,sl,tp, NULL ,MagicNumber, 0 , clrBlue );      
     }      
   if (OrderSell< 1 && rsi<Urov_30 && rsi1>Urov_30)
     {
      tiket= OrderSend ( _Symbol , OP_SELL ,Lot, Bid ,slippage,sl,tp, NULL ,MagicNumber, 0 , clrRed );      
     }
  }
//+------------------------------------------------------------------+