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

Example of how to convert MT4 indicators to NT

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

    Example of how to convert MT4 indicators to NT

    MQL indicators are based on c so they are very easy to convert to c# in most cases. However one thing which is confusing is the array indexing.

    This is because in MQL4 an array can be either a normal array or an 'indicator buffer' and they are both declared as a standard array.

    ie if you have this:

    double array0[];
    double array1[];

    int init() {
    IndicatorBuffers(1);
    SetIndexBuffer(0, array1);
    }

    Then array0 is a normal array, ie forward indexed, array0[0] is the oldest value

    However because array1 is set as a buffer MT4 performs some behind the scenes changes to make it behave like NT dataSeries, ie reverse indexed, array1[0] is the most recent value

    Another thing you will often see in MT4 indicators is BarsCounted, that is just a counter for how many bars the indicator has processed so it is equivalent to CurrentBar in NT.

    See the attached example for more info
    Attached Files

    #2
    Great post!

    Perhaps this could be a good thread for questions/ free general discussion on converting MetaTrader to NinjaScript.

    I'll take a look, and if I can remember any MT indicators I converted to NT I'll post both the original and converted code here for comparison...

    Comment


      #3
      Thanx sefrat,

      at my first conversions i looked in mt4 tutorials / api from to understand some thinks (for example with array init ...)

      A good starting point is here http://www.forexmt4.com/_MT4_Tutorials/

      Nice day

      Comment


        #4
        hi, can you help me to convert this MT4 indicator to Ninjatrader indicator ?
        it is a simple Stoch of RSI, named DTosch. the available StochRSI in NT is not what i am looking for... please help..

        thank you...
        Attached Files

        Comment


          #5
          I am trying to covert the Mq4 to C# (NT) using http://www.code2code.net/
          I really don't know how to do it.. perhaps this might help you to convert my request ... Hope I don't make a joke on my self
          Attached Files

          Comment


            #6
            kissaki,

            NinjaTrader files need to be wrapped with NinjaTrader code. Suggest you start off with the Indicator Wizard to generate the wrappers necessary.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              The language coversion from MQL4 to C# is easy. However, the programming and object model are completely different. Hence if someonce has plans to migrate an indicator you would be better off reimplementing it from scratch. You might reuse the indicator logic if this is not too tightly coupled with the MT4 api.

              Comment


                #8
                DTOSC NT Indicator

                I someone still need it i did it based on code form DTOSC.TXT
                Attached Files

                Comment


                  #9
                  trackerman1, welcome to our forums and thanks for sharing it. Perhaps you want to export the final file as zip from NT so it could be easier to include / set up?
                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by trackerman1 View Post
                    I someone still need it i did it based on code form DTOSC.TXT
                    This is a StochasticRSI with two signal lines (simple moving averages) added.

                    The code can be improved in two ways:

                    (1) MAX and MIN are resource hogs. When you set this indicator to COBC = false, it will create a heavy CPU load. Better change lines 52 and 53

                    Code:
                    double LLV = MIN(CurRSI_DS, periodStoch)[0];
                    double HHV = MAX(CurRSI_DS, periodStoch)[0];
                    to

                    Code:
                    double LLV;
                    double HHV;
                    if(FirstTickOfBar)
                    {
                         double LLV = MIN(CurRSI_DS, periodStoch)[0];
                         double HHV = MAX(CurRSI_DS, periodStoch)[0];
                    }
                    else
                    {
                          LLV = Math.Min(LLV, Low[0]);
                          LLH = Math.Max(HHV, High[0]);
                    }
                    2. In line 55 you check a double for zero after an arithmetic calculation. This should never be done. You could replace

                    Code:
                    if ((HHV-LLV)!=0)
                    with

                    Code:
                    if (Math.Abs(HHV-LLV) < 0.000000000001)
                    Otherwise I have published an open source StochasticRSI with an added signal line a month ago. It can be found here:

                    The best futures trading community on the planet: futures trading, market news, trading charts, trading platforms, trading strategies


                    The indicator has two plots and works in a similar fashion as the standard Stochatics indicator. Both plots use exponential smoothing (EMA).

                    First plot: When the smoothing period is set to 1, it displays the raw StochRSI, otherwise it is smoothed with the smoothing period.

                    Second plot: The second plot is a slower moving average of the StochRSI.
                    Attached Files

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by jeronymite, 04-12-2024, 04:26 PM
                    3 responses
                    40 views
                    0 likes
                    Last Post jeronymite  
                    Started by bill2023, Today, 08:51 AM
                    2 responses
                    16 views
                    0 likes
                    Last Post bill2023  
                    Started by sidlercom80, 10-28-2023, 08:49 AM
                    167 responses
                    2,260 views
                    0 likes
                    Last Post jeronymite  
                    Started by warreng86, 11-10-2020, 02:04 PM
                    7 responses
                    1,362 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Started by Perr0Grande, Today, 08:16 PM
                    0 responses
                    5 views
                    0 likes
                    Last Post Perr0Grande  
                    Working...
                    X