3 registered members (7th_zorro, Aku_Aku, 1 invisible),
579
guests, and 1
spider. |
Key:
Admin,
Global Mod,
Mod
|
|
|
TMA-RSI from NaningBob
#424690
06/20/13 12:57
06/20/13 12:57
|
Joined: Jun 2013
Posts: 6
freedom0x0
OP
Newbie
|
OP
Newbie
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: jcl]
#424818
06/22/13 12:12
06/22/13 12:12
|
Joined: May 2013
Posts: 16
FalseDave
Newbie
|
Newbie
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.
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
freedom0x0
OP
Newbie
|
OP
Newbie
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: FalseDave]
#427764
08/13/13 12:21
08/13/13 12:21
|
Joined: Jul 2013
Posts: 1
magft
Guest
|
Guest
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.
//+------------------------------------------------------------------+
//| 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
|
|
|
|