[ARCHIVE] 포럼을 어지럽히 지 않도록 초보자 질문. 프로, 놓치지 마세요. 너 없이는 아무데도 - 3. - 페이지 204

 
skyjet :
이것은 중첩된 기능이 아니라 기본 MACD Sample Expert Advisor의 일부입니다. 계산된 제비를 추가하려고 합니다. 주요 및 유일한 start() 함수

그런 다음 전체 코드를 살펴봐야 합니다. 당신이 보여준 것은 기능입니다
 
여기 :) 위에서 언급한 로트 계산을 입력하는 방법을 모르겠습니다.
 //+------------------------------------------------------------------+
//|                                                  MACD Sample.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+

extern double TakeProfit = 50 ;
extern double Lots = 0.1 ;
extern double TrailingStop = 30 ;
extern double MACDOpenLevel= 3 ;
extern double MACDCloseLevel= 2 ;
extern double MATrendPeriod= 26 ;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   double MacdCurrent, MacdPrevious, SignalCurrent;
   double SignalPrevious, MaCurrent, MaPrevious;
   int cnt, ticket, total;
// initial data checks
// it is important to make sure that the expert works with a normal
// chart and the user did not make any mistakes setting external 
// variables (Lots, StopLoss, TakeProfit, 
// TrailingStop) in our case, we check TakeProfit
// on a chart of less than 100 bars
   if ( Bars < 100 )
     {
       Print ( "bars less than 100" );
       return ( 0 );  
     }
   if (TakeProfit< 10 )
     {
       Print ( "TakeProfit less than 10" );
       return ( 0 );   // check TakeProfit
     }
// to simplify the coding and speed up access
// data are put into internal variables
   MacdCurrent= iMACD ( NULL , 0 , 12 , 26 , 9 , PRICE_CLOSE ,MODE_MAIN, 0 );
   MacdPrevious= iMACD ( NULL , 0 , 12 , 26 , 9 , PRICE_CLOSE ,MODE_MAIN, 1 );
   SignalCurrent= iMACD ( NULL , 0 , 12 , 26 , 9 , PRICE_CLOSE ,MODE_SIGNAL, 0 );
   SignalPrevious= iMACD ( NULL , 0 , 12 , 26 , 9 , PRICE_CLOSE ,MODE_SIGNAL, 1 );
   MaCurrent= iMA ( NULL , 0 ,MATrendPeriod, 0 , MODE_EMA , PRICE_CLOSE , 0 );
   MaPrevious= iMA ( NULL , 0 ,MATrendPeriod, 0 , MODE_EMA , PRICE_CLOSE , 1 );

   total= OrdersTotal ();
   if (total< 1 ) 
     {
       // no opened orders identified
       if ( AccountFreeMargin ()<( 1000 *Lots))
        {
         Print ( "We have no money. Free Margin = " , AccountFreeMargin ());
         return ( 0 );  
        }
       // check for long position (BUY) possibility
       if (MacdCurrent< 0 && MacdCurrent>SignalCurrent && MacdPrevious<SignalPrevious &&
         MathAbs (MacdCurrent)>(MACDOpenLevel* Point ) && MaCurrent>MaPrevious)
        {
         ticket= OrderSend ( Symbol (),OP_BUY,Lots,Ask, 3 , 0 ,Ask+TakeProfit* Point , "macd sample" , 16384 , 0 , Green );
         if (ticket> 0 )
           {
             if ( OrderSelect (ticket,SELECT_BY_TICKET,MODE_TRADES)) Print ( "BUY order opened : " , OrderOpenPrice ());
           }
         else Print ( "Error opening BUY order : " , GetLastError ()); 
         return ( 0 ); 
        }
       // check for short position (SELL) possibility
       if (MacdCurrent> 0 && MacdCurrent<SignalCurrent && MacdPrevious>SignalPrevious && 
         MacdCurrent>(MACDOpenLevel* Point ) && MaCurrent<MaPrevious)
        {
         ticket= OrderSend ( Symbol (),OP_SELL,Lots,Bid, 3 , 0 ,Bid-TakeProfit* Point , "macd sample" , 16384 , 0 , Red );
         if (ticket> 0 )
           {
             if ( OrderSelect (ticket,SELECT_BY_TICKET,MODE_TRADES)) Print ( "SELL order opened : " , OrderOpenPrice ());
           }
         else Print ( "Error opening SELL order : " , GetLastError ()); 
         return ( 0 ); 
        }
       return ( 0 );
     }
   // it is important to enter the market correctly, 
   // but it is more important to exit it correctly...   
   for (cnt= 0 ;cnt<total;cnt++)
     {
       OrderSelect (cnt, SELECT_BY_POS, MODE_TRADES);
       if ( OrderType ()<=OP_SELL &&   // check for opened position 
         OrderSymbol ()== Symbol ())   // check for symbol
        {
         if ( OrderType ()==OP_BUY)   // long position is opened
           {
             // should it be closed?
             if (MacdCurrent> 0 && MacdCurrent<SignalCurrent && MacdPrevious>SignalPrevious &&
               MacdCurrent>(MACDCloseLevel* Point ))
                {
                 OrderClose ( OrderTicket (), OrderLots (),Bid, 3 , Violet ); // close position
                 return ( 0 ); // exit
                }
             // check for trailing stop
             if (TrailingStop> 0 )  
              {                 
               if (Bid- OrderOpenPrice ()> Point *TrailingStop)
                 {
                   if ( OrderStopLoss ()<Bid- Point *TrailingStop)
                    {
                     OrderModify ( OrderTicket (), OrderOpenPrice (),Bid- Point *TrailingStop, OrderTakeProfit (), 0 , Green );
                     return ( 0 );
                    }
                 }
              }
           }
         else // go to short position
           {
             // should it be closed?
             if (MacdCurrent< 0 && MacdCurrent>SignalCurrent &&
               MacdPrevious<SignalPrevious && MathAbs (MacdCurrent)>(MACDCloseLevel* Point ))
              {
               OrderClose ( OrderTicket (), OrderLots (),Ask, 3 , Violet ); // close position
               return ( 0 ); // exit
              }
             // check for trailing stop
             if (TrailingStop> 0 )  
              {                 
               if (( OrderOpenPrice ()-Ask)>( Point *TrailingStop))
                 {
                   if (( OrderStopLoss ()>(Ask+ Point *TrailingStop)) || ( OrderStopLoss ()== 0 ))
                    {
                     OrderModify ( OrderTicket (), OrderOpenPrice (),Ask+ Point *TrailingStop, OrderTakeProfit (), 0 , Red );
                     return ( 0 );
                    }
                 }
              }
           }
        }
     }
   return ( 0 );
  }
// the end.
 
skyjet : 여기 :) 위에서 언급한 로트 계산을 입력하는 방법을 모르겠습니다.
 //+------------------------------------------------------------------+
//|                                                  MACD Sample.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+

extern double TakeProfit = 50 ;
extern double Lots = 0.1 ;
extern double TrailingStop = 30 ;
extern double MACDOpenLevel= 3 ;
extern double MACDCloseLevel= 2 ;
extern double MATrendPeriod= 26 ;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   double MacdCurrent, MacdPrevious, SignalCurrent;
   double SignalPrevious, MaCurrent, MaPrevious;
   int cnt, ticket, total;
// initial data checks
// it is important to make sure that the expert works with a normal
// chart and the user did not make any mistakes setting external 
// variables (Lots, StopLoss, TakeProfit, 
// TrailingStop) in our case, we check TakeProfit
// on a chart of less than 100 bars
   if ( Bars < 100 )
     {
       Print ( "bars less than 100" );
       return ( 0 );  
     }
   if (TakeProfit< 10 )
     {
       Print ( "TakeProfit less than 10" );
       return ( 0 );   // check TakeProfit
     }
// to simplify the coding and speed up access
// data are put into internal variables
   MacdCurrent= iMACD ( NULL , 0 , 12 , 26 , 9 , PRICE_CLOSE ,MODE_MAIN, 0 );
   MacdPrevious= iMACD ( NULL , 0 , 12 , 26 , 9 , PRICE_CLOSE ,MODE_MAIN, 1 );
   SignalCurrent= iMACD ( NULL , 0 , 12 , 26 , 9 , PRICE_CLOSE ,MODE_SIGNAL, 0 );
   SignalPrevious= iMACD ( NULL , 0 , 12 , 26 , 9 , PRICE_CLOSE ,MODE_SIGNAL, 1 );
   MaCurrent= iMA ( NULL , 0 ,MATrendPeriod, 0 , MODE_EMA , PRICE_CLOSE , 0 );
   MaPrevious= iMA ( NULL , 0 ,MATrendPeriod, 0 , MODE_EMA , PRICE_CLOSE , 1 );

   total= OrdersTotal ();
   if (total< 1 ) 
     {
       // no opened orders identified
       if ( AccountFreeMargin ()<( 1000 *Lots))
        {
         Print ( "We have no money. Free Margin = " , AccountFreeMargin ());
         return ( 0 );  
        }
       // check for long position (BUY) possibility
       if (MacdCurrent< 0 && MacdCurrent>SignalCurrent && MacdPrevious<SignalPrevious &&
         MathAbs (MacdCurrent)>(MACDOpenLevel* Point ) && MaCurrent>MaPrevious)
        {
         ticket= OrderSend ( Symbol (),OP_BUY, Lots() ,Ask, 3 , 0 ,Ask+TakeProfit* Point , "macd sample" , 16384 , 0 , Green );
         if (ticket> 0 )
           {
             if ( OrderSelect (ticket,SELECT_BY_TICKET,MODE_TRADES)) Print ( "BUY order opened : " , OrderOpenPrice ());
           }
         else Print ( "Error opening BUY order : " , GetLastError ()); 
         return ( 0 ); 
        }
       // check for short position (SELL) possibility
       if (MacdCurrent> 0 && MacdCurrent<SignalCurrent && MacdPrevious>SignalPrevious && 
         MacdCurrent>(MACDOpenLevel* Point ) && MaCurrent<MaPrevious)
        {
         ticket= OrderSend ( Symbol (),OP_SELL, Lots() ,Bid, 3 , 0 ,Bid-TakeProfit* Point , "macd sample" , 16384 , 0 , Red );
         if (ticket> 0 )
           {
             if ( OrderSelect (ticket,SELECT_BY_TICKET,MODE_TRADES)) Print ( "SELL order opened : " , OrderOpenPrice ());
           }
         else Print ( "Error opening SELL order : " , GetLastError ()); 
         return ( 0 ); 
        }
       return ( 0 );
     }
   // it is important to enter the market correctly, 
   // but it is more important to exit it correctly...   
   for (cnt= 0 ;cnt<total;cnt++)
     {
       OrderSelect (cnt, SELECT_BY_POS, MODE_TRADES);
       if ( OrderType ()<=OP_SELL &&   // check for opened position 
         OrderSymbol ()== Symbol ())   // check for symbol
        {
         if ( OrderType ()==OP_BUY)   // long position is opened
           {
             // should it be closed?
             if (MacdCurrent> 0 && MacdCurrent<SignalCurrent && MacdPrevious>SignalPrevious &&
               MacdCurrent>(MACDCloseLevel* Point ))
                {
                 OrderClose ( OrderTicket (), OrderLots (),Bid, 3 , Violet ); // close position
                 return ( 0 ); // exit
                }
             // check for trailing stop
             if (TrailingStop> 0 )  
              {                 
               if (Bid- OrderOpenPrice ()> Point *TrailingStop)
                 {
                   if ( OrderStopLoss ()<Bid- Point *TrailingStop)
                    {
                     OrderModify ( OrderTicket (), OrderOpenPrice (),Bid- Point *TrailingStop, OrderTakeProfit (), 0 , Green );
                     return ( 0 );
                    }
                 }
              }
           }
         else // go to short position
           {
             // should it be closed?
             if (MacdCurrent< 0 && MacdCurrent>SignalCurrent &&
               MacdPrevious<SignalPrevious && MathAbs (MacdCurrent)>(MACDCloseLevel* Point ))
              {
               OrderClose ( OrderTicket (), OrderLots (),Ask, 3 , Violet ); // close position
               return ( 0 ); // exit
              }
             // check for trailing stop
             if (TrailingStop> 0 )  
              {                 
               if (( OrderOpenPrice ()-Ask)>( Point *TrailingStop))
                 {
                   if (( OrderStopLoss ()>(Ask+ Point *TrailingStop)) || ( OrderStopLoss ()== 0 ))
                    {
                     OrderModify ( OrderTicket (), OrderOpenPrice (),Ask+ Point *TrailingStop, OrderTakeProfit (), 0 , Red );
                     return ( 0 );
                    }
                 }
              }
           }
        }
     }
   return ( 0 );
  }
// the end.

double Lots()
  {
   double lot;
   lot=( AccountFreeMargin ()* AccountLeverage ()*Risk)/( MarketInfo ( Symbol (), MODE_LOTSIZE));
   lot= NormalizeDouble (lot, 1 );
   return (lot);
  }
이 정도
 
Vinin :
이 정도
도와주셔서 감사합니다!
 
skyjet :
도와주셔서 감사합니다!

로트 계산 기능만 보편화해야
 

안녕하세요.

저는 이 사업의 초보자입니다. 그래서 제가 도움을 요청하는 것입니다.


다음은 코드입니다.

 int start()
  {
  
    
   if ( IsTesting ()) return ;
 
      
     if ( AccountBalance () < 111 ){
       Alert ( "Erorr Balance" );
       return ; 
      
     if ( AccountNumber () != 11111 ){
       Alert ( "Error AccountNumber" );
       return ;}
      
   }
  

111보다 작으면 먼저 금액의 잔액을 확인한 다음 경고하고 반환하고, 더 많은 경우 계좌 번호 를 확인하고, 계좌가 정확하면 거래하고, 그렇지 않으면 경고하고 반환하도록 하고 싶습니다.

하지만 어째서인지 AccountBalance나 AccountNumber를 제거하면 개별적으로만 실행되는데...

멍청한 질문일 수도 있지만 내가 놓치고 있는 것은 무엇인가요?

고맙습니다

 
volodin_andrei :

안녕하세요.

저는 이 사업의 초보자입니다. 그래서 도움을 요청하는 것입니다.


다음은 코드입니다.

111보다 작으면 먼저 잔액을 확인한 다음 알림 및 반환, 더 많은 경우 계좌 번호를 확인, 계정이 정확하면 거래하고 그렇지 않으면 알림 및 반환...

하지만 어째서인지 AccountBalance나 AccountNumber를 제거하면 개별적으로만 실행되는데...

멍청한 질문일 수도 있지만 내가 놓치고 있는 것은 무엇인가요?

고맙습니다


대괄호(중괄호)를 넣지 않았습니다.

 int start()
  {
  
    
   if ( IsTesting ()) return ;
 
      
   if ( AccountBalance () < 111 )
   {
       Alert ( "Erorr Balance" );
       return ( 0 ); 
   }  
   if ( AccountNumber () != 11111 )
   {
       Alert ( "Error AccountNumber" );
       return ( 0 );
   }
   return ( 0 );
}

괄호는 충분했지만 잘못된 위치에

 

나는 당신의 도움으로 그것을 수정했지만 컴파일 할 때 맹세합니다. 분명히 어딘가에 여분의 브래킷이 있거나 .... :(

 
대괄호 일치 기능이 있는 텍스트 편집기를 찾으십시오.
 
Vinin :

그리고 다른 상품이나 다른 Expert Advisors에 대해서도 포지션이 열리면 어떻게 될까요? 당신이 쓰는 것을 생각하십시오
불행히도 조건에 대한 설명이 완전하다고 주장하지 않고 "40차"의 개념을 완전히 공개하지 않으면 표준 기능을 사용하는 것보다 EA에서 열린 주문의 수를 변수로 유지하는 것이 더 쉽습니다. . 이 상황에서 연기는 별개의 문제입니다.