NexusFi: Find Your Edge


Home Menu

 





Reverse Exponential Moving Average


Discussion in NinjaTrader

Updated
    1. trending_up 3,839 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 3 posts
    2. attach_file 1 attachments




 
Search this Thread

Reverse Exponential Moving Average

  #1 (permalink)
 
cutzpr's Avatar
 cutzpr 
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); 

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
ZombieSqueeze
Platforms and Indicators
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
MC PL editor upgrade
MultiCharts
Quant vue
Trading Reviews and Vendors
Cheap historycal L1 data for stocks
Stocks and ETFs
 
  #3 (permalink)
 
cutzpr's Avatar
 cutzpr 
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 kcalcbar ;     
    
double lambda,lambdatornumerator,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);
                
Period;
                
lambda=  2.0 / (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 == 0Value[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  kReversePTR >0ReversePTR--)
                { 
             
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
Started this thread Reply With Quote
  #4 (permalink)
 buzzsaw 
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

Reply With Quote
Thanked by:




Last Updated on September 3, 2017


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts