Ichimoko Tenkan-sen from iIchimoko(...) function wrong values (MQL4)

To add comments, please log in or register
Klaus Kaserer
11
Klaus Kaserer  

I was testing my EA with the build in Strategy Tester from MetaTreader 4. I recognized that my EA placed far too few orders because of missed trend signs. After checking the chart by my own, I realized that my EA processed the Tenken-sen wrong.

Therefore I printed the retrieved Tenken-sen values with Alert(...) and wrote down the values from the chart. Strangely I spotted non equal values. Check code for all alerted and chart values.


I have no idea why there are this two "wrong" values. Maybe it's because of my "new bar" identification?

In addition I think especially at strong changes of the Tenkan-sen I get wrong values and with shift period 1 I always get the correct values.


Code and values:

void OnTick()
{
   // Check if a position should be taken
   if(curBarOpenTime != Time[0]) // Check for new bar
   {
      // New bar started
      curBarOpenTime = Time[0];
      
      // Calculating Tenkan-sen
      double tenkanSen0 = iIchimoku(NULL, 0, 17, 30, 9, MODE_TENKANSEN, 0);
      double tenkanSen1 = iIchimoku(NULL, 0, 17, 30, 9, MODE_TENKANSEN, 1);
      Alert("NEW BAR!   Tenkan-sen(0): ", tenkanSen0,"   Tenkan-sen(1): ", tenkanSen1);
    }  
}/*      

 --- RESULTS ---

From chart (I guess correct values?):
24 08:00-> Tenkan-sen: 1.11824
24 12:00-> Tenkan-sen: 1.1178
24 16:00-> Tenkan-sen: 1.11757
24 20:00-> Tenkan-sen: 1.11757
25 00:00-> Tenkan-sen: 1.11757
25 04:00-> Tenkan-sen: 1.11757
25 08:00-> Tenkan-sen: 1.11733
25 12:00-> Tenkan-sen: 1.11602
25 16:00-> Tenkan-sen: 1.11551
25 20:00-> Tenkan-sen: 1.11526
26 00:00-> Tenkan-sen: 1.11482
26 04:00-> Tenkan-sen: 1.11441

From journal messages:
24 12:00-> Tenkan-sen(0): 1.1178  (correct)   Tenkan-sen(1): 1.11824 (correct)
24 16:00-> Tenkan-sen(0): 1.11757 (correct)   Tenkan-sen(1): 1.1178  (correct)
24 20:00-> Tenkan-sen(0): 1.11757 (correct)   Tenkan-sen(1): 1.11757 (correct)
25 00:01-> Tenkan-sen(0): 1.11757 (correct)   Tenkan-sen(1): 1.11757 (correct)
25 04:00-> Tenkan-sen(0): 1.11757 (correct)   Tenkan-sen(1): 1.11757 (correct)
25 08:00-> Tenkan-sen(0): 1.11757 (wrong)     Tenkan-sen(1): 1.11757 (correct)
25 12:00-> Tenkan-sen(0): 1.11706 (wrong)     Tenkan-sen(1): 1.11733 (correct)  
25 16:00-> Tenkan-sen(0): 1.11551 (correct)   Tenkan-sen(1): 1.11602 (correct)  
25 20:00-> Tenkan-sen(0): 1.11526 (correct)   Tenkan-sen(1): 1.11551 (correct)
26 00:01-> Tenkan-sen(0): 1.11482 (correct)   Tenkan-sen(1): 1.11527 (correct)
26 04:00-> Tenkan-sen(0): 1.11441 (correct)   Tenkan-sen(1): 1.11482 (correct)
Alain Verleyen
38685
Alain Verleyen  
klaus1n3:

I was testing my EA with the build in Strategy Tester from MetaTreader 4. I recognized that my EA placed far too few orders because of missed trend signs. After checking the chart by my own, I realized that my EA processed the Tenken-sen wrong.

Therefore I printed the retrieved Tenken-sen values with Alert(...) and wrote down the values from the chart. Strangely I spotted non equal values. Check code for all alerted and chart values.


I have no idea why there are this two "wrong" values. Maybe it's because of my "new bar" identification?

In addition I think especially at strong changes of the Tenkan-sen I get wrong values and with shift period 1 I always get the correct values.


Code and values:

Because Bar 0 (current open bar) value can change. In your journal Tenkan-sen(0) is the value at the opening of bar 0. On the chart, while looking at bar's value, what you see is the value when the bar is close.
Klaus Kaserer
11
Klaus Kaserer  

Alain Verleyen:
Because Bar 0 (current open bar) value can change. In your journal Tenkan-sen(0) is the value at the opening of bar 0. On the chart, while looking at bar's value, what you see is the value when the bar is close.

Ohhhh Ok, thank you Alain for taking the time!

So at a new bar event I should use the function with shift period 1 to get the correct "past" Tenkan-sen?

To add comments, please log in or register