Greetings,

I've been playing around with converting an indicator popular on Steve Hopwoods and other sites, TMA_CG. Essentially using TMA bands + and - some Band deviation as a building block for the EA. Here is the link to the strategy and indicator: http://www.stevehopwoodforex.com/phpBB3/viewtopic.php?f=5&t=3372

I'm running into some confusing times converting arrays from MT4 into series in Zorro. Here is the offending code:
Code:
void calculateTma(int limit)
{
   int i,j,k;
   double FullLength = 2.0*HalfLength+1.0;
     
   for (i=limit; i>=0; i--)
   {
      double sum  = (HalfLength+1)*iMA(NULL,0,1,0,MODE_SMA,Price,i);
      double sumw = (HalfLength+1);
      for(j=1, k=HalfLength; j<=HalfLength; j++, k--)
      {
         sum  += k*iMA(NULL,0,1,0,MODE_SMA,Price,i+j);
         sumw += k;

         if (j<=i)
         {
            sum  += k*iMA(NULL,0,1,0,MODE_SMA,Price,i-j);
            sumw += k;
         }
      }
      tmBuffer[i] = sum/sumw;
  
      double diff = iMA(NULL,0,1,0,MODE_SMA,Price,i)-tmBuffer[i];
      if (i> (Bars-HalfLength-1)) continue;
      if (i==(Bars-HalfLength-1))
      {
         upBuffer[i] = tmBuffer[i];
         dnBuffer[i] = tmBuffer[i];
         if (diff>=0)
            {
               wuBuffer[i] = MathPow(diff,2);
               wdBuffer[i] = 0;
            }
         else
            {               
               wdBuffer[i] = MathPow(diff,2);
               wuBuffer[i] = 0;
            }                  
         continue;
      }
      if(diff>=0)
      {
          wuBuffer[i] = (wuBuffer[i+1]*(FullLength-1)+MathPow(diff,2))/FullLength;
          wdBuffer[i] =  wdBuffer[i+1]*(FullLength-1)/FullLength;
      }
      else
      {
           wdBuffer[i] = (wdBuffer[i+1]*(FullLength-1)+MathPow(diff,2))/FullLength;
           wuBuffer[i] =  wuBuffer[i+1]*(FullLength-1)/FullLength;
      }
      upBuffer[i] = tmBuffer[i] + BandsDeviations*MathSqrt(wuBuffer[i]);
      dnBuffer[i] = tmBuffer[i] - BandsDeviations*MathSqrt(wdBuffer[i]);
   }
}



I've attempted to convert this code and I get a nice crash on Zorro crazy My problem is that I get confused on when to use a Zorro series as a whole, just use the last bar of it with [0], or when I should actually be performing operations in a for loop...

Also, how in the world do I represent the i+j portion of the above code:
Code:
iMA(NULL,0,1,0,MODE_SMA,Price,i+j);



Print statements help but haven't been sure-fire. Appreciate any thoughts.

Last edited by Mandark; 02/27/14 01:10. Reason: Added full function code for comparison