Magic Number 배열을 만드는 방법은 무엇입니까? - 페이지 4

 
존,
1) 첫 번째 OrderSend()는 반환 값이 더 큰지 테스트하여 성공했는지 확인합니다.
두 번째 주문을 시도하기 전에 0보다 작습니다.
2) 주문 쌍을 식별하고 처리하기 위해 주문 쌍이 다음과 같은 경우 코드를 기반으로 할 수 있습니다.
서로 다른 유형으로 구성되었습니다(그러나 그룹화하는 경우 알고리즘을 변경해야 합니다.
2개 이상이거나 그룹의 주문이 모두 동일한 유형인 경우):
다음 샘플 프로그램 "ReportsTrader.mq4"는 다음 문제 근처에 스트래들 주문을 배치합니다.
보고서 또는 뉴스 이벤트.
스트래들 주문은 시장 가격보다 높거나 낮은 두 개의 보류 주문 으로 구성됩니다. 언제 하나
보류 중인 주문이 시장 가격에 도달하면 시장가 주문으로 변경되고 다른 보류 중인 주문

주문을 삭제해야 합니다. 따라서 주문 쌍을 추적하려면 순서 번호가 필요합니다.

 //+------------------------------------------------------------------+
//|                                                ReportsTrader.mq4 |
//|                                          Copyright © 2010, sxTed |
//|                                            MailTo: sxTed@gmx.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, sxTed"
#property link       "MailTo: sxTed@gmx.com"

//+------------------------------------------------------------------+
//| input parameters:                                                |
//+-----------0---+----1----+----2----+----3]------------------------+
extern int             ExpertID = 2 ;
extern int             StopLoss = 20 ;
extern int           TakeProfit = 60 ;
extern int     DistanceToMarket = 15 ;
extern double              Lots = 0.05 ;
extern bool          AlertError = true;

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
void start() {
   static string Report[ 4 ][ 4 ] = { "2010.12.30 05:00" , "USDJPY" , "JPY Purchasing Manager Index"     , "0" ,
                                 "2010.12.30 09:00" , "EURUSD" , "EUR Italian Producer Price Index" , "0" ,
                                 "2010.12.30 13:30" , "USDJPY" , "USD Initial Jobless Claims"       , "0" ,
                                 "2010.12.31 00:30" , "AUDUSD" , "AUD Private Sector Credit"        , "0"
                                };
   int     Position[ 10 ][ 7 ], iReports= ArrayRange (Report, 0 ), i, k, iPairs, iPipsFactor;
   int     iOrders= OrdersTotal (), iPositions= ArrayRange (Position, 0 ), iSequenceNumber;
   double dTS, dSL, pp;
   string sSequenceNumber;

   //----------------------------------------------------------------- triage of orders   
   if (iOrders > iPositions) iPositions= ArrayResize (Position,iOrders)/iOrders;
   ArrayInitialize (Position, 0 );
   for (i= 0 ; i<iOrders; i++) {
       if (! OrderSelect (i,SELECT_BY_POS))   continue ;
       if (OrderMagicNumber() != ExpertID) continue ;
      iSequenceNumber = StrToInteger(OrderComment());
       for (k= 0 ; k<iPositions; k++) {
         if (Position[k][ 6 ] == iSequenceNumber) {
            Position[k][OrderType()] = OrderTicket();
             break ;
         }   
         if (Position[k][ 6 ] == 0 ) {
            Position[k][ 6 ]           = iSequenceNumber;
            Position[k][OrderType()] = OrderTicket();
            iPairs++;
             break ;
         }   
      }      
   }
   //----------------------------------------------------------------- maintain straddle orders   
   for (i= 0 ; i<iPairs; i++) {
       if (Position[i][OP_BUY] > 0 ) {
         if ( OrderSelect (Position[i][OP_BUY], SELECT_BY_TICKET)) {
             if ((MarketInfo(OrderSymbol(),MODE_DIGITS) == 5 ) || (MarketInfo(OrderSymbol(),MODE_DIGITS) == 3 )) iPipsFactor = 10 ;
             else iPipsFactor = 1 ;
            dTS=StopLoss*iPipsFactor*MarketInfo(OrderSymbol(),MODE_POINT);
            dSL=OrderStopLoss()+dTS* MathFloor ((MarketInfo(OrderSymbol(),MODE_BID)-dTS-OrderStopLoss())/dTS);
             if (MarketInfo(OrderSymbol(),MODE_BID)-dSL >= dTS && dSL > OrderStopLoss()) {
               if (!OrderModify(OrderTicket(),OrderOpenPrice(),dSL,OrderTakeProfit(), 0 )) return (Error( "OrderModify" ));
            }
         }
      }
       if (Position[i][OP_SELL] > 0 ) {
         if ( OrderSelect (Position[i][OP_SELL], SELECT_BY_TICKET)) {
             if ((MarketInfo(OrderSymbol(),MODE_DIGITS) == 5 ) || (MarketInfo(OrderSymbol(),MODE_DIGITS) == 3 )) iPipsFactor = 10 ;
             else iPipsFactor = 1 ;
            dTS=StopLoss*iPipsFactor*MarketInfo(OrderSymbol(),MODE_POINT);
            dSL=OrderStopLoss()-dTS* MathFloor ((OrderStopLoss()-dTS-MarketInfo(OrderSymbol(),MODE_ASK))/dTS);
             if (dSL-MarketInfo(OrderSymbol(),MODE_ASK) >= dTS && dSL < OrderStopLoss()) {
               if (!OrderModify(OrderTicket(),OrderOpenPrice(),dSL,OrderTakeProfit(), 0 )) return (Error( "OrderModify" ));
            }
         }
      }
       if (Position[i][OP_BUYSTOP] > 0 && Position[i][OP_SELLSTOP] == 0 ) {
         if (!OrderDelete(Position[i][OP_BUYSTOP])) return (Error( "OrderDelete ticket " +Position[i][OP_BUYSTOP]));
      }
       if (Position[i][OP_BUYSTOP] == 0 && Position[i][OP_SELLSTOP] > 0 ) {
         if (!OrderDelete(Position[i][OP_SELLSTOP])) return (Error( "OrderDelete ticket " +Position[i][OP_SELLSTOP]));
      }
   }
   //----------------------------------------------------------------- place new straddle orders for Report
   for (i= 0 ; i<iReports; i++) {
       if (Report[i][ 3 ] == "0" ) {
         if (( TimeGMT () >= StrToTime(Report[i][ 0 ])- PERIOD_M5 * 60 ) && ( TimeGMT () <= StrToTime(Report[i][ 0 ]))) {
            Report[i][ 3 ] = "done" ;
            sSequenceNumber=DoubleToStr(SequenceNumber(), 0 );
             if ((MarketInfo(Report[i][ 1 ],MODE_DIGITS) == 5 ) || (MarketInfo(Report[i][ 1 ],MODE_DIGITS) == 3 )) iPipsFactor = 10 ;
             else iPipsFactor = 1 ;
            pp=MarketInfo(Report[i][ 1 ],MODE_ASK)+DistanceToMarket*iPipsFactor*MarketInfo(Report[i][ 1 ],MODE_POINT);
             if ( OrderSend (Report[i][ 1 ],OP_BUYSTOP,Lots,pp, 3 ,pp-StopLoss*iPipsFactor*MarketInfo(Report[i][ 1 ],MODE_POINT),pp+TakeProfit*iPipsFactor*MarketInfo(Report[i][ 1 ],MODE_POINT),sSequenceNumber,ExpertID, 0 , Green ) == - 1 ) return (Error( "OrderSend OP_BUYSTOP" ));
            RefreshRates();
            pp=MarketInfo(Report[i][ 1 ],MODE_BID)-DistanceToMarket*iPipsFactor*MarketInfo(Report[i][ 1 ],MODE_POINT);
             if ( OrderSend (Report[i][ 1 ],OP_SELLSTOP,Lots,pp, 3 ,pp+StopLoss*iPipsFactor*MarketInfo(Report[i][ 1 ],MODE_POINT),pp-TakeProfit*iPipsFactor*MarketInfo(Report[i][ 1 ],MODE_POINT),sSequenceNumber,ExpertID, 0 , Red ) == - 1 ) return (Error( "OrderSend OP_SELLSTOP" ));
         }
      }
   }
}

int Error( string sErrorMessage) {
   int iErrorNumber= GetLastError ();
   Print (sErrorMessage, " error " ,iErrorNumber);
   if (AlertError) Alert (sErrorMessage, " error " ,iErrorNumber);
   return (- 1 );
}

//+------------------------------------------------------------------+
//| Function..: SequenceNumber                                       |
//| Purpose...: Generate a sequential number.                        |
//| Returns...: dSeqNum - next sequence number.                      |
//| Notes.....: MT4 keeps the value of the global variable at the    |
//|             client terminal for 4 weeks since the last access.   |
//|             Use SequenceNumber() to generate a unique identity   |
//|             for each order (and passed via parameter <magic>     |
//|             number, or converted to a string and passed via the  |
//|             parameter <comment> to the OrderSend() function) as  |
//|             the trade servers of some brokers do modify the      |
//|             ticket number of a pending order when it changes to  |
//|             a market order.                                      |
//|             The same sequence number could, for example, be used |
//|             to identify the two positions of a straddle order.   |
//|             ******************************************************
//|             * If the expert has to close partial lots, then MT4  *
//|             * retains in the new order the contents of the       *
//|             * OrderMagicNumber() but loses OrderComment().       *
//|             ******************************************************
//| Sample....: string sNumber=DoubleToStr(SequenceNumber(),0);      |
//|             if(OrderSend("EURUSD",OP_BUY,1,Ask,3,Ask-25*Point,   |
//|                          Ask+25*Point,sNumber,16384,0,Green) > 0)|
//|                OrderSend("EURUSD",OP_BUY,1,Ask,3,Ask-25*Point,   |
//|                          Ask+65*Point,sNumber,16384,0,Green);    |
//+------------------------------------------------------------------+
double SequenceNumber() {
   double dSeqNum= 1 , d;
   string sName= "SequenceNumber" ;

   while ( GlobalVariableCheck ( "Semaphore" )) d+= 0 ;
   GlobalVariableSet ( "Semaphore" , 1 );
   if ( GlobalVariableCheck (sName)) dSeqNum= GlobalVariableGet (sName)+ 1 ;
   GlobalVariableSet (sName,dSeqNum);
   GlobalVariableDel ( "Semaphore" );
   return (dSeqNum);
}

//+------------------------------------------------------------------+
//| Function..: TimeGMT                                              |
//| Thank you.: Slawa ref. http://www.metatrader4.com/forum/2435     |
//| Purpose...: Retrieve the current system date and time expressed  |
//|             in GMT (UTC) time.                                   |
//| Returns...: tGMT.                                                |
//+------------------------------------------------------------------+
#import "Kernel32.dll"
   void GetSystemTime( int & TimeArray[]);
#import

datetime TimeGMT () {
   int TimeArray[ 4 ];
  GetSystemTime(TimeArray);
   int YY=TimeArray[ 0 ]& 0x0000FFFF ;
   int MM=TimeArray[ 0 ]>> 16 ;
   int DD=TimeArray[ 1 ]>> 16 ;
   int hh=TimeArray[ 2 ]& 0x0000FFFF ;
   int mm=TimeArray[ 2 ]>> 16 ;
   int ss=TimeArray[ 3 ]& 0x0000FFFF ;
   return (StrToTime( StringConcatenate (YY, "." ,MM, "." ,DD, " " ,hh, ":" ,mm, ":" ,ss)));
}
//+------------------------------------------------------------------+
파일:
 
감사해요! 와우, 코드를 읽고 이해하는 데 시간이 걸릴 것입니다...
 

Chee Chua 이 문제를 해결하셨는지 모르겠지만 저는 같은 일을 할 수 있는 수준에 가까워졌습니다.

내 시스템은 가격이 가격 수준을 다시 방문하고 주문이 존재하지 않는 경우 주문이 이루어지도록 영구적인 것으로 간주되는 가격 수준(시작할 때 내 입력을 기반으로 함)을 생성합니다. 이러한 가격 수준은 for 루프를 사용하여 각 보류 주문 이 생성될 때 생성됩니다. 그런 다음 매직넘버는 가격 수준에서 파생됩니다.

여기에서 내 코드를 볼 수 있습니다.

https://www.mql5.com/en/forum/306224


내 유일한 문제는 때때로 내 번호가 내가 해결할 수없는 거래의 Pricelevel보다 1 자리 적게 나온다는 것입니다.

Anyone want to take a crack at this?
Anyone want to take a crack at this?
  • 2019.03.11
  • www.mql5.com
Hi All, Anyone want to take a crack at this? This code will ask for inputs, so in this case the following were entered 2019.03.11 11:56:18.393 2016...