Download MetaTrader 5
To add comments, please log in or register
Having questions? Ask them on the Forum - traders will help you!
teja
26
teja 2015.07.08 16:17 

I recently started to use the strategy tester, on MT4 version 4 build 840. I have tried to find an answer to my problem by searching the forum and the web, but no results.

I hope that someone here will be able to at least direct my research.

The data returned by the Print function in the strategy tester journal, do not match the indicator value for specific timestamp.


JOURNAL ENTRY MESSAGE EXAMPLE:

2015.04.06 01:00  FX_3_RSI EURUSD,H1: RSI_1 = 71.5278


The RSI value from variable RSI 1 displayed is 71.5278, but when I check the value on the chart for the specific timestamp I can find that it is 73.6427!
Does anybody know what's wrong?


Thanks in advance

honest_knave
969
honest_knave 2015.07.08 16:22  

Please post your code for your print statement.

Remember that the timestamp relates to when the print statement was made, not necessarily to the time of the RSI value you are printing.

teja
26
teja 2015.07.08 16:53  

Hi honest_knave

In fact I think you can see both timestamps in the log, the exucution date in the TIME column and the signal date in the MESSAGE column!

See below example executed today with RSI at 24.3009 on date 2017.07.02 at time 18:00, but on the chart it's at 55.2319.

2015.07.08 12:38:56.277   |  2015.07.02 18:00  Goran-0707 EURUSD,H1: BuyRSI_1 = 24.3009

Thank you for your help.

Keith Watford
Moderator
7950
Keith Watford 2015.07.08 17:02  
Probably because you are printing the value while the candle is open. The chart shows the value when the candle is closed.
teja
26
teja 2015.07.08 17:30  

Hi, here is the code, for Print statement . Thanks again for your help.

teja
26
teja 2015.07.08 17:40  

Sorry SRC button. :)

                          
//+------------------------------------------------------------------+                          
//| expert start function                                            |                          
//+------------------------------------------------------------------+                          
int start() {                           
   int Order = SIGNAL_NONE;                             
   int Total, Ticket;                           
   double StopLossLevel, TakeProfitLevel;                               
                                
                                
                                
   if (EachTickMode && Bars != BarCount) TickCheck = False;                             
   Total = OrdersTotal();                               
   Order = SIGNAL_NONE;                         
                                
   //+------------------------------------------------------------------+                               
   //| Variable Begin                                                   |                               
   //+------------------------------------------------------------------+                               
                                        

double RSI_1 = iRSI(NULL,0,9,0,0);
double BuyRSI_4 = 50;

Print("RSI_1 = ",RSI_1);                        
                                
   //+------------------------------------------------------------------+                               
   //| Variable End                                                     |                               
   //+------------------------------------------------------------------+                               
                                
   //Check position                             
   bool IsTrade = False;                                
                                
   for (int i = 0; i < Total; i ++) {                           
      if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES));  else;   
      if(OrderType() <= OP_SELL &&  OrderSymbol() == Symbol()) {                                
         IsTrade = True;                                
         if(OrderType() == OP_BUY) {                            
            //Close                             
                                
            //+------------------------------------------------------------------+                              
            //| Signal Begin(Exit Buy)                                           |                              
            //+------------------------------------------------------------------+                              
                                
                     
                                if (RSI_1 < BuyRSI_4) Order = SIGNAL_CLOSEBUY;
                                
            //+------------------------------------------------------------------+                              
            //| Signal End(Exit Buy)                                             |                              
            //+------------------------------------------------------------------+                              
                                
            if (Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {                          
               if (OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen));  else;                               
               if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");                             
               if (!EachTickMode) BarCount = Bars;                              
               IsTrade = False;                         
               continue;                                
            }                           
            //Trailing stop                             
            if(UseTrailingStop && TrailingStop > 0) {                                           
               if(Bid - OrderOpenPrice() > Point * TrailingStop) {                              
                  if(OrderStopLoss() < Bid - Point * TrailingStop) {                            
                     if (OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen));   else;
                     if (!EachTickMode) BarCount = Bars;                                
                     continue;                          
                  }                             
               }                                
            }                           
         } else {                               
            //Close                             
                                
            //+------------------------------------------------------------------+                              
            //| Signal Begin(Exit Sell)                                          |                              
            //+------------------------------------------------------------------+                              
                                
            if (RSI_1 > BuyRSI_4) Order = SIGNAL_CLOSESELL;                     
                                
            //+------------------------------------------------------------------+                              
            //| Signal End(Exit Sell)                                            |                              
            //+------------------------------------------------------------------+                              
                                
            if (Order == SIGNAL_CLOSESELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {                         
               if (OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange));   else;
               if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell");                            
                                
               if (!EachTickMode) BarCount = Bars;                              
               IsTrade = False;                         
               continue;                                
            }                           
            //Trailing stop                             
            if(UseTrailingStop && TrailingStop > 0) {                                           
               if((OrderOpenPrice() - Ask) > (Point * TrailingStop)) {                          
                  if((OrderStopLoss() > (Ask + Point * TrailingStop)) || (OrderStopLoss() == 0)) {                              
                     if (OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop, OrderTakeProfit(), 0, DarkOrange));   else;                           
                     if (!EachTickMode) BarCount = Bars;                                
                     continue;                          
                  }                             
               }                                
            }                           
         }
      }                         
   }                            
                                
   //+------------------------------------------------------------------+                               
   //| Signal Begin(Entry)                                              |                               
   //+------------------------------------------------------------------+                               

   if (RSI_1 > BuyRSI_4) Order = SIGNAL_BUY;                                            
   if (RSI_1 < BuyRSI_4) Order = SIGNAL_SELL;   

Print("RSI_1 = ",RSI_1);        
                        
   //+------------------------------------------------------------------+                               
   //| Signal End                                                       |                               
   //+------------------------------------------------------------------+                               
                                
   //Buy                                
   if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {                                
      if(!IsTrade) {                            
         //Check free margin                            
         if (AccountFreeMargin() < (1000 * Lots)) {                             
            Print("We have no money. Free Margin = ", AccountFreeMargin());                             

whroeder1
13624
whroeder1 2015.07.08 18:28  
GumRai: Probably because you are printing the value while the candle is open. The chart shows the value when the candle is closed.
No probably about it.
double RSI_1 = iRSI(NULL,0,9,0,0);
teja
26
teja 2015.07.08 19:32  

Thank you for your help,

I will try to figure out why this shift could affect the output when running a EA.

teja
26
teja 2015.07.09 16:51  
WHRoeder:
No probably about it.

Thank you WHRoeder, As you noticed I'm new to the programming world, it took a while before I find how to fix it, but your hint was in the good direction.

Thanks again for your help man. :)

/
To add comments, please log in or register