백 테스트 시 EA가 계속 마이너스 이익을 내는 이유는 무엇입니까? - 페이지 4

 

이것은 내 최신 코드입니다. 내가 원하는 결과를 제공하지 않는 것을 제외하고는 아무 잘못도 생각할 수 없습니다.

//+------------------------------------------------------------------+
//|                                       RSI_strategy_cyxstudio.mq4 |
//|                                  Copyright 2013, Tjipke de Vries |
//|                                     https://forum.mql4.com/53695/ |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
#include <stderror.mqh>
#include <stdlib.mqh>


extern int RSIPeriod        =  2;      //number of periods for RSI
extern double UpperBound    =  95;     //set upper bound value for RSI
extern double LowerBound    =  5;      //set lower bound value for RSI

extern double Lots  = 0.1;
extern double StopLoss      = 60;       //Set the stop loss level
extern double TakeProfit    = 120;       //Set the take profit level
extern double TrailingStop = 40;
//extra settings for OrderSend
extern int        MagicNumber = 54333;
extern string     CommentEA = "RSI strategy";
extern int        Slippage.Pips    = 3;



//---
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----   
  Alert(OrdersTotal());

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   int Ticket1;
   int Ticket2;
   bool Ticket3;
   bool Ticket4;
   
   double SL,TP;
   int Total;
   double MagicNo;
   double Slippage;
    int cnt;
   
   double pAsk = MarketInfo(Symbol(), MODE_ASK);
   double pBid = MarketInfo(Symbol(), MODE_BID);
   double MA200 = iMA(NULL, 1440, 200, 0,MODE_SMA,PRICE_CLOSE, 0);  //200 day Moving Average   
   double MA5 = iMA(NULL, 1440, 5, 0,MODE_SMA,PRICE_CLOSE, 0);      //  5 day Moving Average
   double CurrentRSI = iRSI (NULL, 0, RSIPeriod,PRICE_CLOSE ,0);
   double PrevRSI =  iRSI (NULL, 0, RSIPeriod,PRICE_CLOSE ,1);
   double LastRSI = iRSI (NULL, 0, RSIPeriod,PRICE_CLOSE ,2);
   
   if(Bars<100)
     {
      Print("bars less than 100");
      return(0);  
     }
   
   if(AccountFreeMargin()<(1000*Lots))
        {
         Print("We have no money. Free Margin = ", AccountFreeMargin());
         return(0);  
        }



//Check for open orders if there are none then check for conditions to open one

      if (OrdersTotal() ==0 && LastRSI > PrevRSI && PrevRSI > CurrentRSI && CurrentRSI < LowerBound && pAsk > MA200) {    //Condition to execute buy entry
  
        Ticket1 = OrderSend(Symbol(), OP_BUY, Lots, pAsk, Slippage.Pips, pBid - ( StopLoss * Point ), pAsk + ( TakeProfit * Point ), "Buy.", MagicNumber,0,Yellow);       //execute buy order
   
    if(Ticket1>0)
           {
            if(OrderSelect(Ticket1,SELECT_BY_TICKET,MODE_TRADES)) 
               Print("BUY order opened : ",OrderOpenPrice());
            
           }
         if (Ticket1 < 0) {
         Print("Error opening BUY order : ",GetLastError()); 
         return(0); 
   }  
  

  if (OrdersTotal() ==0 && LastRSI < PrevRSI && PrevRSI < CurrentRSI && CurrentRSI > UpperBound && pBid < MA200) {     //Condition to execute sell entry
  
       Ticket2 = OrderSend(Symbol(), OP_SELL, Lots, pBid, Slippage.Pips, pAsk + ( StopLoss * Point ), pBid - ( TakeProfit * Point ), "Sell.",MagicNumber, 0, Yellow)  ;     //execute sell order
       if(Ticket2>0)
           {
            if(OrderSelect(Ticket2,SELECT_BY_TICKET,MODE_TRADES)) 
               Print("SELL order opened : ",OrderOpenPrice());
           
           }
         if (Ticket2<0) {
          Print("Error opening SELL order : ",GetLastError()); 
         return(0); 
        }
   } 
      
      }
 


   
    int ticket=OrderTicket();
    double lots=OrderLots();
   
   
   for (int i = OrdersTotal() - 1; i >= 0; i--)
   {
   
      if (OrderSelect(i, SELECT_BY_POS))
      {
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {


         if (OrderType() == OP_BUY && pBid > MA5)
         {
          Ticket3 = OrderClose(ticket, lots, pBid, Slippage.Pips);
          
          if (Ticket3 == true ) {
          Print("BUY position closed", OrderClosePrice());
          }
          if (Ticket3 == false) {
          Print("Error closing BUY position", ErrorDescription(GetLastError()));
          }
          }
          
          if (OrderType() == OP_SELL && pBid < MA5)
          {
          Ticket4 = OrderClose(ticket, lots, pAsk, Slippage.Pips);
           if (Ticket4 == true ) {
          Print("SELL position closed", OrderClosePrice());
          }
          if (Ticket4 == false) {
          Print("Error closing SELL position", ErrorDescription(GetLastError()));
          }
    }
      }
      
   }
   }
   
   
   
        
        
           return(0);
}
 

이 주제 2페이지를 보면 내가 준 것을 찾을 수 있습니다.

 //+------------------------------------------------------------------+
//|                                       RSI_strategy_cyxstudio.mq4 |
//|                                  Copyright 2013, Tjipke de Vries |
//|                                     https://forum.mql4.com/53695/ |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link       "http://www.metaquotes.net"


extern int RSIPeriod        =   3 ;       //number of periods for RSI //WHY DIDN't  YOU LEAVE THIS VALUE 3 
extern double UpperBound    =   90 ;     //set upper bound value for RSI //WHY DID YOU MAKE THIS TO 95
extern double LowerBound    =   5 ;       //set lower bound value for RSI
extern int MASlowPeriod     = 200 ;
extern int MAFastPeriod     = 5 ;
extern double Lots  = 0.1 ;
extern double StopLoss      = 60 ;       //Set the stop loss level
extern double TakeProfit    = 120 ;       //Set the take profit level
extern double TrailingStop = 40 ;
//extra settings for OrderSend
extern int         MagicNumber = 54333 ;
extern string      CommentEA = "RSI strategy" ;
extern int         Slippage.Pips    = 3 ;


int     BUYS= 1 ,SELLS= 1 ;                            //WHY DID YOU REMOVE THIS FROM YOUR CODE
//++++ These are adjusted for 5 digit brokers.
int      pips2points;       // slippage  3 pips    3=points    30=points
double   pips2dbl;         // Stoploss 15 pips    0.015      0.0150
int      Digits .pips;       // DoubleToStr(dbl/pips2dbl, Digits.pips)
//---
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----   
   if ( Digits % 2 == 1 )   // DE30=1/JPY=3/EURUSD=5 forum.mql4.com/43064#515262
     {pips2dbl = Point * 10 ; pips2points = 10 ;   Digits .pips = 1 ;}
     else {pips2dbl = Point ;    pips2points =   1 ;   Digits .pips = 0 ;}
     // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl  //WHY DID YOU REMOVE THIS        
//----      
//??   Alert(OrdersTotal());   //WHAT IS THIS DOING HERE  THIS IS NOT IN MY CODE
//----
   return ( 0 );
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return ( 0 );
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   int Ticket;
   double SL,TP;
   int Total;
   
   double pAsk = MarketInfo( Symbol (), MODE_ASK);
   double pBid = MarketInfo( Symbol (), MODE_BID);
   double MA200 = iMA ( NULL , 1440 , MASlowPeriod, 0 , MODE_SMA , PRICE_CLOSE , 0 );   //200 day Moving Average   
   double MA5 = iMA ( NULL , 1440 , MAFastPeriod, 0 , MODE_SMA , PRICE_CLOSE , 0 );       //  5 day Moving Average
   double CurrentRSI = iRSI ( NULL , 1440 , RSIPeriod, PRICE_CLOSE , 0 );
   // WHY DID YOU MAKE  PrevRSI and LastRSI  REMOVE IT IT IS NOT IN MY CODE 
   
   if ( Bars < 100 )
     {
       Print ( "bars less than 100" );
       return ( 0 );  
     }
   
   if (AccountFreeMargin()<( 1000 *Lots))
        {
         Print ( "We have no money. Free Margin = " , AccountFreeMargin());
         return ( 0 );  
        }


   if ( OrdersTotal ()< 1 )            //  WHY DID YOU REMOVE THIS
        {
         BUYS= 0 ;
         SELLS= 0 ;
        } 
 
28
cyxstudio 2013.01.31 18:36
deVries :

이것이 시작이다.....

지금까지의 것과 다른 점에 대해 ..... 의견을 주십시오.

그런 다음 https://www.mql5.com/en/forum/139654 에서 읽고 거래 확인을 카운트다운하는 루프를 만드십시오.


보시다시피 거래 확인을 카운트다운하는 루프를 만들도록 요청했습니다.

이것이 코드 내에서 다음 단계입니다.

코드의 해당 부분만 요청합니다.

거래를 구매하고 거래를 별도로 판매하도록 계산합니다.

 
deVries :

이 주제 2페이지를 보면 내가 준 것을 찾을 수 있습니다.



사용법을 몰라서 삭제했습니다. 당신은 나에게 부분적으로 그것이 어떻게 작동 하는지 볼 수없는 코드를 주었다.
 

--

 

 
deVries :

28
cyxstudio 2013.01.31 18:36
데브리스 :

시작이다.....

지금까지의 것과 다른 점에 대해 ..... 의견을 주십시오.

그런 다음 https://www.mql5.com/en/forum/139654 에서 읽고 거래 확인을 카운트다운하는 루프를 만드십시오.


보시다시피 거래 확인을 카운트 다운하는 루프를 만들도록 요청했습니다.

이것이 코드 내에서 다음 단계입니다.

코드의 해당 부분만 요청합니다.

거래를 구매하고 거래를 별도로 판매하도록 계산하십시오.

이와 같이?

int 티켓=OrderTicket();
더블 랏=OrderLots();
for (int i = OrdersTotal() - 1, i >= 0, i--)
{
if (OrderSelect(i, SELECT_BY_POS))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {


//실행할 코드 블록

}
}

}

 
cyxstudio :

사용법을 몰라서 삭제했습니다. 당신은 부분적으로 코드를 줬어 나는 그것이 어떻게 작동하는지 볼 수 없었습니다.
 if ( OrdersTotal ()< 1 )  
        {
         BUYS= 0 ;
         SELLS= 0 ;
        } 

EA가 다시 시작되는 순간

BUYS는 1로 설정됩니다.

판매가 1로 설정되었습니다.

OrdersTotal()은 귀하의 계정에서 열린 모든 거래의 합계를 제공합니다.

그것은 0일 수 있고 우리는 nottrade가 열려 있고 이 EA의 거래가 있는지 확인할 필요가 없습니다

OrdersTotal () > 0인 경우 BUYS는 1로, SELLS는 1로 유지

우리는 그것이 우리 EA에서 온 것인지 확인해야 하고 다른 유형(구매, 판매, 구매 제한...)을 계산해야 합니다.

그래서

 
cyxstudio :

이와 같이?

int 티켓=OrderTicket();
더블 랏=OrderLots();
for (int i = OrdersTotal() - 1, i >= 0, i--)
{
if (OrderSelect(i, SELECT_BY_POS))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {


//실행할 코드 블록

}
}

}

SRC 버튼 사용

이 루프만 시작합니다(어떤 조건에 대해)

루프에서 선택한 거래가 매수인지 매도인지 어떻게 알 수 있습니까?

그리고 어떻게 계산합니까 ??

 
deVries :

SRC 버튼 사용

이 루프만 시작합니다(어떤 조건에 대해)

루프에서 선택한 거래가 매수인지 매도인지 어떻게 알 수 있습니까?

그리고 어떻게 계산합니까 ??


opps.

 if (OrderType() == OP_BUY && pBid > MA5)
         {
          Ticket3 = OrderClose(ticket, lots, pBid, Slippage.Pips);
          
          if (Ticket3 == true ) {
          Print("BUY position closed", OrderClosePrice());
          }
          if (Ticket3 == false) {
          Print("Error closing BUY position", ErrorDescription(GetLastError()));
          }
          }
          
          if (OrderType() == OP_SELL && pBid < MA5)
          {
          Ticket4 = OrderClose(ticket, lots, pAsk, Slippage.Pips);
           if (Ticket4 == true ) {
          Print("SELL position closed", OrderClosePrice());
          }
          if (Ticket4 == false) {
          Print("Error closing SELL position", ErrorDescription(GetLastError()));
          }
    }
      }

폐쇄 무역 기능 을 위해.

사용

 if (OrderType() == OP_SELL && pBid < MA5)

매수와 매도를 구분합니다.

주문을 여는 조건에 문제가 있습니까?

 if ( OrdersTotal () == 0 )

그것을 제거하고 닫기 주문 기능에 사용한 루프로 교체합니까?

 
cyxstudio :


옵스.

폐쇄 무역 기능을 위해.

사용

매수와 매도를 구분합니다.

주문을 여는 조건에 문제가 있습니까?

그것을 제거하고 닫기 주문 기능에 사용한 루프로 교체합니까?

이 순간에 이미 거래가 열려 있는지 확인 해야 합니다.

거래를 열기 전에 거래가 열려 있는지 알아야 합니다

아직도 나는 당신이 거래를 세는 것을 볼 수 없습니다

.

메타 트레이더 스테이션에서 이동 평균 EA 코드를 살펴보고 어떻게 수행되는지 확인하십시오....