코드에 대한 도움이 필요합니다 - 페이지 4

 
diamstar :
나는 ea를 붙인 후 스마일리가 아닌 x가 앞에 있는 오른쪽 상단 모서리에 dea의 d 이름을 보았습니다. 나는 gmt로 시간을 입력했다.


안녕하세요 다이아스타입니다.

우선 여기에서 얻은 코드가 학습 목적임을 이해해야 합니다.

즉, 자신의 책임하에 원하는 방식으로 코드를 테스트, 수정 또는 사용합니다.

문제로 돌아가서 웃는 얼굴이 보이지 않으면 Expert Advisers 버튼을 확인 하십시오.

빨간색이면 누르세요.

또한 MT4의 설정을 확인해야 할 수도 있습니다.

도구로 이동하여 옵션(하단의 마지막 항목)을 선택합니다.

다음과 같이 표시되지 않는 경우:

이렇게 보이게하십시오.

이제 작동해야 합니다. EA를 중지하려면 Expert Adviser 버튼을 누르십시오.

백 테스트를 아직 실행하지 않았습니까?

시간은 서버 시간이어야 합니다.

 
고맙습니다. 나는 지금 스마일리를 보고 있다. 이번주에 테스트 후 업데이트 하겠습니다. 다시 한번 감사합니다.
 
diamstar :
고맙습니다. 나는 지금 스마일리를 보고 있다. 이번주에 테스트 후 업데이트 하겠습니다. 다시 한번 감사합니다.


전략 테스터 , 비주얼 여부, 최적화 기능에서 백 테스트를 실행하는 방법을 알고 있습니까?

아니면 데모에서 테스트하게 되어 기쁩니까? 전략 테스터를 사용하면 최상의 설정을 더 빨리 찾을 수 있습니다.

행운을 빕니다

 
스마일리가 보이지만 아직 주문이 활성화되지 않았습니다. 전략 테스터 의 저널을 확인했는데 주문 보내기 오류 130이 표시됩니다.
 
diamstar :
스마일리가 보이지만 아직 주문이 활성화되지 않았습니다. 전략 테스터의 저널을 확인했는데 주문 보내기 오류 130이 표시됩니다.


사용 중인 설정과 차트 기간을 게시할 수 있습니까?

설정에 대한 설명이 필요하면 질문하세요. 문제 없습니다.

여기에 평소와 같이 학습 목적으로 다시 약간 개선된 버전이 있습니다.

 //+------------------------------------------------------------------+
//|                                               News_Trader_v1.mq4 |
//|                                            Copyright © 2013 _3DE |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2013 _3DE"
#property link        "http://www.metaquotes.net"
extern string   Note1       = "Set parameters in Pips not points !" ;
extern string   Note5       = "Set PeriodSignal in minutes!" ;
extern string   Note6       = "1=M1;5=M5;15=M15;30=M30;60=H1;240=H4;1440=D1!" ;
extern int      PeriodForSignal= 15 ;
extern int      TakeProfit  = 25 ; // Take profit pips
extern int      StopLoss    = 0 ; // Stop loss pips (manual trading)
extern string   Note4       = "Leave SetDistance to zero if trading news !" ;
extern int      SetDistance= 10 ; // Distance for BuyStop and SellStop from price at news time
extern string   Note2       = "Set day of the month for the news !" ;
extern string   Note3       = "Set to zero to trade every day at the same time !" ;
extern int      DayOfNews   = 0 ; // Day of the month of news
extern int      NewsHour    = 0 ; // Hour of news
extern int      NewsMin     = 1 ; // Minute of news
extern int      Expiration= 600 ; // Expiration of pending orderes
extern int      BEPips      = 0 ; // Move to break even after BEPips
extern int      TrailingStop= 0 ; // What distance to keep trailing
extern int      Slip        = 5 ; // Slippage
extern int      MagicNumber= 2210 ; // Must be unique for every chart
extern double   Lots= 0.1 ;
extern bool     WriteLog= false ; // Write a log file 
extern string   TradeLog    = "MI_Log" ;
input    string   EaComment   = "NewsTrader_EA" ;

double high_M1,low_M1,openPriceBuyStop,openPriceSellStop,slOpenBuyStop,slSellStop,tpOpenBuyStop,tpSellStop,spread,price;

string filename;
int pointMultiply= 10 ;
double minDist= 0 ;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   if (SetDistance== 0 )pointMultiply= 10 ;
   else {pointMultiply=SetDistance;}
   if ( Digits == 3 || Digits == 5 )
     {
      pointMultiply  *= 10 ;
      TakeProfit     *= 10 ;
      StopLoss       *= 10 ;
      BEPips         *= 10 ;
      TrailingStop   *= 10 ;
      SetDistance    *= 10 ;
     }
   minDist= MarketInfo ( NULL , MODE_STOPLEVEL )* Point ;
//----
   return ( 0 );
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----

//----
   return ( 0 );
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
   int i;
   int OrdersCondition,minofday,minofnews;

   filename= Symbol ()+TradeLog+ "-" + Month ()+ "-" + Day ()+ ".txt" ;

   if (BEPips> 0 ) DoBE(BEPips);

   if (TrailingStop> 0 ) DoTrail();

   OrdersCondition=CheckOrdersCondition();
   if ( Day ()==DayOfNews || DayOfNews== 0 )
     {
      minofday= Hour ()* 60 + Minute ();
      minofnews=NewsHour* 60 +NewsMin;

       if ((minofday==minofnews- 2 ) || (minofday==minofnews- 1 ))
        {
         high_M1= iHigh ( NULL ,PeriodForSignal, 0 );
         low_M1= iLow ( NULL ,PeriodForSignal, 0 );
         //--- Get the highest high and lowest low for the last 3 bars on 1 minute

         for (i= 1 ;i<= 3 ;i++) if ( iHigh ( NULL ,PeriodForSignal,i)>high_M1) high_M1= iHigh ( NULL ,PeriodForSignal,i);
         for (i= 1 ;i<= 3 ;i++) if ( iLow ( NULL ,PeriodForSignal,i)<low_M1) low_M1= iLow ( NULL ,PeriodForSignal,i);

         spread= Ask - Bid ;
         openPriceBuyStop= NormalizeDouble ((high_M1+spread+(pointMultiply* Point )), Digits );
         slOpenBuyStop= NormalizeDouble (high_M1, Digits );
         tpOpenBuyStop= NormalizeDouble ((openPriceBuyStop+(TakeProfit* Point )+spread), Digits );
         if ((openPriceBuyStop-slOpenBuyStop)<minDist)
           {
            slOpenBuyStop= NormalizeDouble (openPriceBuyStop-minDist-spread, Digits );
           }
         //---
         openPriceSellStop= NormalizeDouble (low_M1-(pointMultiply* Point ), Digits );
         slSellStop= NormalizeDouble (low_M1, Digits );
         tpSellStop= NormalizeDouble ((openPriceSellStop-(TakeProfit* Point )-spread), Digits );
         if ((slSellStop-openPriceSellStop)<minDist)
           {
            slSellStop= NormalizeDouble (openPriceSellStop+minDist+spread, Digits );
           }
         //---
         if (StopLoss> 0 &&SetDistance> 0 )
           {
            price=( Ask + Bid )/ 2 ;
            high_M1=price+(SetDistance* Point );
            low_M1=price-(SetDistance* Point );
            openPriceBuyStop= NormalizeDouble (high_M1+spread, Digits );
            slOpenBuyStop= NormalizeDouble (openPriceBuyStop-(StopLoss* Point ), Digits );
            tpOpenBuyStop= NormalizeDouble (openPriceBuyStop+(TakeProfit* Point ), Digits );

             if ((openPriceBuyStop-slOpenBuyStop)<minDist)
              {
               slOpenBuyStop= NormalizeDouble (openPriceBuyStop-minDist-(StopLoss* Point ), Digits );
               Alert ( "Stop too close ! Check your StopLoss settitngs !!!" );
              }
            openPriceSellStop= NormalizeDouble (low_M1-spread, Digits );
            slSellStop= NormalizeDouble (openPriceSellStop+(StopLoss* Point ), Digits );

             if ((slSellStop-openPriceSellStop)<minDist)
              {
               slSellStop= NormalizeDouble (openPriceSellStop+minDist+(StopLoss* Point ), Digits );
               Alert ( "Stop too close ! Check your StopLoss settitngs !!!" );
              }
            tpSellStop= NormalizeDouble (openPriceSellStop-(TakeProfit* Point ), Digits );
           }
         if (OrdersCondition== 0 )
           {
             if (WriteLog)Write( "Opening BuyStop & SellStop, OrdersCondition=" +OrdersCondition+ " MinOfDay=" +minofday);
            OpenBuyStop();
            OpenSellStop();
           }

         if (OrdersCondition== 10 )
           {
             if (WriteLog)Write( "Opening SellStop, OrdersCondition=" +OrdersCondition+ " MinOfDay=" +minofday);
            OpenSellStop();
           }

         if (OrdersCondition== 1 )
           {
             if (WriteLog)Write( "Opening BuyStop , OrdersCondition=" +OrdersCondition+ " MinOfDay=" +minofday);
            OpenBuyStop();
           }
        }
     }
   if ((minofday>=minofnews) && (minofday<=minofnews+Expiration- 1 ))
     {

       if (OrdersCondition== 1001 )
        {
         if (WriteLog)Write( "Deleting SellStop Because of BuyStop Hit, OrdersCondition=" +OrdersCondition+ " MinOfDay=" +minofday);
         DeleteSellStop();
        }

       if (OrdersCondition== 110 )
        {
         if (WriteLog)Write( "Deleting BuyStop Because of SellStop Hit, OrdersCondition=" +OrdersCondition+ " MinOfDay=" +minofday);
         DeleteBuyStop();
        }
     }

   if (minofday>=minofnews+Expiration)
     {
       if (OrdersCondition== 11 )
        {
         if (WriteLog)Write( "Deleting BuyStop and SellStop Because 5 min expired, OrdersCondition=" +OrdersCondition+ " MinOfDay=" +minofday);
         DeleteBuyStop();
         DeleteSellStop();
        }

       if ((OrdersCondition== 10 ) || (OrdersCondition== 110 ))
        {
         if (WriteLog)Write( "Deleting BuyStop Because 5 min expired, OrdersCondition=" +OrdersCondition+ " MinOfDay=" +minofday);
         DeleteBuyStop();
        }

       if ((OrdersCondition== 1 ) || (OrdersCondition== 1001 ))
        {
         if (WriteLog)Write( "Deleting SellStop Because 5 min expired, OrdersCondition=" +OrdersCondition+ " MinOfDay=" +minofday);
         DeleteSellStop();
        }
     }

//----
   return ( 0 );
  }
//+------------------------------------------------------------------+
//| int CheckOrdersCondition()                                       |
//+------------------------------------------------------------------+

int CheckOrdersCondition()
  {
   int result= 0 ;
   for ( int i= 0 ;i< OrdersTotal ();i++)
     {
       OrderSelect (i, SELECT_BY_POS , MODE_TRADES );
       if (( OrderType ()== OP_BUY ) && ( OrderSymbol ()== Symbol ()) && ( OrderMagicNumber ()==MagicNumber))
        {
         result+= 1000 ;
        }
       if (( OrderType ()== OP_SELL ) && ( OrderSymbol ()== Symbol ()) && ( OrderMagicNumber ()==MagicNumber))
        {
         result+= 100 ;
        }
       if (( OrderType ()== OP_BUYSTOP ) && ( OrderSymbol ()== Symbol ()) && ( OrderMagicNumber ()==MagicNumber))
        {
         result+= 10 ;
        }
       if (( OrderType ()== OP_SELLSTOP ) && ( OrderSymbol ()== Symbol ()) && ( OrderMagicNumber ()==MagicNumber))
        {
         result+= 1 ;
        }

     }
   return (result); // 0 means we have no trades
  }
// OrdersCondition Result Pattern
//    1    1    1    1
//    b    s    bs   ss
//  
//+------------------------------------------------------------------+
//|void OpenBuyStop()                                                |
//+------------------------------------------------------------------+

void OpenBuyStop()
  {
   int ticket,tries;
   tries= 0 ;
   if (! GlobalVariableCheck ( "InTrade" ))
     {
       while (tries< 3 )
        {
         GlobalVariableSet ( "InTrade" , TimeCurrent ());   // set lock indicator
         ticket= OrderSend ( Symbol (), OP_BUYSTOP ,Lots,openPriceBuyStop,Slip,slOpenBuyStop,tpOpenBuyStop,EaComment,MagicNumber, 0 ,Red);
         if (WriteLog)Write( "in function OpenBuyStop OrderSend Executed , ticket =" +ticket);
         GlobalVariableDel ( "InTrade" );   // clear lock indicator
         if (ticket<= 0 )
           {
            tries++;
           }
         else tries= 3 ;
        }
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OpenSellStop()
  {
   int ticket,tries;
   tries= 0 ;
   if (! GlobalVariableCheck ( "InTrade" ))
     {
       while (tries< 3 )
        {
         GlobalVariableSet ( "InTrade" , TimeCurrent ());   // set lock indicator
         ticket= OrderSend ( Symbol (), OP_SELLSTOP ,Lots,openPriceSellStop,Slip,slSellStop,tpSellStop,EaComment,MagicNumber, 0 ,Red);
         if (WriteLog)Write( "in function OpenSellStop OrderSend Executed , ticket =" +ticket);
         GlobalVariableDel ( "InTrade" );   // clear lock indicator
         if (ticket<= 0 )
           {
            tries++;
           }
         else tries= 3 ;
        }
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void DoBE( int byPips)
  {
   for ( int i= 0 ; i< OrdersTotal (); i++)
     {
       OrderSelect (i, SELECT_BY_POS , MODE_TRADES );
       if ( OrderSymbol ()== Symbol () && ( OrderMagicNumber ()==MagicNumber)) // only look if mygrid and symbol...
        {
         if ( OrderType ()== OP_BUY ) if ( Bid - OrderOpenPrice ()>byPips* Point ) if ( OrderStopLoss ()< OrderOpenPrice ())
           {
             if (WriteLog)Write( "Movine StopLoss of Buy Order to BE+1" );
             OrderModify ( OrderTicket (), OrderOpenPrice (), OrderOpenPrice ()+ Point , OrderTakeProfit (),Red);
           }
         if ( OrderType ()== OP_SELL ) if ( OrderOpenPrice ()- Ask >byPips* Point ) if ( OrderStopLoss ()> OrderOpenPrice ())
           {
             if (WriteLog)Write( "Movine StopLoss of Buy Order to BE+1" );
             OrderModify ( OrderTicket (), OrderOpenPrice (), OrderOpenPrice ()- Point , OrderTakeProfit (),Red);
           }
        }
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void DoTrail()
  {
   for ( int i= 0 ; i< OrdersTotal (); i++)
     {
       OrderSelect (i, SELECT_BY_POS , MODE_TRADES );
       if ( OrderSymbol ()== Symbol () && ( OrderMagicNumber ()==MagicNumber)) // only look if mygrid and symbol...
        {

         if ( OrderType ()== OP_BUY )
           {
             if ( Bid - OrderOpenPrice ()> Point *TrailingStop)
              {
               if ( OrderStopLoss ()< Bid - Point *TrailingStop)
                 {
                   OrderModify ( OrderTicket (), OrderOpenPrice (), Bid - Point *TrailingStop, OrderTakeProfit (), 0 ,Green);
                   return ;
                 }
              }
           }

         if ( OrderType ()== OP_SELL )
           {
             if (( OrderOpenPrice ()- Ask )>( Point *TrailingStop))
              {
               if (( OrderStopLoss ()>( Ask + Point *TrailingStop)) || ( OrderStopLoss ()== 0 ))
                 {
                   OrderModify ( OrderTicket (), OrderOpenPrice (), Ask + Point *TrailingStop, OrderTakeProfit (), 0 ,Red);
                   return ;
                 }
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void DeleteBuyStop()
  {
   for ( int i= 0 ; i< OrdersTotal (); i++)
     {
       OrderSelect (i, SELECT_BY_POS , MODE_TRADES );
       if ( OrderSymbol ()== Symbol () && ( OrderMagicNumber ()==MagicNumber) && ( OrderType ()== OP_BUYSTOP ))
        {
         OrderDelete ( OrderTicket ());
         if (WriteLog)Write( "in function DeleteBuyStopOrderDelete Executed" );
        }

     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void DeleteSellStop()
  {
   for ( int i= 0 ; i< OrdersTotal (); i++)
     {
       OrderSelect (i, SELECT_BY_POS , MODE_TRADES );
       if ( OrderSymbol ()== Symbol () && ( OrderMagicNumber ()==MagicNumber) && ( OrderType ()== OP_SELLSTOP ))
        {
         OrderDelete ( OrderTicket ());
         if (WriteLog)Write( "in function DeleteSellStopOrderDelete Executed" );
        }

     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void Write( string str)
  {
   int handle;

   handle= FileOpen (filename, FILE_READ | FILE_WRITE | FILE_CSV , "/t" );
   FileSeek (handle, 0 , SEEK_END );
   FileWrite(handle,str+ " Time " + TimeToStr ( CurTime (), TIME_DATE | TIME_SECONDS ));
   FileClose (handle);
  }
//+------------------------------------------------------------------+

이전에는 1분 시간 프레임의 신호만 수신했기 때문에 PeriodForSgnal 매개변수를 추가했습니다. 이제 뉴스를 거래하는 경우 원하는 대로 5, 15, 60분으로 설정할 수 있습니다.

StopLoss=0이면 손절매를 계산합니다. SetDistance=0이면 보류 중인 주문 에 대한 거리를 계산합니다.

 
효과가 있었다!!! 오늘 백 테스트를 실행할 수 있습니다. 입력 중 하나에 실수를 저질렀습니다. 나는 여전히 데모 계정 에서 몇 가지 테스트를 시도할 것입니다. 백만 번 감사합니다.
 
diamstar :
효과가 있었다!!! 오늘 백 테스트를 실행할 수 있습니다. 입력 중 하나에 실수를 저질렀습니다. 나는 여전히 데모 계정에서 몇 가지 테스트를 시도할 것입니다. 백만 번 감사합니다.


천만에요.

여기서 배우게 되어 기쁩니다.

그리고 다른 질문이 있으시면 언제든지 문의하십시오.

 
안녕하세요 ea는 백테스팅 에서는 잘 작동하지만 데모에서는 작동하지 않습니다. 내가 온라인에서 본 기사는 주문 보내기와 주문 수정이 다르게 보내야 할 것과 같은 것을 보여줍니다. 나는 이것을 정말로 이해하지 못한다. 감사해요
 
diamstar :
안녕하세요 ea는 백 테스트에서는 잘 작동하지만 데모에서는 작동하지 않습니다. 내가 온라인에서 본 기사는 주문 보내기와 주문 수정이 다르게 보내야 할 것과 같은 것을 보여줍니다. 나는 이것을 정말로 이해하지 못한다. 감사해요


안녕하세요 diamstar 입니다 .

배우고 있다는 소식을 들으니 기쁩니다. 이제 라이브 계정이 아닌 데모를 말하는 것이 확실합니까?

일부 중개인은 EA가 손절매로 주문하고 라이브 계정에서 이익 을 얻는 것을 허용하지 않는다는 것을 알고 있습니다.

해결 방법은 손절매가 0이고 이익이 0인 주문을 보내도록 EA를 수정한 다음 다른 기능을 사용하여 수정하는 것입니다.

손실을 중지하고 원하는 가치로 이익을 얻으십시오. 그러나 다시 말하지만 데모가 아닌 라이브 계정에 대한 것입니다.

데모에서 말한 내용이 발생하면 터미널 버튼을 누르고 전문가 탭과 저널 탭을 확인하고 거기에 오류가 있는지 확인해야 합니다.

오류 메시지가 표시되면 오류 메시지가 무엇인지 알려주십시오.

당신이 무엇을 하려고 하고 무엇이 잘못되었는지 그런 작은 세부사항으로 추측하는 것은 어렵습니다. 어떻게 사용하는지, 중지가 무엇인지, 이익을 취하는지 등을 알려주십시오.

나는 이 EA가 올바른 매개변수와 주문에 대한 적절한 시기에 좋은 결과를 얻을 가능성을 보여주기 때문에 이 EA를 개선하기 위해 노력하고 있습니다.

관심이 있는 한 계속 업데이트하겠습니다.

 
감사합니다. 이 책은 코드를 이해하는 데 큰 도움이 되었습니다. 입력 값을 변경했을 때 데모에서도 완벽하게 작동했습니다. 물론 저는 기꺼이 배우려는 것 이상입니다.
사유: