오류 4756

 

내 ea는 오류 4756을 확인

도와줄 수 있어 고마워

 //+------------------------------------------------------------------+
//|                                                    ErlyBird6.mq5 |
//|                        Copyright 2012, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link       "http://www.mql5.com"
#property version   "1.00"

string name, oldnameHTop,oldnameHBottom,oldnameVstart,oldnameVstop;

input int       MA_Period= 8 ;       // Moving Average Period
input int       StopLoss= 100 ;       // Stop Loss
input int       TakeProfit= 100 ;   // Take Profit
input int       Trigger= 5 ;
input double    Lot= 1 ;
input int       EA_Magic= 12345 ;   // EA Magic Number


int maHandle;   // handle for our Moving Average indicator
int     Sommerzeit     =   87 ;   // DayOfYear Beginn Sommerzeit
int     Winterzeit     =   297 ;   // DayOfYear Beginn Winterzeit
int   TimeSelect;
int STP, TKP;   // To be used for Stop Loss & Take Profit values


double maVal[]; // Dynamic array to hold the values of Moving Average for each bars
double hg[],lw[],p_close;
double High[],  Low[];
double Top,Bottom;

   MqlRates rates[];
   MqlDateTime Time;

 MqlTick latest_price;     // To be used for getting recent/latest price quotes
 MqlTradeRequest mrequest;   // To be used for sending our trade requests
 MqlTradeResult mresult;     // To be used to get our trade results
     // Initialization of mrequest structure
  

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+


int OnInit ()
  {


//--- Get the handle for Moving Average indicator
   maHandle= iMA ( _Symbol , _Period ,MA_Period, 0 , MODE_EMA , PRICE_CLOSE );
//--- What if handle returns Invalid Handle
   if ( maHandle< 0 )
     {
       Alert ( "Error Creating Handles for indicators - error: " , GetLastError (), "!!" );
       return (- 1 );
     }



//--- Let us handle currency pairs with 5 or 3 digit prices instead of 4
   STP = StopLoss;
   TKP = TakeProfit;
   if ( _Digits == 5 || _Digits == 3 )
     {
      STP = STP* 10 ;
      TKP = TKP* 10 ;
     }
   

   return ( 0 );
  }

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit ( const int reason)
  {
//--- destroy timer
   EventKillTimer ();
      
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick ()
  {
   // Do we have enough bars to work with
   if ( Bars ( _Symbol , _Period )< 60 ) // if total bars is less than 60 bars
     {
       Alert ( "We have less than 60 bars, EA will now exit!!" );
       return ;
     }  

// We will use the static Old_Time variable to serve the bar time.
// At each OnTick execution we will check the current bar time with the saved one.
// If the bar time isn't equal to the saved time, it indicates that we have a new tick.

   static datetime Old_Time;
   datetime New_Time[ 1 ];
   bool IsNewBar= false ;

// copying the last bar time to the element New_Time[0]
   int copied= CopyTime ( _Symbol , _Period , 0 , 1 ,New_Time);
   if (copied> 0 ) // ok, the data has been copied successfully
     {
       if (Old_Time!=New_Time[ 0 ]) // if old time isn't equal to new bar time
        {
         IsNewBar= true ;   // if it isn't a first call, the new bar has appeared
         if ( MQL5InfoInteger ( MQL5_DEBUGGING )) Print ( "We have new bar here " ,New_Time[ 0 ], " old time was " ,Old_Time);
         Old_Time=New_Time[ 0 ];             // saving bar time
        }
     }
   else
     {
       Alert ( "Error in copying historical times data, error =" , GetLastError ());
       ResetLastError ();
       return ;
     }

//--- EA should only check for new trade if we have a new bar
   if (IsNewBar== false )
     {
       return ;
     }
 
//--- Do we have enough bars to work with
   int Mybars= Bars ( _Symbol , _Period );
   if (Mybars< 60 ) // if total bars is less than 60 bars
     {
       Alert ( "We have less than 60 bars, EA will now exit!!" );
       return ;
     } 
  
     ArraySetAsSeries (rates, true );
     copied= CopyRates ( _Symbol , 0 , 0 , 60 ,rates);
   
     TimeToStruct (rates[ 0 ].time, Time);
     if (  Time.day_of_year>=Sommerzeit &&   Time.day_of_year<=Winterzeit) TimeSelect= 11 ; else TimeSelect= 10 ;  
     
     if (  Time.hour==TimeSelect &&  Time.min== 0 )   //draw vertical line at TimeSelect
          {
             ObjectDelete ( 0 ,oldnameVstart);  
            name = "VerticalStart" + TimeToString (rates[ 0 ].time, TIME_DATE|TIME_SECONDS);
             ObjectCreate ( 0 ,name, OBJ_VLINE , 0 ,rates[ 0 ].time, 0 ); 
             ObjectSetInteger ( 0 ,name, OBJPROP_COLOR , clrRed );
            oldnameVstart= name;       
          }
      
    
         if (  Time.hour==TimeSelect+ 5 &&  Time.min== 0 )   //draw vertical line at TimeSelect+5
           {
            
             ObjectDelete ( 0 ,oldnameVstop);      
            name = "VerticalEnd" + TimeToString (rates[ 0 ].time, TIME_DATE|TIME_SECONDS);
             ObjectCreate ( 0 , name, OBJ_VLINE , 0 ,rates[ 0 ].time, 0 );
             ObjectSetInteger ( 0 , name, OBJPROP_COLOR , clrDarkViolet );
            oldnameVstop= name;   
            
             ArraySetAsSeries (hg, true );
             ArraySetAsSeries (lw, true );
           
             CopyHigh ( _Symbol , _Period , TimeCurrent (), 5 ,hg);
             CopyLow ( _Symbol , _Period , TimeCurrent (), 5 ,lw);
       
             
             Top = NormalizeDouble (rates[ ArrayMaximum (hg, 0 , WHOLE_ARRAY )].high, _Digits );  
             Bottom = NormalizeDouble (rates[ ArrayMinimum (lw, 0 , WHOLE_ARRAY )].low, _Digits );
          
           
             // draw horizontal line at the top of  5 last  candles 
             ObjectDelete ( 0 , oldnameHTop);
            name = "HorizontalTop" + TimeToString (rates[ 0 ].time, TIME_DATE|TIME_SECONDS);
        
             ObjectCreate ( 0 ,name, OBJ_HLINE , 0 ,rates[ 0 ].time,Top);
             ObjectSetInteger ( 0 ,name , OBJPROP_COLOR , clrGreenYellow );
            oldnameHTop= name;
         
         
             // draw horizontal line at the bottom of  5 last  candles 
             ObjectDelete ( 0 ,oldnameHBottom);
            name = "HorizontalBottom" + TimeToString (rates[ 0 ].time, TIME_DATE|TIME_SECONDS);
        
             ObjectCreate ( 0 ,name, OBJ_HLINE , 0 ,rates[ 0 ].time,Bottom);
             ObjectSetInteger ( 0 ,name , OBJPROP_COLOR , clrCrimson );
            oldnameHBottom= name;
 
     ZeroMemory (mrequest);       
         
 // the MA-8 values arrays
   ArraySetAsSeries (maVal, true );
 
   if ( CopyBuffer (maHandle, 0 , 0 , 3 ,maVal)< 0 )
     {
       Alert ( "Error copying Moving Average indicator buffer - error:" , GetLastError ());
       ResetLastError ();
       return ;
     }
 
 
 
 //--- Get the last price quote using the MQL5 MqlTick Structure
   if (! SymbolInfoTick ( _Symbol ,latest_price))
     {
       Alert ( "Error getting the latest price quote - error:" , GetLastError (), "!!" );
       return ;
     }
 
 
/**********************************           BUY POSITION    ************************************************/             
 
   //--- Declare bool type variables to hold our Buy Conditions
   // bool Buy_Condition_1=(rates[0].close > Top);  
     //bool Buy_Condition_1=(latest_price.ask >Top);
    
    
         // any opened Buy position?
         if (isTrade_BUY())
           {
             Alert ( "We already have a Buy Position!!!" );
             return ;     // Don't open a new Buy Position
           }
         ZeroMemory (mrequest);
         ZeroMemory (mresult); 
         mrequest.action = TRADE_ACTION_PENDING ;   // immediate order execution
         mrequest.price = NormalizeDouble (Top+Trigger* _Point , _Digits );           // latest ask price
         mrequest.sl = NormalizeDouble (latest_price.ask - STP* _Point , _Digits ); // Stop Loss
         mrequest.tp = NormalizeDouble (latest_price.ask + TKP* _Point , _Digits ); // Take Profit
       //  mrequest.sl = 0;
       //  mrequest.tp =0;
         mrequest.symbol = _Symbol ;                                             // currency pair
         mrequest.volume = Lot;                                                 // number of lots to trade
         mrequest.magic = EA_Magic;                                             // Order Magic Number
         mrequest.type = ORDER_TYPE_BUY_STOP ;                                   // Buy Order
         mrequest.type_filling = ORDER_FILLING_RETURN ;                             // Order execution type
         mrequest.deviation= 100 ;                                                 // Deviation from current price
         //--- send order
         OrderSend (mrequest,mresult);
       // get the result code
         if (mresult.retcode== 10009 || mresult.retcode== 10008 ) //Request is completed or order placed
           {
             Alert ( "A Buy order has been successfully placed with Ticket#:" ,mresult.order, "!!" );
           }
         else
           {
             Alert ( "The Buy order request could not be completed -error:" , GetLastError ());
             ResetLastError ();           
             return ;
           }
   
      
 /**********************************          SELL POSITION    ************************************************/             
         if (isTrade_SELL())
           {
             Alert ( "We already have a Sell position!!!" );
             return ;     // Don't open a new Sell Position
           }
         ZeroMemory (mrequest);
         ZeroMemory (mresult); 
         mrequest.action= TRADE_ACTION_PENDING ;                               // immediate order execution
         mrequest.price = NormalizeDouble (Bottom-Trigger* _Point , _Digits );             // latest Bid price
         mrequest.sl = NormalizeDouble (latest_price.bid + STP* _Point , _Digits ); // Stop Loss
         mrequest.tp = NormalizeDouble (latest_price.bid - TKP* _Point , _Digits ); // Take Profit
         mrequest.symbol = _Symbol ;                                           // currency pair
         mrequest.volume = Lot;                                               // number of lots to trade
         mrequest.magic = EA_Magic;                                           // Order Magic Number
         mrequest.type= ORDER_TYPE_SELL_STOP ;                                     // Sell Order
         mrequest.type_filling = ORDER_FILLING_RETURN ;                           // Order execution type
         mrequest.deviation= 100 ;                                             // Deviation from current price
         //--- send order
         OrderSend (mrequest,mresult);
         // get the result code
         if (mresult.retcode== 10009 || mresult.retcode== 10008 ) //Request is completed or order placed
           {
             Alert ( "A Sell order has been successfully placed with Ticket#:" ,mresult.order, "!!" );
           }
         else
           {
             Alert ( "The Sell order request could not be completed -error:" , GetLastError ());
             ResetLastError ();
             return ;
           }
          
          
           }

  DeleteAllOrdersPending();
   
    }
   
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer ()
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Trade function                                                   |
//+------------------------------------------------------------------+
void OnTrade ()
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Tester function                                                  |
//+------------------------------------------------------------------+
double OnTester()
  {
//---
   double ret= 0.0 ;
//---

//---
   return (ret);
  }
//+------------------------------------------------------------------+
bool isTrade_BUY()
  {
   if ( PositionSelect ( _Symbol )== true && PositionGetInteger ( POSITION_TYPE )== POSITION_TYPE_BUY ) // we have an opened position
       {
         return ( true );
        }
  
    
   else 
     {
     return ( false );
     }
  
  }
/////////////////////////////////////////////////////////////////////////////////////


bool isTrade_SELL()
  {
   if ( PositionSelect ( _Symbol )== true && PositionGetInteger ( POSITION_TYPE )== POSITION_TYPE_SELL ) // we have an opened position
       {
         return ( true );
        }
  
    
   else 
     {
     return ( false );
     }
  
  }
  
////////////////////////////////////////////////////////////////////////////////////// 
 void DeleteAllOrdersPending()
   {
    
     if (isTrade_SELL()||isTrade_BUY())
     {  
    
     int i;
   // in this loop we're checking all pending orders
       for (i= 0 ;i< OrdersTotal ();i++)
         {
         // choosing each order and getting its ticket
         ulong ticket= OrderGetTicket (i);
           // processing orders with "our" symbols only
           if ( OrderGetString ( ORDER_SYMBOL )== Symbol ())
             {
             // processing Buy Stop orders
             if ( OrderGetInteger ( ORDER_TYPE )== ORDER_TYPE_BUY_STOP )
                {
                 mrequest.action= TRADE_ACTION_REMOVE ;
                 // putting the ticket number to the structure
                 mrequest.order=ticket;
                 // sending request to trade server
                 OrderSend (mrequest,mresult);
                }
        
         // processing Sell Stop orders
             if ( OrderGetInteger ( ORDER_TYPE )== ORDER_TYPE_SELL_STOP )
               {
               // we will delete this pending order
               mrequest.action= TRADE_ACTION_REMOVE ;
               // putting the ticket number to the structure
               mrequest.order=ticket;
               // sending request to trade server
               OrderSend (mrequest,mresult);
                    
               }
           } 
       } //boucle for
      } //if
    }    
 
dan5 :

내 ea는 오류 4756을 확인

도와줄 수 있어 고마워

2013.03.10 11:19:18 2012.01.04 15:00:00 매수 정지 실패 1.00 EURUSD at 1.30505 sl: 1.28375 tp: 1.30375 [잘못된 정지]
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Order Properties - Documentation on MQL5
 

CopyHigh(_Symbol,_Period,TimeCurrent(),5,hg);

Top = NormalizeDouble(rates[ ArrayMaximum(hg,0,WHOLE_ARRAY) ].high,_Digits); 

- 잘못된 디자인.
최대 double 값 중에서 선택 하고 정수 인덱스 대신 사용

 
dan5 :

내 ea는 오류 4756을 확인

도와줄 수 있어 고마워

오류 4756은 "거래 요청 전송 실패"입니다. 주문을 보낼 때 오류가 발생하면 MqlTradeResult의 반환 코드를 확인하십시오.

         //--- send order
         OrderSend (mrequest,mresult);
         // get the result code
         if (mresult.retcode== 10009 || mresult.retcode== 10008 ) //Request is completed or order placed
           {
             Alert ( "An order has been successfully placed with Ticket#:" ,mresult.order, "!!" );
           }
         else
           {
             Alert ( "The order request could not be completed -error:" , GetLastError (), " with trade return code " ,mresult.retcode );
             ResetLastError ();
             return ;
           }

Konstantin83 에 따르면 잘못된 중지 오류가 있습니다. 즉, SymbolInfoInteger SYMBOL_TRADE_STOPS_LEVEL 및 SYMBOL_TRADE_FREEZE_LEVEL 외부에서 보류 중인 주문을 해야 합니다.

 
phi.nuts :

오류 4756은 "거래 요청 전송 실패"입니다. 주문을 보낼 때 오류가 발생하면 MqlTradeResult의 반환 코드를 확인하십시오.

Konstantin83 에 따르면 잘못된 중지 오류가 있습니다. 즉, SymbolInfoInteger SYMBOL_TRADE_STOPS_LEVEL 및 SYMBOL_TRADE_FREEZE_LEVEL 외부에서 보류 중인 주문을 해야 합니다.

ECN 유형 브로커에 대해서도 유효하지 않은 경유지가 반환됩니까?
 
RaptorUK :
ECN 유형 브로커에 대해서도 유효하지 않은 경유지가 반환됩니까?
물론 대답은 아니오라는 것을 알고 있습니다. 근데 그걸 왜 물어봐?
 
phi.nuts :
물론 대답은 아니오라는 것을 알고 있습니다. 근데 그걸 왜 물어봐?
내가 대답이 아니오라는 것을 알고 있다고 생각하는 이유는 무엇입니까? SL 또는 TP가 OrderSend()와 함께 ECN 브로커로 전송될 때 mql4에서 잘못된 중지( 오류 130 )가 반환되므로 mql5에서도 동일한지 여부를 묻고 있었습니다. 어떤 오류가 반환됩니까?
Documentation on MQL5: Standard Constants, Enumerations and Structures / Codes of Errors and Warnings / Compilation Errors
Documentation on MQL5: Standard Constants, Enumerations and Structures / Codes of Errors and Warnings / Compilation Errors
  • www.mql5.com
Standard Constants, Enumerations and Structures / Codes of Errors and Warnings / Compilation Errors - Documentation on MQL5
 
RaptorUK :
내가 대답이 아니오라는 것을 알고 있다고 생각하는 이유는 무엇입니까? SL 또는 TP가 OrderSend()와 함께 ECN 브로커로 전송될 때 mql4에서 잘못된 중지( 오류 130 )가 반환되므로 mql5에서도 동일한지 여부를 묻고 있었습니다. 어떤 오류가 반환됩니까?
진짜 ? 그 흥미 롭군요. 나중에 확인해봐야겠네요 ;D.
 
phi.nuts :
진짜 ? 그 흥미 롭군요. 나중에 확인해봐야겠네요 ;D.
mql5로 길을 찾는 동안 잠시 조사를 해왔습니다. 전략 테스터의 동작이 브로커가 반환하는 것과 유사한 경우 ENUM_SYMBOL_TRADE_EXECUTIONExchange 실행 또는 시장 실행이고 오류가 반환되지 않는 기호에 대해 전송될 때 SL 및 TP가 무시되는 것으로 보입니다. 따라서 mql4와 비교하면 상황이 상당히 다릅니다.
 
RaptorUK :
mql5로 길을 찾는 동안 잠시 조사를 해왔습니다. 전략 테스터의 동작이 브로커가 반환하는 것과 유사한 경우 ENUM_SYMBOL_TRADE_EXECUTIONExchange 실행 또는 시장 실행이고 오류가 반환되지 않는 기호에 대해 전송될 때 SL 및 TP가 무시되는 것으로 보입니다. 따라서 mql4와 비교하면 상황이 상당히 다릅니다.

Invalid Stops와 관련하여 내가 찾은 다른 것. 심볼이 거래소 또는 시장 실행이 아닌 한 SL & TP로 거래하는 간단한 EA가 있습니다. 그런 다음 SL & TP가 설정되지 않은 거래를 보낸 다음 (TRADE_ACTION_SLTP) SL & TP를 설정하기 위해 두 번째 요청을 보냅니다.

전략 테스터에서 잘 작동하므로 오늘 데모 계정에서 시도했지만 계속 잘못된 중지(오류 10016)가 발생했습니다. 그래서 Stops Level과 Freeze Level을 확인했는데 둘 다 0이고 SL 및 TP의 다양한 수준을 시도했지만 아무 것도 작동하지 않았습니다. 기존 위치에 대해 문제 없이 동일한 SL 및 TP를 수동으로 설정할 수 있습니다. . . 그래서 포지션을 선택할 수 있는 경우에만 SL & TP를 배치하는 테스트를 추가했습니다. . . 더 이상 유효하지 않은 중지, 더 이상 TRADE_ACTION_SLTP 거래 요청도 없습니다 :-(

그래서 TP & SL 없이 보낸 초기 거래 요청 완료와 TP & SL을 보내는 후속 거래 요청 사이에 이 코드를 추가했습니다. . .

         SelectRetryCount = 1 ;
         if (SetTPandSL)
            {
             while (! PositionSelect ( _Symbol ) && SelectRetryCount < 10 )
               {
               Sleep (SelectRetryCount * 100 ); // sleep for SelectRetryCount * 100 mS
               SelectRetryCount++;
               }
            }

SetTPandSL은 초기 거래 요청이 성공하면 true로 설정되고, 그렇지 않으면 TP & SL을 설정하려고 시도하는 의미가 없습니다. 위치가 선택되고 실패하면 100mS 절전이 발생하고 선택이 다시 시도되고 실패하면 최대 9회(총 4.5초) 동안 200mS 절전이 발생합니다.

아직 mql5로 무엇을 하고 있는지 잘 모르겠습니다. 몇 가지 작업을 수행하는 방법에 대해 해킹을 하고 있으며 진행하면서 배우기를 희망하고 있습니다. . . 내가 여기에서 찾은 것이 정상적인 행동입니까? 초기 거래 요청이 10009-TRADE_RETCODE_DONE을 반환하면 TP & SL 설정 요청을 보내도 괜찮을 거라고 생각했습니다. 그렇지 않나요? 아는 사람 있나요 ?

 
RaptorUK :

Invalid Stops와 관련하여 내가 찾은 다른 것. 심볼이 거래소 또는 시장 실행이 아닌 한 SL & TP로 거래하는 간단한 EA가 있습니다. 그런 다음 SL & TP가 설정되지 않은 거래를 보낸 다음 (TRADE_ACTION_SLTP) SL & TP를 설정하기 위해 두 번째 요청을 보냅니다.

전략 테스터에서 잘 작동하므로 오늘 데모 계정에서 시도했지만 계속 잘못된 중지(오류 10016)가 발생했습니다. 그래서 Stops Level과 Freeze Level을 확인했는데 둘 다 0이고 SL 및 TP의 다양한 수준을 시도했지만 아무 것도 작동하지 않았습니다. 기존 위치에 대해 문제 없이 동일한 SL 및 TP를 수동으로 설정할 수 있습니다. . . 그래서 포지션을 선택할 수 있는 경우에만 SL & TP를 배치하는 테스트를 추가했습니다. . . 더 이상 유효하지 않은 중지, 더 이상 TRADE_ACTION_SLTP 거래 요청도 없습니다 :-(

그래서 TP & SL 없이 보낸 초기 거래 요청 완료와 TP & SL을 보내는 후속 거래 요청 사이에 이 코드를 추가했습니다. . .

SetTPandSL은 초기 거래 요청이 성공하면 true로 설정되고, 그렇지 않으면 TP & SL을 설정하려고 시도하는 의미가 없습니다. 위치가 선택되고 실패하면 100mS 절전이 발생하고 선택이 다시 시도되고 실패하면 최대 9회(총 4.5초) 동안 200mS 절전이 발생합니다.

아직 mql5로 무엇을 하고 있는지 잘 모르겠습니다. 몇 가지 작업을 수행하는 방법에 대해 해킹을 하고 있으며 진행하면서 배우기를 희망하고 있습니다. . . 내가 여기에서 찾은 것이 정상적인 행동입니까? 초기 거래 요청이 10009-TRADE_RETCODE_DONE을 반환하면 TP & SL 설정 요청을 보내도 괜찮을 거라고 생각했습니다. 그렇지 않나요? 아는 사람 있나요 ?

주문을 보내거나 수정하기 위해 어떤 기능 , 클래스/방법을 사용하고 있습니까?