Why does my EA keeps giving negative profit when back testing? - page 2

 
deVries:

Have rewritten your code and tried a test   see also the settings  

Not with the best backtestdata but if you do it right it can be profitable

Strategy Tester Report
RSI_strategy_cyxstudio
AlpariUK-Demo - Micro+Classic (Build 451)

SymbolEURUSD (Euro vs US Dollar)
PeriodDaily (D1) 2010.10.01 00:00 - 2013.01.29 00:00 (2010.10.01 - 2013.01.30)
ModelEvery tick (the most precise method based on all available least timeframes)
ParametersRSIPeriod=3; UpperBound=90; LowerBound=5; MASlowPeriod=200; MAFastPeriod=5; Lots=0.1; StopLoss=60; TakeProfit=120; TrailingStop=40; MagicNumber=54333; CommentEA="RSI strategy"; Slippage.Pips=3;
Bars in test1603Ticks modelled40187739Modelling qualityn/a
Mismatched charts errors2062601
Initial deposit3000.00
Total net profit967.18Gross profit2226.34Gross loss-1259.16
Profit factor1.77Expected payoff13.62
Absolute drawdown107.10Maximal drawdown327.47 (7.99%)Relative drawdown7.99% (327.47)
Total trades71Short positions (won %)66 (69.70%)Long positions (won %)5 (80.00%)
Profit trades (% of total)50 (70.42%)Loss trades (% of total)21 (29.58%)
Largestprofit trade120.07loss trade-60.00
Averageprofit trade44.53loss trade-59.96
Maximumconsecutive wins (profit in money)8 (424.26)consecutive losses (loss in money)3 (-179.93)
Maximalconsecutive profit (count of wins)424.26 (8)consecutive loss (count of losses)-179.93 (3)
Averageconsecutive wins4consecutive losses2

 

 


wat the...?? i had written at least 7-10 times in different ways and it either did not execute any position at all or make negative profit... how did u do that????
 
RaptorUK:
That would makes me think there is something not right.


    if (BUYS<1 && CurrentRSI < LowerBound && pAsk > MA200) 
        {    //Condition to execute buy entry  
         Ticket = OrderSend(Symbol(), OP_BUY,......


// LowerBound=5


  if (SELLS<1 && CurrentRSI > UpperBound && pBid > MA200) 
      {     //Condition to execute sell entry
       Ticket = OrderSend(Symbol(), OP_SELL, Lots,......


// UpperBound=90
Normally yes but in this case no, it is done with setting cyxstudio has chosen for RSI
 
deVries:

Have rewritten your code and tried a test   see also the settings  

Not with the best backtestdata but if you do it right it can be profitable

Strategy Tester Report
RSI_strategy_cyxstudio
AlpariUK-Demo - Micro+Classic (Build 451)

SymbolEURUSD (Euro vs US Dollar)
PeriodDaily (D1) 2010.10.01 00:00 - 2013.01.29 00:00 (2010.10.01 - 2013.01.30)
ModelEvery tick (the most precise method based on all available least timeframes)
ParametersRSIPeriod=3; UpperBound=90; LowerBound=5; MASlowPeriod=200; MAFastPeriod=5; Lots=0.1; StopLoss=60; TakeProfit=120; TrailingStop=40; MagicNumber=54333; CommentEA="RSI strategy"; Slippage.Pips=3;
Bars in test1603Ticks modelled40187739Modelling qualityn/a
Mismatched charts errors2062601
Initial deposit3000.00
Total net profit967.18Gross profit2226.34Gross loss-1259.16
Profit factor1.77Expected payoff13.62
Absolute drawdown107.10Maximal drawdown327.47 (7.99%)Relative drawdown7.99% (327.47)
Total trades71Short positions (won %)66 (69.70%)Long positions (won %)5 (80.00%)
Profit trades (% of total)50 (70.42%)Loss trades (% of total)21 (29.58%)
Largestprofit trade120.07loss trade-60.00
Averageprofit trade44.53loss trade-59.96
Maximumconsecutive wins (profit in money)8 (424.26)consecutive losses (loss in money)3 (-179.93)
Maximalconsecutive profit (count of wins)424.26 (8)consecutive loss (count of losses)-179.93 (3)
Averageconsecutive wins4consecutive losses2

 

 


would you please let me look at your code? i need to study it and learn from my mistakes.
 
deVries:
Normally yes but in this case no, it is done with setting cyxstudio has chosen for RSI
Ah OK,  if you can explain it then there is no cuase for concern  ;-)
 

With  UpperBound 90   and LowerBound 10

Strategy Tester Report
RSI_strategy_cyxstudio
AlpariUK-Demo - Micro+Classic (Build 451)

SymbolEURUSD (Euro vs US Dollar)
PeriodDaily (D1) 2010.10.01 00:00 - 2013.01.29 00:00 (2010.10.01 - 2013.01.30)
ModelEvery tick (the most precise method based on all available least timeframes)
ParametersRSIPeriod=3; UpperBound=90; LowerBound=10; MASlowPeriod=200; MAFastPeriod=5; Lots=0.1; StopLoss=60; TakeProfit=120; TrailingStop=40; MagicNumber=54333; CommentEA="RSI strategy"; Slippage.Pips=3;
Bars in test1603Ticks modelled40187739Modelling qualityn/a
Mismatched charts errors2062601
Initial deposit3000.00
Total net profit782.62Gross profit3062.38Gross loss-2279.76
Profit factor1.34Expected payoff7.38
Absolute drawdown106.90Maximal drawdown400.70 (9.90%)Relative drawdown9.90% (400.70)
Total trades106Short positions (won %)66 (69.70%)Long positions (won %)40 (55.00%)
Profit trades (% of total)68 (64.15%)Loss trades (% of total)38 (35.85%)
Largestprofit trade120.07loss trade-60.12
Averageprofit trade45.04loss trade-59.99
Maximumconsecutive wins (profit in money)8 (425.96)consecutive losses (loss in money)4 (-240.12)
Maximalconsecutive profit (count of wins)490.51 (6)consecutive loss (count of losses)-240.12 (4)
Averageconsecutive wins3consecutive losses2

 

 

 

How does that look 

 
cyxstudio:

would you please let me look at your code? i need to study it and learn from my mistakes.

This is the begin.....

Give your comment .....  about what is different from yours so far...

//+------------------------------------------------------------------+
//|                                       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
extern double UpperBound    =  90;     //set upper bound value for RSI
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;
//++++ 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        
//----      

//----
   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);
   
   
   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)
        {
         BUYS=0;
         SELLS=0;
        } 

 Then take a read at  https://www.mql5.com/en/forum/139654   and try to make a loop counting down checking trades

 
deVries:

This is the begin.....

Give your comment .....  about what is different from yours so far...

 Then take a read at  https://www.mql5.com/en/forum/139654   and try to make a loop counting down checking trades


Its not complete...

i am trying to fill in the rest and test it now...

 by the way why would you use   when a simple Ask can return the same value?

double pAsk = MarketInfo(Symbol(), MODE_ASK);  
 
cyxstudio:


Its not complete...

i am trying to fill in the rest and test it now...

 by the way why would you use   when a simple Ask can return the same value?

Ask can be out of date,  the call above will be current without the need to call RefreshRates()
 

Aslo the int    BUYS=1,SELLS=1; are meant to be indicators whether a position has been opened right? 

 

i add in my own scripts and when i test it with strategy tester for 20 days...nothing happened, no trades were executed 

 
cyxstudio:

Aslo the int    BUYS=1,SELLS=1; are meant to be indicators whether a position has been opened right? 

 

i add in my own scripts and when i test it with strategy tester for 20 days...nothing happened, no trades were executed 

when you start your Metatrader the EA has to find out if there is a trade open 

I do only the loop counting down for checking trades if there's a trade

If I set it at the beginning on one and OrdersTotal() >0  then I make it checking trades if(.......>      || .......>     ){do the loop....