Gamestudio Links
Zorro Links
Newest Posts
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
Data from CSV not parsed correctly
by jcl. 04/20/24 08:32
Zorro FIX plugin - Experimental
by jcl. 04/20/24 08:30
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (7th_zorro, Aku_Aku, 1 invisible), 579 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
TMA-RSI from NaningBob #424690
06/20/13 12:57
06/20/13 12:57
Joined: Jun 2013
Posts: 6
F
freedom0x0 Offline OP
Newbie
freedom0x0  Offline OP
Newbie
F

Joined: Jun 2013
Posts: 6
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 ?

Re: TMA-RSI from NaningBob [Re: freedom0x0] #424692
06/20/13 13:17
06/20/13 13:17
Joined: Jul 2000
Posts: 27,982
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,982
Frankfurt
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.

Re: TMA-RSI from NaningBob [Re: jcl] #424758
06/21/13 10:51
06/21/13 10:51
Joined: Jun 2013
Posts: 6
F
freedom0x0 Offline OP
Newbie
freedom0x0  Offline OP
Newbie
F

Joined: Jun 2013
Posts: 6
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?

Re: TMA-RSI from NaningBob [Re: freedom0x0] #424760
06/21/13 11:27
06/21/13 11:27
Joined: Jul 2000
Posts: 27,982
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,982
Frankfurt
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);

Re: TMA-RSI from NaningBob [Re: jcl] #424818
06/22/13 12:12
06/22/13 12:12
Joined: May 2013
Posts: 16
F
FalseDave Offline
Newbie
FalseDave  Offline
Newbie
F

Joined: May 2013
Posts: 16
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);   
   //}   
}


Re: TMA-RSI from NaningBob [Re: jcl] #424834
06/22/13 16:13
06/22/13 16:13
Joined: Jun 2013
Posts: 6
F
freedom0x0 Offline OP
Newbie
freedom0x0  Offline OP
Newbie
F

Joined: Jun 2013
Posts: 6
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?

Last edited by freedom0x0; 06/22/13 16:18.
Re: TMA-RSI from NaningBob [Re: freedom0x0] #425078
06/26/13 11:31
06/26/13 11:31
Joined: May 2013
Posts: 16
F
FalseDave Offline
Newbie
FalseDave  Offline
Newbie
F

Joined: May 2013
Posts: 16
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.

Re: TMA-RSI from NaningBob [Re: FalseDave] #427764
08/13/13 12:21
08/13/13 12:21
Joined: Jul 2013
Posts: 1
M
magft Offline
Guest
magft  Offline
Guest
M

Joined: Jul 2013
Posts: 1
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

Re: TMA-RSI from NaningBob [Re: magft] #466736
06/29/17 23:27
06/29/17 23:27
Joined: Jun 2017
Posts: 78
B
BobbyT Offline
Junior Member
BobbyT  Offline
Junior Member
B

Joined: Jun 2017
Posts: 78
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


Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1