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

convert tradestation to ninjatrader - 3 lines of code

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

    convert tradestation to ninjatrader - 3 lines of code

    I'm trying to convert this oscillator code from tradestation easy language to ninja.



    int Value1 = 100 * ( XAverage( XAverage( Close - (.5 * ( Highest( High, Length ) + Lowest( Low, Length ) ) ), Smooth1), Smooth2) / (.5 * XAverage( XAverage( Highest( High, Length )- Lowest( Low, Length ), Smooth1 ), Smooth2 ) ) ) ;



    I have got this far but it does look like what it shoudl: please help! its my first indicator in ninja thanks


    Code:
     protected override void OnBarUpdate()
            {
                // Use this method for calculating your indicator values. Assign a value to each
                // plot below by replacing 'Close[0]' with your own formula.
                
                int highestBar =  HighestBar( High, Length );
                int lowestBar = LowestBar( Low, Length ) ;
                
                
                DataSeries myDataSeries = new DataSeries(this);
                
                myDataSeries.Set(highestBar - lowestBar);    
                
                double internalEMAChild = EMA(myDataSeries,Smooth1)[0];
                            
                DataSeries myDataSeries2 = new DataSeries(this);                    
                myDataSeries2.Set(internalEMAChild);                            
                double internalEMAParent = .5 *( EMA(myDataSeries2,Smooth2)[0]);
                
                        
                DataSeries myDataSeries3 = new DataSeries(this);
                double tempLowestHighest = Close[0] - ( .5 * (highestBar + lowestBar));
                            
                
                myDataSeries3.Set(tempLowestHighest);
                double externalEMAChild = EMA( myDataSeries3,Smooth1)[0];
                
                DataSeries myDataSeries4 = new DataSeries(this);
                myDataSeries4.Set(externalEMAChild);
                double externalEMAParent = EMA(myDataSeries4,Smooth2)[0];            
                
                
                Plot0.Set(100 * (externalEMAParent /internalEMAParent ));
            }
    Last edited by fudge; 06-21-2009, 04:44 PM. Reason: Convert code from Tradestation to Ninja - 3 lines only

    #2
    Hi,

    I didn't go through the code in detail but it looks like you are using Ninja's HighestBar() to replicate the TS function Highest(), they are not the same.
    Highest () in TS represents the highest value over a period, HighestBar() in NT will return the number of bars ago the highest price occurred within the period, not the value itself.

    The NT equivalent to TS Highest() is MAX()

    NT function MAX()
    Definition
    Returns the highest value over the specified period.


    TS function Highest()
    The Highest function returns the highest price over a range of bars.

    Also, you probably want to create your dataseries object in Initialize()


    Code:
    protected override void Initialize() 
    { 
        myDataSeries = new DataSeries(this); // "this" refers to the indicator, or strategy 
                                             // itself. This syncs the DataSeries object 
                                             // to historical data bars 
    }
    Regards,
    TG
    Last edited by TraderGuy; 06-21-2009, 07:09 PM.
    TraderGuy
    NinjaTrader Ecosystem Vendor - EMS

    Comment


      #3
      Ninjascript tutorials

      I think the guys behind ninjatrader should review their business model. If they concentrate on showing off what the software can do....as they do now, they will do just fine. If in addition they put in some effort to enable users make full use of the software's potential, they they will surpass whatever projections they have (IMHO). Most persons who like Nijatrader are held back by the lack of interest shown by the owners to simplify the coding learning process for traders; especially for those coming from other platforms.
      For example, Tradestation and Metaquotes are very much older and more popular than Ninjatrader.....so quite a number of those wishing to use ninjatrader have some tools developed on these older platforms. What a help it will be if Ninjatrader guys made some effort like if they had a section for teaching the relationship between it's language and the others!
      Some form of tutorial forum where whoever wishes can be encouraged to organise lessons for newbie coders will go a long way.......see what coders guru and others have done for MT4.
      Cheers all.

      Comment


        #4
        boboinuk, thanks for the input and feedback. We're always looking to expand our available educational materials.

        For our basic indicator coding tutorials, please review this link -



        For strategies this one -



        For NinjaScript related reference samples and tips, please check this -



        Furthermore the comprehensive NinjaScript language reference can be found in the help guide (press F1 anywhere in NinjaTrader) under NinjaScript > NinjaScript Language Reference.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          I agree with Boboinuk, maybe we should start a topic about conversions. It is so hard to search the forums to find a post to show what the equivalent NT code for the TS XAverage is, for example.
          eDanny
          NinjaTrader Ecosystem Vendor - Integrity Traders

          Comment


            #6
            eDanny, thanks for the input, I'll forward this idea.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Jesus Fing Christ

              I did everything that i can by reading these forums but no luck...this why i have stuck with TS for 6 years now...i can call them ask they anything i want and they will help! my time is more important studying markets etc than programming in an over complicated platform.


              all this and it still don t work...it draws but completely wrong

              {

              [Description("")]
              public class MomentumIndicator : Indicator
              {
              #region Variables
              // Wizard
              private int length = 121; // Default setting for Length
              private int smooth1 = 12; // Default setting for Smooth1
              private int smooth2 = 13; // Default setting for Smooth2
              DataSeries myDataSeries = null;
              DataSeries myDataSeries2 = null;
              DataSeries myDataSeries3 = null;
              DataSeries myDataSeries4 = null;

              // User defined variables (add any user defined variables below)
              #endregion

              /// <summary>
              /// This method is used to configure the indicator and is called once before any bar data is loaded.
              /// </summary>
              protected override void Initialize()
              {
              Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
              CalculateOnBarClose = true;
              Overlay = false;
              PriceTypeSupported = false;
              myDataSeries = new DataSeries(this);
              myDataSeries2 = new DataSeries(this);
              myDataSeries3 = new DataSeries(this);
              myDataSeries4 = new DataSeries(this);
              }

              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              protected override void OnBarUpdate()
              {
              // Use this method for calculating your indicator values. Assign a value to each
              // plot below by replacing 'Close[0]' with your own formula.


              double highestBar = MAX( High, Length )[0];
              double lowestBar = MAX( Low, Length )[0] ;

              MDS.Set(highestBar - lowestBar);

              double internalEMAChild = EMA(myDataSeries,Smooth1)[0];


              MDS2.Set(internalEMAChild);
              double internalEMAParent = .5 *( EMA(MDS2,Smooth2)[0]);

              double tempLowestHighest = Close[0] - ( .5 * (highestBar + lowestBar));


              MDS3.Set(tempLowestHighest);
              double externalEMAChild = EMA( MDS3,Smooth1)[0];

              MDS4.Set(externalEMAChild);
              double externalEMAParent = EMA(MDS4,Smooth2)[0];


              Plot0.Set((externalEMAParent /internalEMAParent ));
              }

              #region Properties
              [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
              [XmlIgnore()]
              public DataSeries MDS
              {
              get { Update(); return myDataSeries; }
              }

              [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
              [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
              public DataSeries MDS2
              {
              get { Update(); return myDataSeries2; }
              }
              [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
              [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
              public DataSeries MDS3
              {
              get { Update(); return myDataSeries3; }
              }
              [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
              [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
              public DataSeries MDS4
              {
              get {Update(); return myDataSeries4; }
              }



              [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
              [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
              public DataSeries Plot0
              {
              get { return Values[0]; }
              }

              [Description("")]
              [Category("Parameters")]
              public int Length
              {
              get { return length; }
              set { length = Math.Max(1, value); }
              }

              [Description("")]
              [Category("Parameters")]
              public int Smooth1
              {
              get { return smooth1; }
              set { smooth1 = Math.Max(1, value); }
              }

              [Description("")]
              [Category("Parameters")]
              public int Smooth2
              {
              get { return smooth2; }
              set { smooth2 = Math.Max(1, value); }
              }
              #endregion
              }
              }

              #region NinjaScript generated code. Neither change nor remove.
              // This namespace holds all indicators and is required. Do not change it.
              namespace NinjaTrader.Indicator
              {
              public partial class Indicator : IndicatorBase
              {
              private MomentumIndicator[] cacheMomentumIndicator = null;

              private static MomentumIndicator checkMomentumIndicator = new MomentumIndicator();

              /// <summary>
              /// Enter the description of your new custom indicator here
              /// </summary>
              /// <returns></returns>
              public MomentumIndicator MomentumIndicator(int length, int smooth1, int smooth2)
              {
              return MomentumIndicator(Input, length, smooth1, smooth2);
              }

              /// <summary>
              /// Enter the description of your new custom indicator here
              /// </summary>
              /// <returns></returns>
              public MomentumIndicator MomentumIndicator(Data.IDataSeries input, int length, int smooth1, int smooth2)
              {
              checkMomentumIndicator.Length = length;
              length = checkMomentumIndicator.Length;
              checkMomentumIndicator.Smooth1 = smooth1;
              smooth1 = checkMomentumIndicator.Smooth1;
              checkMomentumIndicator.Smooth2 = smooth2;
              smooth2 = checkMomentumIndicator.Smooth2;

              if (cacheMomentumIndicator != null)
              for (int idx = 0; idx < cacheMomentumIndicator.Length; idx++)
              if (cacheMomentumIndicator[idx].Length == length && cacheMomentumIndicator[idx].Smooth1 == smooth1 && cacheMomentumIndicator[idx].Smooth2 == smooth2 && cacheMomentumIndicator[idx].EqualsInput(input))
              return cacheMomentumIndicator[idx];

              MomentumIndicator indicator = new MomentumIndicator();
              indicator.BarsRequired = BarsRequired;
              indicator.CalculateOnBarClose = CalculateOnBarClose;
              indicator.Input = input;
              indicator.Length = length;
              indicator.Smooth1 = smooth1;
              indicator.Smooth2 = smooth2;
              indicator.SetUp();

              MomentumIndicator[] tmp = new MomentumIndicator[cacheMomentumIndicator == null ? 1 : cacheMomentumIndicator.Length + 1];
              if (cacheMomentumIndicator != null)
              cacheMomentumIndicator.CopyTo(tmp, 0);
              tmp[tmp.Length - 1] = indicator;
              cacheMomentumIndicator = tmp;
              Indicators.Add(indicator);

              return indicator;
              }

              }
              }

              // This namespace holds all market analyzer column definitions and is required. Do not change it.
              namespace NinjaTrader.MarketAnalyzer
              {
              public partial class Column : ColumnBase
              {
              /// <summary>
              /// Enter the description of your new custom indicator here
              /// </summary>
              /// <returns></returns>
              [Gui.Design.WizardCondition("Indicator")]
              public Indicator.MomentumIndicator MomentumIndicator(int length, int smooth1, int smooth2)
              {
              return _indicator.MomentumIndicator(Input, length, smooth1, smooth2);
              }

              /// <summary>
              /// Enter the description of your new custom indicator here
              /// </summary>
              /// <returns></returns>
              public Indicator.MomentumIndicator MomentumIndicator(Data.IDataSeries input, int length, int smooth1, int smooth2)
              {
              return _indicator.MomentumIndicator(input, length, smooth1, smooth2);
              }

              }
              }

              // This namespace holds all strategies and is required. Do not change it.
              namespace NinjaTrader.Strategy
              {
              public partial class Strategy : StrategyBase
              {
              /// <summary>
              /// Enter the description of your new custom indicator here
              /// </summary>
              /// <returns></returns>
              [Gui.Design.WizardCondition("Indicator")]
              public Indicator.MomentumIndicator MomentumIndicator(int length, int smooth1, int smooth2)
              {
              return _indicator.MomentumIndicator(Input, length, smooth1, smooth2);
              }

              /// <summary>
              /// Enter the description of your new custom indicator here
              /// </summary>
              /// <returns></returns>
              public Indicator.MomentumIndicator MomentumIndicator(Data.IDataSeries input, int length, int smooth1, int smooth2)
              {
              if (InInitialize && input == null)
              throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");

              return _indicator.MomentumIndicator(input, length, smooth1, smooth2);
              }

              }
              }
              #endregion
              [/code]
              Last edited by fudge; 06-23-2009, 05:59 PM.

              Comment


                #8
                Welcome to the forum. What you are looking for appears to be William Blau's Stochastic Momentum Index. If you'd just described what you wanted and posted the entire TS EL code, I am sure some one would have recognized it earlier and gave you the answer.

                This indicator is available for NT here:


                Last edited by thrunner; 06-23-2009, 10:33 PM.

                Comment


                  #9
                  <Bump>

                  90% agree. I don't know about allocating resources to teach others about how C#/NT correlates to other languages, as that would be extremely resource intensive. It would be nice if there was a "wiki" which was devoted to each language. So you go to the wiki and it would have a list of functions for say EasyLanguage and the NT version of that basic function might be there. Multiple users could post their version of code and it would get better over time. I just posted FracPortion() somewhere lately (nothing fancy or difficult, but for me it was a pretty big win ;-0 )

                  Ideally, there should be a wiki that we could post to. As more coders look at the code, it would continue to improve. Ideally, over time, who knows, maybe it could be converted to a .dll and you could use the same function names in your code and then have minor changes to make.

                  Also, google Joel Raymont, he wrote an EL to NT translator. He offered to sell it to NT, but they didn't bite. I thought it would be smart for them to license his software and then provide this as a feature in their software or via their website. So you would come to the website, paste your EL code, and it would spit back the NT/C# version for you to start with.

                  Made no sense to me as to why they didn't license it or work with Joel.

                  I understand they are not in the business of teaching C#, but more examples and case scenarios showing how to using C# as it relates to NT would be helpful.

                  I remember going to the TradeStation classes in Chicago and after I left I was able to do a lot of things I was struggling with. The problem with Tradestation is that it is built on top of old platform and of course you are "stuck" using them as your broker (for the most part unless you want to add a layer of potential issues to your strategy).

                  Anyway, this might be something that the users need to do for themselves, NT has kind of provided a good start, but more would be helpful. One day at a time. Patience.

                  Originally posted by boboinuk View Post
                  I think the guys behind ninjatrader should review their business model. If they concentrate on showing off what the software can do....as they do now, they will do just fine. If in addition they put in some effort to enable users make full use of the software's potential, they they will surpass whatever projections they have (IMHO). Most persons who like Nijatrader are held back by the lack of interest shown by the owners to simplify the coding learning process for traders; especially for those coming from other platforms.
                  For example, Tradestation and Metaquotes are very much older and more popular than Ninjatrader.....so quite a number of those wishing to use ninjatrader have some tools developed on these older platforms. What a help it will be if Ninjatrader guys made some effort like if they had a section for teaching the relationship between it's language and the others!
                  Some form of tutorial forum where whoever wishes can be encouraged to organise lessons for newbie coders will go a long way.......see what coders guru and others have done for MT4.
                  Cheers all.

                  Comment


                    #10
                    int Value1 = 100 * ( XAverage( XAverage( Close - (.5 * ( Highest( High, Length ) + Lowest( Low, Length ) ) ), Smooth1), Smooth2) / (.5 * XAverage( XAverage( Highest( High, Length )- Lowest( Low, Length ), Smooth1 ), Smooth2 ) ) ) ;

                    should translate to:

                    MDSnumerator.Set(Close[0]-(.5*(MAX(High,Length[0])
                    [0]+MIN(Low,Length[0])[0]);

                    MDSdenominator.Set(MAX(High,Length)[0]-MIN(Low,Length)[0]);

                    int value1 = 100*EMA(EMA(MDSnumerator,Smooth1),Smooth2)[0]/EMA(EMA(MDSdenominator,Smooth1),Smooth2);

                    i just wrote this before i realized that thrunner posted the code

                    fudge: note the similarity of the TS and C#
                    the key difference is that you can't add two dataseries (or subtract,mult...etc) the way you do in TS, since the EMA's can only be applied to a dataseries you must create one for them.
                    (if the dataseries class had overloaded the basic arithmetic (+,- and maybe * as well) they'd look almost identical (although that can open its own can of worms when dealing with different sized dataseries instances)

                    Comment


                      #11
                      Originally posted by r2kTrader View Post
                      <Bump>

                      ...The problem with Tradestation is that it is built on top of old platform ...
                      i believe EL was based on pascal

                      Comment


                        #12
                        Excellent post r2kTrader, worthy of repeating!

                        Originally posted by r2kTrader View Post
                        <Bump>

                        90% agree. I don't know about allocating resources to teach others about how C#/NT correlates to other languages, as that would be extremely resource intensive. It would be nice if there was a "wiki" which was devoted to each language. So you go to the wiki and it would have a list of functions for say EasyLanguage and the NT version of that basic function might be there. Multiple users could post their version of code and it would get better over time. I just posted FracPortion() somewhere lately (nothing fancy or difficult, but for me it was a pretty big win ;-0 )

                        Ideally, there should be a wiki that we could post to. As more coders look at the code, it would continue to improve. Ideally, over time, who knows, maybe it could be converted to a .dll and you could use the same function names in your code and then have minor changes to make.

                        Also, google Joel Raymont, he wrote an EL to NT translator. He offered to sell it to NT, but they didn't bite. I thought it would be smart for them to license his software and then provide this as a feature in their software or via their website. So you would come to the website, paste your EL code, and it would spit back the NT/C# version for you to start with.

                        Made no sense to me as to why they didn't license it or work with Joel.

                        I understand they are not in the business of teaching C#, but more examples and case scenarios showing how to using C# as it relates to NT would be helpful.

                        I remember going to the TradeStation classes in Chicago and after I left I was able to do a lot of things I was struggling with. The problem with Tradestation is that it is built on top of old platform and of course you are "stuck" using them as your broker (for the most part unless you want to add a layer of potential issues to your strategy).

                        Anyway, this might be something that the users need to do for themselves, NT has kind of provided a good start, but more would be helpful. One day at a time. Patience.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Brevo, Today, 01:45 AM
                        0 responses
                        2 views
                        0 likes
                        Last Post Brevo
                        by Brevo
                         
                        Started by aussugardefender, Today, 01:07 AM
                        0 responses
                        3 views
                        0 likes
                        Last Post aussugardefender  
                        Started by pvincent, 06-23-2022, 12:53 PM
                        14 responses
                        238 views
                        0 likes
                        Last Post Nyman
                        by Nyman
                         
                        Started by TraderG23, 12-08-2023, 07:56 AM
                        9 responses
                        384 views
                        1 like
                        Last Post Gavini
                        by Gavini
                         
                        Started by oviejo, Today, 12:28 AM
                        0 responses
                        5 views
                        0 likes
                        Last Post oviejo
                        by oviejo
                         
                        Working...
                        X