Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Just downloaded NT, translating from TS

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Just downloaded NT, translating from TS

    Hello...

    To get myself at the right track from the beginning, I've a couple of questions.

    I'm trying to translate an .ELD file from Tradestation, this .ELD uses a function called XAverageOrig, take a look here:
    inputs:
    Price(numericseries),
    Length(numericsimple);{ this input assumed to be a constant >= 1 }
    variables:
    SmoothingFactor(1/Length);
    ifCurrentBar=1then
    XAverageOrig=Price
    else
    XAverageOrig=XAverageOrig[1]+SmoothingFactor*(Price-XAverageOrig[1]);


    I'm a little confused, should I code it as an indicator ie. like SMA or should it be a custom method? I did try to program it as a method:
    publicdouble XAverageOrig(IDataSeries price, int length)
    {

    double smoothingFactor = 1/length;

    if (CurrentBar == 1)
    return price[0];
    else
    return XAverageOrig(price, length) + smoothingFactor * (price[0] - XAverageOrig(price, length));



    }

    But as I feared it behaved like a recursion and killed my CPU

    Any help?

    Kind regards
    Januson


    #2
    I would code it as an indicator, that way you can code it once and have it available for anything that can use an indicator.

    What I would do is create an indicator via the wizard and lets name the plot XAvg in the wizard.

    In OnBarUpdate()

    Code:
    double smoothingFactor = 1 / length;
    
    if (CurrentBar == 1)
        XAvg.Set(Input[0]);
    else
      XAvg.Set(XAvg[1] + smoothingFactor * (Input[0] - XAvg[1]));
    Note: I use Input[0] which refers to the default value passed into this indicator such as High or Close or Low price, or another indicator for that matter.
    RayNinjaTrader Customer Service

    Comment


      #3
      I should have added that you need to code this as an indicator since you have to maintain an array of calculated values by where a method does not do that for you.

      I am referring to accessing the value of XAvg of 1 bar ago.
      RayNinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by andrewtrades, Today, 04:57 PM
      1 response
      10 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by chbruno, Today, 04:10 PM
      0 responses
      6 views
      0 likes
      Last Post chbruno
      by chbruno
       
      Started by josh18955, 03-25-2023, 11:16 AM
      6 responses
      436 views
      0 likes
      Last Post Delerium  
      Started by FAQtrader, Today, 03:35 PM
      0 responses
      9 views
      0 likes
      Last Post FAQtrader  
      Started by rocketman7, Today, 09:41 AM
      5 responses
      20 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Working...
      X