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 small EL code to NinjaScript.

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

    Convert small EL code to NinjaScript.

    If somebody could help convert this to NinjaScript for me I will insert into remainder of code and then display as a whole to finish the conversion as there will be errors. This Bollinger is unaffected by opening gaps. Great indicator.


    if date<>date[1] then
    begin
    gap = GapCoef*(O-C[1]);
    Accum = Accum+gap;
    end;
    Last edited by Lobo; 12-17-2009, 06:26 PM. Reason: More info.

    #2
    hey lobo,

    is GapCoef a custom function? I don't see it in my TS library.

    It should to something like this

    Code:
    double gap = 0;
    double accum = 0;
    if(Time[0].Date != Time[1].Date)
    {
        gap = GapCoef(Open[0] - Close[1]);
        accum += gap;
    }
    But this assumes you have the GapCoef() function in NT.

    hope this helps.
    mrlogik
    NinjaTrader Ecosystem Vendor - Purelogik Trading

    Comment


      #3
      Hey MrLogic. GapCoef is basically an input. Can be exchanged for 1.0 for now.
      1.0*(O-C[1]); accomplishes the same thing. I will include a more detailed explaination soon. I can see this code is going to need a bit of modifying. Thanks for your help.

      Comment


        #4
        No problem.

        Good Luck
        mrlogik
        NinjaTrader Ecosystem Vendor - Purelogik Trading

        Comment


          #5
          Well, having a problem with StdDev function so I will post EL code in it's whole to save some time.

          inputs:
          Length( 19),
          NumDevsUp( 1.9),
          NumDevsDn( -1.9);

          variables:
          Avg( 0 ),
          SDev( 0 ),
          LoBand( 0 ),
          MidLine( 0 ),
          UpBand( 0 ) ;
          // gapless day transitions - John McCormick May 2008

          Vars:
          RelC(0), // Relative Close
          gap(0), // the opening gap (modified by the gap coefficient)
          GapCoef(1.0), // Gap Coefficient
          Accum(0); // The sum of all the daily gaps

          if date<>date[1] then
          begin
          gap = GapCoef*(O-C[1]);
          Accum = Accum+gap;
          end;

          RelC = C-Accum;

          // Gapless - end

          MidLine = AverageFC( RelC, Length ) + accum ;
          SDev = StandardDev( RelC, Length, 1 );

          UpBand = MidLine + NumDevsUp * SDev ;
          LoBand = MidLine + NumDevsDn * SDev ;


          Plot1( UpBand, "BolUpBand" ) ;
          Plot2( LoBand, "BolLoBand" ) ;
          Plot3( MidLine, "BolMidL" ) ;

          Comment


            #6
            Happy holidays.

            Attached.
            Attached Files
            mrlogik
            NinjaTrader Ecosystem Vendor - Purelogik Trading

            Comment


              #7
              Thanks for the effort! These gapless indicators can't be beat as far as I'm concerned. There is still something strange here though as it is preforming as though it is a normal Bollinger. I have checked the identical code that I posted with TS and works correctly there. Will look deeper into it tomorrow and let you know. Will try to post image to show what it should look like. Hope you can get some use of this indicator once it's working. Merry Christmas to you.
              Last edited by Lobo; 12-18-2009, 04:01 PM.

              Comment


                #8
                Thought I'd include a bit of an explanation supplied by the creator, John McCormick.
                I'll figure how to upload images tomorrow and you'll see the large difference it makes.

                I use a routine I call, "gapless," which avoids these problems by treating separate days in a manner similar to continuous contracts.
                This is how it works: The opening “gap” is recorded for the first bar of each trading day.

                A relative stream of OHLC's are calculated by subtracting this “gap” from the actual prices. This relative stream of OHLC’s are maintained right along side of the real OHLC’s. If the EL programmer needs to convert between the relative prices and the real price data, the sum of all the gap values is stored in the variable, “accum,” which makes the conversion simple.

                If you’re squeamish about eliminating the opening gap altogether, I’ve included a “GapCoef,” that you can set between 0.00 and 1.00 to reduce part or all of the gap as you choose. For example, set the coefficient to 0.5 to reduce the gap by half. I prefer to eliminate the gap altogether so I set the coefficient to 1.0, which eliminates 100% of the opening gap.

                Indicators, such as RSI and Stochastics, (see below examples) work fine with this relative price stream and never need to be converted back to real prices.

                If you have an indicator that needs to be displayed on the same scale as the underlying data, simply add “accum,” i.e. (indicator + accum) as the last step prior to plotting. You can see an example of this with the Bollinger Band below (code included below in Gapless.ELD).

                In order to work correctly, all manipulations (adding, averaging, etc...) should only be done with the relative data (RelO, RelH, RelL and RelC), then if the data needs to be returned to the real domain the variable "accum" is added as the last step.

                // gapless day transitions - John McCormick May 2008

                Vars:
                RelO(0), // Relative Open
                RelH(0), // Relative High
                RelL(0), // Relative low
                RelC(0), // Relative Close
                gap(0), // the opening gap (modified by the gap coefficient)
                GapCoef(1.0), // Gap Coefficient
                Accum(0); // The sum of all the daily gaps

                if date<>date[1] then
                begin
                gap = GapCoef*(O-C[1]);
                Accum = Accum+gap;
                end;

                RelO = O-Accum;
                RelC = C-Accum;
                RelH = H-Accum;
                RelL = L-Accum;

                // Gapless - end

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by ghoul, Today, 06:02 PM
                3 responses
                14 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by jeronymite, 04-12-2024, 04:26 PM
                3 responses
                44 views
                0 likes
                Last Post jeronymite  
                Started by Barry Milan, Yesterday, 10:35 PM
                7 responses
                20 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by AttiM, 02-14-2024, 05:20 PM
                10 responses
                180 views
                0 likes
                Last Post jeronymite  
                Started by DanielSanMartin, Yesterday, 02:37 PM
                2 responses
                13 views
                0 likes
                Last Post DanielSanMartin  
                Working...
                X