Download MetaTrader 5

Troublesome Ichimoku

To add comments, please log in or register
kishor-mistry
19
kishor-mistry  

Hi All,

I'm trying to learn MT5 programing & am having a few teething issues. This is the latest one:

Here is a short debug print out:

KN 0 11:15:22 k_orders_demo_04 (GBPUSD,H1) 2013.03.14 00:06:40   ich1:1.492075
FJ 0 11:15:22 k_orders_demo_04 (GBPUSD,H1) 2013.03.14 00:06:40   ich2:1.4937
OP 0 11:15:22 k_orders_demo_04 (GBPUSD,H1) 2013.03.14 00:06:40   ich3:1.4883175
PM 0 11:15:22 k_orders_demo_04 (GBPUSD,H1) 2013.03.14 00:06:40   ich4:1.48894
EI 0 11:15:22 k_orders_demo_04 (GBPUSD,H1) 2013.03.14 00:06:40   ich5:1.797693134862316e+308
KS 0 11:15:22 k_orders_demo_04 (GBPUSD,H1) 2013.03.14 00:06:59   ich1:1.492075
FO 0 11:15:22 k_orders_demo_04 (GBPUSD,H1) 2013.03.14 00:06:59   ich2:1.4937
OD 0 11:15:22 k_orders_demo_04 (GBPUSD,H1) 2013.03.14 00:06:59   ich3:1.4883175
PP 0 11:15:22 k_orders_demo_04 (GBPUSD,H1) 2013.03.14 00:06:59   ich4:1.48894
EE 0 11:15:22 k_orders_demo_04 (GBPUSD,H1) 2013.03.14 00:06:59   ich5:1.797693134862316e+308
PG 0 11:15:22 k_orders_demo_04 (GBPUSD,H1) 2013.03.14 00:07:00   ich1:1.492075
IS 0 11:15:22 k_orders_demo_04 (GBPUSD,H1) 2013.03.14 00:07:00   ich2:1.4937
LK 0 11:15:22 k_orders_demo_04 (GBPUSD,H1) 2013.03.14 00:07:00   ich3:1.4883175
KD 0 11:15:22 k_orders_demo_04 (GBPUSD,H1) 2013.03.14 00:07:00   ich4:1.48894
JR 0 11:15:22 k_orders_demo_04 (GBPUSD,H1) 2013.03.14 00:07:00   ich5:1.797693134862316e+308
JH 0 11:15:22 k_orders_demo_04 (GBPUSD,H1) 2013.03.14 00:07:20   ich1:1.492075
OP 0 11:15:22 k_orders_demo_04 (GBPUSD,H1) 2013.03.14 00:07:20   ich2:1.4937
FO 0 11:15:22 k_orders_demo_04 (GBPUSD,H1) 2013.03.14 00:07:20   ich3:1.4883175
EG 0 11:15:22 k_orders_demo_04 (GBPUSD,H1) 2013.03.14 00:07:20   ich4:1.48894
PN 0 11:15:22 k_orders_demo_04 (GBPUSD,H1) 2013.03.14 00:07:20   ich5:1.797693134862316e+308

The value if ich5 - Chinkou - is reported as a very large no. & is not consistent with what I observe on the

plotted screen. Why?   Also, ich1,2,3,4 - Tenkan, Kijun, Senkou Span A & B, although bear some correlation

to the observed screen plot, remain the same from tick to tick in the print out? Why should this be?

The following simple routine is what I'm working with:

 

//+------------------------------------------------------------------+
int TradeSignal_20()
  {
   int sig=0;

   if(h_ich==INVALID_HANDLE)
     {
      h_ich=iIchimoku(Symbol(),Period(),9,26,52);
      return(0);
     }
   else
     {

      if(CopyBuffer(h_ich,0,0,3,ich1_buffer)<3)
      {Print("err<3");}
      else
      {Print("ich1:",ich1_buffer[0]);}

      if(CopyBuffer(h_ich,1,0,3,ich2_buffer)<3)
      {Print("err<3");}
      else
      {Print("ich2:",ich2_buffer[0]);}

      if(CopyBuffer(h_ich,2,0,3,ich3_buffer)<3)
      {Print("err<3");}
      else
      {Print("ich3:",ich3_buffer[0]);}

      if(CopyBuffer(h_ich,3,0,3,ich4_buffer)<3)
      {Print("err<3");}
      else
      {Print("ich4:",ich4_buffer[0]);}

      if(CopyBuffer(h_ich,4,0,3,ich5_buffer)<3)
      {Print("err<3");}
      else
      {Print("ich5:",ich5_buffer[0]);}

      if(!ArraySetAsSeries(ich1_buffer,true))
         return(0);
      if(!ArraySetAsSeries(ich2_buffer,true))
         return(0);
      if(!ArraySetAsSeries(ich3_buffer,true))
         return(0);
      if(!ArraySetAsSeries(ich4_buffer,true))
         return(0);
      if(!ArraySetAsSeries(ich5_buffer,true))
         return(0);              
     }
//--- perform checking of the condition and set the value for sig
   if(ich1_buffer[1]>ich2_buffer[1])
      sig=1;
   else if(ich1_buffer[1]<ich2_buffer[1])
      sig=-1;
   else sig=0;

//--- return the trade signal
   return(sig);
  }
//+------------------------------------------------------------------+

 

Thanks for looking & would certainly appreciate any constructive suggestion or advise on this

 trivial but troublesome issue.

Best Regards

Kishor 

Simon Gniadkowski
Moderator
18003
Simon Gniadkowski  
kishor-mistry:

Hi All,

I'm trying to learn MT5 programing & am having a few teething issues. This is the latest one:

The following simple routine is what I'm working with:

<CODE REMOVED>

Thanks for looking & would certainly appreciate any constructive suggestion or advise on this

Please   edit   your post above . . . please use the SRC button to post code: How to use the SRC button.
kishor-mistry
19
kishor-mistry  

RaptorUK:
Please   edit   your post above . . . please use the SRC button to post code: How to use the SRC button.

 

Thanks for your suggestion RaptorUK. 

Alain Verleyen
Moderator
31183
Alain Verleyen  

Chinkou is shifted to the past with kijun period. So if you get value from index 0 (current bar), the value of Chinkou is an empty value. By default EMPTY_VALUE is DBL_MAX, which is the value you get for ich5.

You are using this kind of code :

if(CopyBuffer(h_ich,0,0,3,ich1_buffer)<3)
      {Print("err<3");}
      else
      {Print("ich1:",ich1_buffer[0]);}

and later you set 

ArraySetAsSeries(ich1_buffer,true)

So when you print your value ich1_buffer is probably index by default. In MT5 it's indexed from oldest data (index=0) to newest (index=count-1).

You are printing ichi1_buffer[0], which is value of buffer 0 for second closed candle in the past. Of course this value don't change.

If you want value for the current candle, either use ArraySetAsSeries(...true) before printing values. Or print like this :

{Print("ich1:",ich1_buffer[2]);}
Documentation on MQL5: Array Functions / ArraySetAsSeries
Documentation on MQL5: Array Functions / ArraySetAsSeries
  • www.mql5.com
Array Functions / ArraySetAsSeries - Documentation on MQL5
Simon Gniadkowski
Moderator
18003
Simon Gniadkowski  
kishor-mistry:
Thanks for your suggestion RaptorUK. 
Thank you. 
kishor-mistry
19
kishor-mistry  
angevoyageur:

Chinkou is shifted to the past with kijun period. So if you get value from index 0 (current bar), the value of Chinkou is an empty value. By default EMPTY_VALUE is DBL_MAX, which is the value you get for ich5.

You are using this kind of code :

and later you set 

So when you print your value ich1_buffer is probably index by default. In MT5 it's indexed from oldest data (index=0) to newest (index=count-1).

You are printing ichi1_buffer[0], which is value of buffer 0 for second closed candle in the past. Of course this value don't change.

If you want value for the current candle, either use ArraySetAsSeries(...true) before printing values. Or print like this :

Hello Angevoyageur,

Many thanks for your explanation & suggestion. I have just tried the mod & it works very well. However, please note that ich5 buffer is still

printing out the same large no. as shown below:

 

HP      0       12:38:36        k_orders_demo_04 (GBPUSD,H1)    2013.03.14 00:11:00   ich5:1.797693134862316e+308
DI      0       12:38:36        k_orders_demo_04 (GBPUSD,H1)    2013.03.14 00:11:20   ich1:1.49418
CG      0       12:38:36        k_orders_demo_04 (GBPUSD,H1)    2013.03.14 00:11:20   ich2:1.4937
HM      0       12:38:36        k_orders_demo_04 (GBPUSD,H1)    2013.03.14 00:11:20   ich3:1.48792
QI      0       12:38:36        k_orders_demo_04 (GBPUSD,H1)    2013.03.14 00:11:20   ich4:1.489475
FM      0       12:38:36        k_orders_demo_04 (GBPUSD,H1)    2013.03.14 00:11:20   ich5:1.797693134862316e+308
NM      0       12:38:36        k_orders_demo_04 (GBPUSD,H1)    2013.03.14 00:11:40   ich1:1.49418
MK      0       12:38:36        k_orders_demo_04 (GBPUSD,H1)    2013.03.14 00:11:40   ich2:1.4937
JR      0       12:38:36        k_orders_demo_04 (GBPUSD,H1)    2013.03.14 00:11:40   ich3:1.48792
GJ      0       12:38:36        k_orders_demo_04 (GBPUSD,H1)    2013.03.14 00:11:40   ich4:1.489475
LJ      0       12:38:36        k_orders_demo_04 (GBPUSD,H1)    2013.03.14 00:11:40   ich5:1.797693134862316e+308
JR      0       12:38:36        k_orders_demo_04 (GBPUSD,H1)    2013.03.14 00:11:59   ich1:1.49418
IH      0       12:38:36        k_orders_demo_04 (GBPUSD,H1)    2013.03.14 00:11:59   ich2:1.4937
FF      0       12:38:36        k_orders_demo_04 (GBPUSD,H1)    2013.03.14 00:11:59   ich3:1.48792
KO      0       12:38:36        k_orders_demo_04 (GBPUSD,H1)    2013.03.14 00:11:59   ich4:1.489475
HG      0       12:38:36        k_orders_demo_04 (GBPUSD,H1)    2013.03.14 00:11:59   ich5:1.797693134862316e+308
GG      0       12:38:36        k_orders_demo_04 (GBPUSD,H1)    2013.03.14 00:12:00   ich1:1.49418
HM      0       12:38:36        k_orders_demo_04 (GBPUSD,H1)    2013.03.14 00:12:00   ich2:1.4937
KK      0       12:38:36        k_orders_demo_04 (GBPUSD,H1)    2013.03.14 00:12:00   ich3:1.48792
NS      0       12:38:36        k_orders_demo_04 (GBPUSD,H1)    2013.03.14 00:12:00   ich4:1.489475
IS      0       12:38:36        k_orders_demo_04 (GBPUSD,H1)    2013.03.14 00:12:00   ich5:1.797693134862316e+308
ED      0       12:38:36        k_orders_demo_04 (GBPUSD,H1)    2013.03.14 00:12:20   ich1:1.49418
FR      0       12:38:36        k_orders_demo_04 (GBPUSD,H1)    2013.03.14 00:12:20   ich2:1.4937
IH      0       12:38:36        k_orders_demo_04 (GBPUSD,H1)    2013.03.14 00:12:20   ich3:1.48792
PD      0       12:38:36        k_orders_demo_04 (GBPUSD,H1)    2013.03.14 00:12:20   ich4:1.489475
CP      0       12:38:36        k_orders_demo_04 (GBPUSD,H1)    2013.03.14 00:12:20   ich5:1.797693134862316e+308

 

Is there any reason why the ich5 buffer is not initializing? 

Many thanks for your help.

Best Regards

Kishor 

Alain Verleyen
Moderator
31183
Alain Verleyen  
kishor-mistry:

Hello Angevoyageur,

Many thanks for your explanation & suggestion. I have just tried the mod & it works very well. However, please note that ich5 buffer is still

printing out the same large no. as shown below:

 

 

Is there any reason why the ich5 buffer is not initializing? 

Many thanks for your help.

Best Regards

Kishor 

Did you change your code for ich5 as suggested above ?

if(CopyBuffer(h_ich,4,0+26,3,ich5_buffer)<3)
      {Print("err<3");}
      else
      {Print("ich5:",ich5_buffer[2]);}
kishor-mistry
19
kishor-mistry  
angevoyageur:

Did you change your code for ich5 as suggested above ?

Hello Angevoyageur, 

Yes - I just tried it. I now get some reasonable returns. That's great.

Much appreciate your kind help. Thank you very much.

Best Regards

Kishor 

Alain Verleyen
Moderator
31183
Alain Verleyen  
kishor-mistry:

Hello Angevoyageur, 

Yes - I just tried it. I now get some reasonable returns. That's great.

Much appreciate your kind help. Thank you very much.

Best Regards

Kishor 

You are welcome.
amin_mohammadi
88
amin_mohammadi  

Hello everybody,

I'm using iIchimoku function to create a handle for ichimoku.

After filling buffer arrays the gathered values are logical but they differ with the value shown in chart by hovering the mouse on them.

for example for kijun sen the value of Kijun_sen_Buffer[0] is:0.94392499999999 but in the same time in the chart the value is: 0.97932

and the code is :

bool TradeAnalyzer::FillArraysFromBuffers(void)
  {

//   if(type==Call_iIchimoku)
      ichimokuHandle=iIchimoku("AUDCAD.m",PERIOD_M1,9,26,52);
   //else
   //  {
   //   //--- fill the structure with parameters of the indicator
   //   MqlParam pars[3];
   //   //--- periods and shifts of the Alligator lines
   //   pars[0].type=TYPE_INT;
   //   pars[0].integer_value=9;
   //   pars[1].type=TYPE_INT;
   //   pars[1].integer_value=26;
   //   pars[2].type=TYPE_INT;
   //   pars[2].integer_value=52;
   //   //--- create handle
   //   ichimokuHandle=IndicatorCreate(_Symbol,_Period,IND_ICHIMOKU,3,pars);
   //  }
//--- if the handle is not created

amount = Bars("AUDCAD.m",PERIOD_M1);
   if(ichimokuHandle==INVALID_HANDLE)
     {
      //--- tell about the failure and output the error code
      PrintFormat(_Symbol,EnumToString(_Period),GetLastError());
      //--- the indicator is stopped early
      return(INIT_FAILED);
     }
//--- show the symbol/timeframe the Ichimoku Kinko Hyo indicator is calculated for
   short_name=StringFormat("iIchimoku(%s/%s, %d, %d ,%d)",_Symbol,EnumToString(_Period),9,26,52);
   IndicatorSetString(INDICATOR_SHORTNAME,short_name);
//--- normal initialization of the indicator 
   if(CopyBuffer(ichimokuHandle,0,0,amount,Tenkan_sen_Buffer)<0)
     {
      //--- if the copying fails, tell the error code
      PrintFormat("1.Failed to copy data from the iIchimoku indicator, error code %d",GetLastError());
      //--- quit with zero result - it means that the indicator is considered as not calculated
      return(false);
     }

//--- fill a part of the Kijun_sen_Buffer array with values from the indicator buffer that has index 1
   if(CopyBuffer(ichimokuHandle,1,0,amount,Kijun_sen_Buffer)<0)
     {
      //--- if the copying fails, tell the error code
      PrintFormat("2.Failed to copy data from the iIchimoku indicator, error code %d",GetLastError());
      //--- quit with zero result - it means that the indicator is considered as not calculated
      return(false);
     }

//--- fill a part of the Chinkou_Span_Buffer array with values from the indicator buffer that has index 2
//--- if senkou_span_shift>0, the line is shifted in the future direction by senkou_span_shift bars
   if(CopyBuffer(ichimokuHandle,2,-senkou_span_shift,amount,Senkou_Span_A_Buffer)<0)
     {
      //--- if the copying fails, tell the error code
      PrintFormat("3.Failed to copy data from the iIchimoku indicator, error code %d",GetLastError());
      //--- quit with zero result - it means that the indicator is considered as not calculated
      return(false);
     }

//--- fill a part of the Senkou_Span_A_Buffer array with values from the indicator buffer that has index 3
//--- if senkou_span_shift>0, the line is shifted in the future direction by senkou_span_shift bars
   if(CopyBuffer(ichimokuHandle,3,-senkou_span_shift,amount,Senkou_Span_B_Buffer)<0)
     {
      //--- if the copying fails, tell the error code
      PrintFormat("4.Failed to copy data from the iIchimoku indicator, error code %d",GetLastError());
      //--- quit with zero result - it means that the indicator is considered as not calculated
      return(false);
     }

//--- fill a part of the Senkou_Span_B_Buffer array with values from the indicator buffer that has 0 index
//--- when copying Chinkou Span, we don't need to consider the shift, since the Chinkou Span data
//--- is already stored with a shift in iIchimoku  
   if(CopyBuffer(ichimokuHandle,4,0,amount,Chinkou_Span_Buffer)<0)
     {
      //--- if the copying fails, tell the error code
      PrintFormat("5.Failed to copy data from the iIchimoku indicator, error code %d",GetLastError());
      //--- quit with zero result - it means that the indicator is considered as not calculated
      return(false);
     }

   return true;
Alain Verleyen
Moderator
31183
Alain Verleyen  
amin_mohammadi:

Hello everybody,

I'm using iIchimoku function to create a handle for ichimoku.

After filling buffer arrays the gathered values are logical but they differ with the value shown in chart by hovering the mouse on them.

for example for kijun sen the value of Kijun_sen_Buffer[0] is:0.94392499999999 but in the same time in the chart the value is: 0.97932

and the code is :

You have to use ArraySetAsSeries() with your buffers, otherwise index 0 is the oldest value on your chart.

Or try to print value like Kijun_sen_Buffer[amount-1] for current bar and Kijun_sen_Buffer[amount-2] for last closed bar.

12
To add comments, please log in or register