Tenkan sen value

 

I am trying to list the value of the tenkan sen but it keeps displaying 0.00000

Any ideas?


//---- Tenkan Sen
   i=Bars-Tenkan;
   if(counted_bars>Tenkan) i=Bars-counted_bars-1;
   while(i>=0)
     {
      high=High[i]; low=Low[i]; k=i-1+Tenkan;
      while(k>=i)
        {
         price=High[k];
         if(high<price) high=price;
         price=Low[k];
         if(low>price)  low=price;
         k--;
        }
      Tenkan_Buffer[i]=(high+low)/2;
      i--;
      
      Comment ("TS: "+ DoubleToStr(Tenkan_Buffer[0],5));
     }
 

Sometimes index buffers don't really get set while you are still in the loop.

I have had to create a second loop to see values... after the first loop has completed.

Don't know why.

Also, you are dividing a double by an integer --

Tenkan_Buffer[i]=(high+low)/2;

change to

Tenkan_Buffer[i]=(high+low)/2.0;

 

I think this is the standard code that gets shipped with the Ichimoku indicator but I'll check that.

Will this do it for the alert? If I want to compare it to the previoud value is i=+1 or -1 ? Logically it should be -1 but I've seen different code.

//----ALERTS
//---- TS cross KS
if (Tenkan_Buffer[0] > Kijun_Buffer[0] && Tenkan_Buffer[-1] < Kijun_Buffer[-1])
{  //crossed upwards
   Alert ("TS crossed KS upwards on+ "+Symbol());}
if (Tenkan_Buffer[0] < Kijun_Buffer[0] && Tenkan_Buffer[-1] > Kijun_Buffer[-1])
{  //crossed downwards
   Alert ("TS crossed KS downwards on+ "+Symbol());}