Dark Theme
Light Theme
Trading Articles
Article Categories
Article Tools
Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to
register in order to view the content of the threads and start contributing to our community.
It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Reverse Exponential Moving Average
Updated September 3, 2017
trending_up
3,839 views
thumb_up
1 thanks given
group
2 followers
forum
3 posts
attach_file
1 attachments
Reverse Exponential Moving Average
January 20th, 2016, 10:41 AM
United States
Experience: None
Platform: TWS,Ninja Trader
Trading: Forex, Futures, Stocks
Posts: 35 since Apr 2012
Thanks Given: 10
Thanks Received: 10
Does anyone have a Reverse Exponential Moving Average ninjascript? Or can help me convert this code from Amibrokers to Ninjatrader
// Reverse EMA function, by D.Tsokakis, June 2003
Code
P = 20 ;
CLOSEviaEMA = 0.5 *(( P + 1 )* EMA ( C , P )-( P - 1 )* Ref ( EMA ( C , P ),- 1 ));
Plot
( C , "CLOSE" , 1 , 1 );
Plot
( CLOSEviaEMA , "CLOSEviaEMA" , 7 , 8 );
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
January 25th, 2016, 02:02 PM
United States
Experience: None
Platform: TWS,Ninja Trader
Trading: Forex, Futures, Stocks
Posts: 35 since Apr 2012
Thanks Given: 10
Thanks Received: 10
I need some coding/math guru's to please let me know what is wrong with this code. The formula for a Reverse Exponential Moving Average is .
There are two different methods to calc this formula which I believe I coded correctly, but all I am getting is essentially a straight line, not a moving average even after verifying different inputs. Is there something wrong with the coding of the formula? or how I am processing the bars? Please assist.
Code
public class ReverseEMA : Indicator
{
//public Series<double> rEMA;
int k , calcbar ;
double lambda , lambdator , numerator , denominator , quotient ;
protected override void OnStateChange ()
{
if ( State == State . SetDefaults )
{
Description = @ "ReverseEMA" ;
Name = "ReverseEMA" ;
Calculate = Calculate . OnBarClose ;
IsOverlay = true ;
DisplayInDataBox = true ;
DrawOnPricePanel = true ;
DrawHorizontalGridLines = true ;
DrawVerticalGridLines = true ;
PaintPriceMarkers = true ;
ScaleJustification = NinjaTrader . Gui . Chart . ScaleJustification . Right ;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true ;
Period = 10 ;
BarsRequiredToPlot = Period ; // Do not plot until their are atleast enough bars to calcu REMA
AddPlot ( Brushes . DarkBlue , "REMA" );
}
else if ( State == State . Configure )
{
//rEMA = new Series<double>(this);
k = Period ;
lambda = 2.0 / ( 1 + k );
lambdator = 1.0 ;
numerator = 0.0 ;
denominator = 0.0 ; // REMA formula-expansion contains +1 at the end, never less, never negative
}
} //protected override void OnStateChange()
protected override void OnBarUpdate ()
{
if ( CurrentBars [ 0 ] < BarsRequiredToPlot ) return; // Ensures we have enough bars loaded for our iterations and indicator
if ( CurrentBar == 0 ) Value [ 0 ] = Input [ 0 ]; // Sets temp value for indicator first bar
/*-----------------------------------------------------------------------------/
Only used for error checking if Lambda will be independant
of Period
-----------------------------------------------------------------------------*/
/*
if ( lambda <= 0.0 // lambda shall not fall on/under 0.0
|| lambda > 1.0 // shall not grow beyond 1.0
|| k <= 0 // depth shall not be negative or 0
)
return -1.0; // context-protecting RET value
*/
/*-----------------------------------------------------------------------------/
First way for code formula
-----------------------------------------------------------------------------*/
double quotient ;
for ( int ReversePTR = k ; ReversePTR > 0 ; ReversePTR --)
{
calcbar = CurrentBar - ReversePTR ;
numerator += Math . Pow ( lambda , k - ReversePTR ) * Input [ calcbar ];
denominator += Math . Pow ( lambda , k - ReversePTR );
quotient = numerator / denominator ;
Print( " I am on bar " + CurrentBar +
"\r\n The CalcBar is " + calcbar +
"\r\n The Price is " + Input [ calcbar ] +
"\r\n The ReversePTR is " + ReversePTR +
"\r\n The current count is " + ( k - ReversePTR ) +
"\r\n The Lambda is " + Math . Pow ( lambda , k - ReversePTR ) +
"\r\n The Numerator is " + numerator +
"\r\n The Denominator is " + denominator +
"\r\n The quotient is " + quotient +
"\r\n-------------------------" );
}
Values [ 0 ][ 0 ] = ( numerator / denominator );
Print( " The REMA is " + Values [ 0 ][ 0 ] +
"\r\n" );
/*-----------------------------------------------------------------------------/
Second way for code formula
------------------------------------------------------------------------------/
for (int ReversePTR = k; ReversePTR >0; ReversePTR--)
{
calcbar = CurrentBars[0] - ReversePTR;
numerator += lambdator * Input[calcbar];
denominator += lambdator;
lambdator *= lambda;
quotient = numerator / denominator;
Print(" I am on bar " + CurrentBar +
"\r\n The CalcBar is " + calcbar +
"\r\n The Price is " + Input[calcbar] +
"\r\n The ReversePTR is " + ReversePTR +
"\r\n The current count is " + (k-ReversePTR) +
"\r\n The Lambdator is " + lambdator +
"\r\n The Numerator is " + numerator +
"\r\n The Denominator is " + denominator +
"\r\n The quotient is " + quotient +
"\r\n -------------------------");
}
Values[0][0] = (numerator / denominator);
Print(" The REMA is " + Values[0][0] +
"\r\n");
*/
//-----------------------------------------------------------------------
} //protected override void OnBarUpdate()
Attached Files
Elite Membership required to download: CC.ReverseEMA.cs
September 3rd, 2017, 06:18 AM
Leesburg, VA
Experience: Advanced
Platform: NinjaTrader
Posts: 80 since Aug 2010
Thanks Given: 78
Thanks Received: 35
Did you ever get this going?. The new S&C article has links to code for NT7 & 8 and other platforms.
TRADERS’ TIPS - SEPTEMBER 2017
Last Updated on September 3, 2017