TMA-RSI from NaningBob

Posted By: freedom0x0

TMA-RSI from NaningBob - 06/20/13 12:57

hi
I am trying to port over the naningbob's TMA-RSI indicator to zorro.

I am having trouble in TMA-RSI calculation.
The the indicator was supposed to used the arrays of TMASlope to calculate the RSI and the TMASlope is recalculated all the time.
Any suggestion to fix this?

lite-c
var TMA_Slope_RSI ( int period, int shift) {
var *TMA_Slope_Values = malloc((shift+period + 10 ) * sizeof(var));
int i =0;
for ( i = shift; i < (shift+period + 10); i++ ){
TMA_Slope_Values[i] = TMASlope(i) ;
}
var cur_rsi = RSI(TMA_Slope_Values,period);
printf( "\n tmarsi1 = %.4f" , cur_rsi );
free(TMA_Slope_Values);
return cur_rsi;
}

Mt4
double GetSlopeRSI(string symbol, int tf, int shift)
{
//We could cut these calculation dramatically as we only need the
//set of bars necessary to run the calc. Make slick later.
double curRSI;

//Get our values to calc RSI on.
//fill the array not sure how small this can be.
//but we have to call a slope for every value. This works and only makes
//12 calls instead of 200 or 2000
for ( int i = shift; i < shift+RSIPeriod + 10; i++ )
{
TMA_Slope_Values[i] = GetSlope(symbol,tf,i) ;
}

curRSI = iRSIOnArray(TMA_Slope_Values,ArraySize(TMA_Slope_Values),RSIPeriod,shift);
//Print("curRSI " + curRSI + " TF: " +tf + " Shift: " + shift);
return(curRSI);

}

BTW, i am wondering if the TriMA in the indicator is having the same calculation of NaningBob's TMA ?
Posted By: jcl

Re: TMA-RSI from NaningBob - 06/20/13 13:17

What for do you need malloc()? From what I see, your function TMA_Slope_RSI is just "RSI(series(TMASlope(0))+shift,period);" - if I have not misunderstood it.

The Zorro Trima is the TMA, but I am not sure if the MT4 TMA is the TMA. MT4 indicators often produce different results than the real indicators they are named after.
Posted By: freedom0x0

Re: TMA-RSI from NaningBob - 06/21/13 10:51

Thanks jcl, it think it really simplified the algo.

BTW, may i know what this code mean?
series(TMASlope(0))+shift

Does it return the series' pointer added with the shift?
So that the data that push in the RSI is a shifted data series?
Posted By: jcl

Re: TMA-RSI from NaningBob - 06/21/13 11:27

Yes, it returns the series pointer and adds the shift to the pointer, so you get an offset into the series. This is equivalent to the MT4 shift parameter.

Alternatively, this would produce the same result:

RSI(series(TMASlope(shift)),period);
Posted By: FalseDave

Re: TMA-RSI from NaningBob - 06/22/13 12:12

Heres a script I adapted a while back using NB's 10.2 to look at slope values. I adapted it the other day to use an RSI of the slope value. This might be of some use to you. Maybe not.
Code:
var valOpen()
{  
   var val = 0;  
   for(open_trades)    
      if(strstr(TradeAsset,Asset) && TradeIsOpen)      
      val += TradeResult;  
  return val;
}


//+------------------------------------------------------------------+
//| calcTmaTrue()                                                                        |
//+------------------------------------------------------------------+
double calcTmaTrue( int inx )
{
   // return ( iMA( symbol, tf, 21, 0, MODE_LWMA, PRICE_CLOSE, inx ) );
   vars Close = series(priceClose());
   double dblSum  = 0;
   double dblSumw = 0;
   int jnx, knx;
   int sundayCandles = 0;

   for ( jnx = 0, knx = 21; jnx < 21; jnx++, knx-- )
   {   
      dblSum  += Close[inx + jnx + sundayCandles] * knx;
      dblSumw += knx;
   }
   
   return ( dblSum / dblSumw );
}

//+------------------------------------------------------------------+
//| calcPrevTrue()                                                                        |
//+------------------------------------------------------------------+
double calcPrevTrue( int inx )
{
   vars Close = series(priceClose());
   double dblSum  = Close[ inx ] * 20;
   double dblSumw = 20;
   int jnx, knx;
   int sundayCandles = 0;
   
   for ( jnx = 1, knx = 21; jnx < 22; jnx++, knx-- )
   {   
      dblSum  += Close[ inx + jnx + sundayCandles ] * knx;
      dblSumw += knx;
   }
   
   return ( dblSum / dblSumw );
}

//+------------------------------------------------------------------+
//| GetSlope()                                                                              |
//+------------------------------------------------------------------+
double GetSlope(int shift)
{
   int shiftWithoutSunday = shift;  
   double atr = ATR(100) / 10;
   double gadblSlope = 0.0;
   if ( atr != 0 )
   {
      double dblTma = calcTmaTrue( shiftWithoutSunday );
      double dblPrev = calcPrevTrue( shiftWithoutSunday );
      gadblSlope = ( dblTma - dblPrev ) / atr;
   }
   
   return ( gadblSlope );

}

function run()
{
   BarPeriod = 240;                                  // 4H Period
   StartDate = 20120101;
   EndDate = 20130701;
   LookBack = 500;
   set(PLOTNOW|PLOTPRICE);

   //while(asset(loop("EUR/USD","USD/JPY","GBP/USD","AUD/USD","NZD/USD","USD/CAD","USD/CHF")));
   //{
      vars Price = series(price());
      vars PriceOpen = series(priceOpen());
      vars TwoFortyMA = series(LowPass(PriceOpen,240));
      
      vars Slope = series(GetSlope(0));
      vars SlopeRSI = series(RSI(Slope,2));
       
      if (Price[0] > TwoFortyMA[0] && Price[0] > TestMA[0] && rising(TestMA) && NumOpenLong < 1 )
      {
         enterLong();
      }
      
      if (Price[0] < TwoFortyMA[0] && Price[0] < TestMA[0] && falling(TestMA) && NumOpenShort < 1 )
      {
         enterShort();  
      }
      
      
      TakeProfit = 100*PIP;
      //Stop = 100 * PIP;
      
      plot("TwoFortyMA",TwoFortyMA[0],0,GREEN);
      plot("TestMA",TestMA[0],0,BLUE);
      plot("Slope",Slope[0],NEW,RED);
      plot("SlopeRSI",SlopeRSI[0],NEW,GREEN);   
   //}   
}

Posted By: freedom0x0

Re: TMA-RSI from NaningBob - 06/22/13 16:13

Thansk FalseDave.

I am now planning to code weekly pivot.
I am not sure if I code it correctly.
Should i calculate on Monday only and save it as global variable or calcuate every run?
Please advice.


BarPeriod = 240;
TimeFrame = 6*5;


var Close = priceClose(1);
var High = priceHigh(1);
var Low = priceLow(1);
var Pivot = (Close + High + Low) / 3;

var S1 = 2*Pivot - High;
var S2 = Pivot - (High - Low);
var S3 = 2*Pivot - (2*High - Low);
var R1 = 2*Pivot - Low;
var R2 = Pivot + (High - Low);
var R3 = 2*Pivot + (High - 2*Low);


BTW FalseDave, the TMA used in NaningBob seems like different from what the formula googled.
Do you have any good reference on the TMA algo?
Posted By: FalseDave

Re: TMA-RSI from NaningBob - 06/26/13 11:31

The TMA slope code I used was taken from one of the MT4 indicator from NB's system. A while backnow I'll have to try and find the exact one. When plotted and using a short TimeFrame I think it looks correct as far as I can tell.

JCL informs me that TMA is a double SMA.

function TMA(var *data,int period)
{
return SMA(series(SMA(data,period),period));
}

I stuck with what I had as it seemed to work but JCL is probably correct.
Posted By: magft

Re: TMA-RSI from NaningBob - 08/13/13 12:21

I plotted out the two versions for TMA and they not the same. This leads me to believe the one from nanningbob indicator is not a standard TMA as jcl knows his stuff.

Anyway here is the code that plots them both and the TMASlope and RSI(2) of TMASlope for those interested.

Code:
//+------------------------------------------------------------------+
//| TMA by jcl double SMA                                            |
//+------------------------------------------------------------------+
double TMA(var *data,int period) 
{ 
	return SMA(series(SMA(data,period)),period); 
}

//+------------------------------------------------------------------+
//| calcTmaTrue()                                                    |
//+------------------------------------------------------------------+
double calcTmaTrue( int inx )
{
   // return ( iMA( symbol, tf, 21, 0, MODE_LWMA, PRICE_CLOSE, inx ) );
   vars Close = series(priceClose());
   double dblSum  = 0;
   double dblSumw = 0;
   int jnx, knx;
   int sundayCandles = 0;

   for ( jnx = 0, knx = 21; jnx < 21; jnx++, knx-- )
   {   
      dblSum  += Close[inx + jnx + sundayCandles] * knx;
      dblSumw += knx;
   }
   
   return ( dblSum / dblSumw );
}

//+------------------------------------------------------------------+
//| calcPrevTrue()                                                   |
//+------------------------------------------------------------------+
double calcPrevTrue( int inx )
{
   vars Close = series(priceClose());
   double dblSum  = Close[ inx ] * 20;
   double dblSumw = 20;
   int jnx, knx;
   int sundayCandles = 0;
   
   for ( jnx = 1, knx = 21; jnx < 22; jnx++, knx-- )
   {   
      dblSum  += Close[ inx + jnx + sundayCandles ] * knx;
      dblSumw += knx;
   }
   
   return ( dblSum / dblSumw );
}

//+------------------------------------------------------------------+
//| GetSlope()                                                                              |
//+------------------------------------------------------------------+
double GetSlope(int shift)
{
   int shiftWithoutSunday = shift;  
   double atr = ATR(100) / 10;
   double gadblSlope = 0.0;
   if ( atr != 0 )
   {
      double dblTma = calcTmaTrue( shiftWithoutSunday );
      double dblPrev = calcPrevTrue( shiftWithoutSunday );
      gadblSlope = ( dblTma - dblPrev ) / atr;
   }
   
   return ( gadblSlope );

}

function run()
{
   BarPeriod = 240;                                  // 4H Period
   StartDate = 20120101;
   EndDate = 20130701;
   LookBack = 500;
   set(PLOTNOW|PLOTPRICE);

   
   vars Price = series(price());
   vars TMATrue = series(calcTmaTrue(0));
   vars jclTMA = series(TMA(Price,10));  //not sure what period meant to be but none match TMATrue
   vars Slope = series(GetSlope(0));
   vars RSISlope = series(RSI(Slope,2));
   
   plot("TMATrue",TMATrue[0],0,BLUE);
   plot("jclTMA",jclTMA[0],0,RED);
   plot("SlopeTMATrue",Slope[0],NEW,RED);
   plot("RSISlopeTMATrue",RSISlope[0],NEW,GREEN);   
   
}



I do like the simplicity of Zorro.

Regards

Mike
Posted By: BobbyT

Re: TMA-RSI from NaningBob - 06/29/17 23:27

Hello everyone,

Sorry for the thread necromancy. Although it's not the best way to start on a forum I figured this thread would be a good place to ask the following instead of creating a new one (if admin would like a new thread instead feel free to move this to one or ask me to do it myself).

Q: Do any of the above have NB/Baluda's CSS indicator transcribed into lite-c? I should be able to manage this myself but I'm new to zorro/lite-c so it's going to take some leg-work on my end to get it up and running. So I was hoping some kind soul has already done so, especially seeing as some of NBs bits'n'bobs have turned up here.

Is it as simple as calculating the slope as per above then feeding the values into the CurrencyStrength indi that comes with Zorro? I would like to think it's that simple but the CurrencyStength indi looks like it only updates the most recent value in the array meaning NBs CSS would be wrong on the most recent value as it recalculates the past 20 values every new bar from bar20 to bar0.

Thanks for your time and sorry again for the necro thread.

Cheers,
BobbyT
© 2024 lite-C Forums