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

Strategy using several signals HelkinAshi, &Trend on 2 diff agg period, not compling

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

    Strategy using several signals HelkinAshi, &Trend on 2 diff agg period, not compling

    The following code is what I am trying to use. I am sure I have not followed some protocol.
    Helkin Ashi code works fine on its own but adding the trend code I get many errors with the Initialize it says no suitable method to overiride.
    I any one has a similar code or can help me out.

    I believe the problem area is not so much the second period. It is the Sum statement.

    I am trying to convert a thinkorswim script to Ninjascript.
    in TOS it is:
    def O1 = open( Period = agg);
    def C1 = close( Period = agg);
    def H1 = high( Period = agg);
    def L1 = low( Period = agg);
    def Adata = Sum((O1 + H1 + L1 + C1) / 4, 6) / 6;
    What I have written for Ninjascript is:
    ADATA(BarsArray[0])[0] = SUM((O1 + H1 + C1 + L1)/4,6)/6; but the error is best overloaded match has some invalid arguments and cannot convert from double to series<double>.
    If I can get past this I think I will be ok.
    Last edited by set2win; 07-23-2020, 04:41 AM.

    #2
    Hello set2win,

    Thanks for your post and welcome to the NinjaTrader forums!

    The Sum() method require a data series as the input to be summed over the specified period. Reference: https://ninjatrader.com/support/help...mation_sum.htm

    In your case you are trying to add individual double values.

    If I understand correctly you want to get the sum of the last 6 HA Closes? If so then all you need is: ADATA[0] = Sum(HACLOSE, 6)[0]



    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_PaulH View Post
      Hello set2win,

      Thanks for your post and welcome to the NinjaTrader forums!

      The Sum() method require a data series as the input to be summed over the specified period. Reference: https://ninjatrader.com/support/help...mation_sum.htm

      In your case you are trying to add individual double values.

      If I understand correctly you want to get the sum of the last 6 HA Closes? If so then all you need is: ADATA[0] = Sum(HACLOSE, 6)[0]


      Thanks the solution you provided is great. On the second aggregation of 5 min, what is the proper code for BDATA which will use an array based on the 5 min values of HACLOSE. I added:
      else if (State == State.Configure)
      {
      // Add a 5 minute Bars object - BarsInProgress index = 1
      AddDataSeries(BarsPeriodType.Minute, 5);
      }

      So the reference would be index 1
      Should I create a new series for that for HACLOSE values
      Last edited by set2win; 07-23-2020, 08:10 AM.

      Comment


        #4
        Hello set2win,

        Thanks for your reply.

        I would suggest that you simply add a 5-minute Heiken-Ashi series: https://ninjatrader.com/support/help...heikenashi.htm

        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_PaulH View Post
          Hello set2win,

          Thanks for your reply.

          I would suggest that you simply add a 5-minute Heiken-Ashi series: https://ninjatrader.com/support/help...heikenashi.htm
          Thanks again PaulH you came to the rescue once again. I have it all working with the changes you advised. And it pretty well mimics the TOS strategy as far as results are concerned, so now that I have made this progress I can look at other scripts and try to convert.
          Thanks you once again.

          Comment


            #6
            Originally posted by set2win View Post
            Thanks again PaulH you came to the rescue once again. I have it all working with the changes you advised. And it pretty well mimics the TOS strategy as far as results are concerned, so now that I have made this progress I can look at other scripts and try to convert.
            Thanks you once again.
            I couldn't get it working with the changes suggestions ... I have "AddHeikenAshi("CL 09-20", BarsPeriodType.Minute, 1, MarketDataType.Last);" instead of "AddHeikenAshi("ES 03-18", BarsPeriodType.Minute, 1, MarketDataType.Last);". Could you please share/post your working version ?

            Omololu

            Comment


              #7
              If anyone is interested. I resolved my compiling issues with the help of PaulH, many thanks. I will be testing this strategy in near future. As far as Strategy analyzer it seems to do pretty good. You can choose to TradeLong or TradeShort or both in the parameters. I found NQ 09-20 trading at 2 minute works best. Just one contract during the worst drop in the market Feb 19 to March 24 shows outstanding results. If anyone has a comment or finds problems with the strategy let me know. This is not trading advice or to be used live till you test it thoroughly. I include the code and a screenshot of the analyzer.
              Attached Files

              Comment


                #8
                Sorry but not out of the woods just yet. In trying to run the code in chart as strategy I am getting an error. Strategy 'DCHelkinA****rendLongShort': Error on calling 'OnBarUpdate' method on bar 0: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

                The code I have figured out that is giving the error is this: HAOPEN[0] = Math.Abs((O2 + C2) / 2); where O2 and C2 = Open[1] and Close[2}
                if (HACLOSE[0] > HAOPEN[0]) HASTATE = 100; else HASTATE = -100;

                If I remove this the error goes away and the strategy Enables. Any thoughts on this??

                Comment


                  #9
                  Hello set2win,

                  Thanks for your post.

                  This type error occurs when you are trying to access a data point that the script does not know about. Keep in mind that a script will process all of the historical data and starts on the very first historical bar in the data series. If your code then tries to access a previous bars ago, then an error will occur because there is no previous bar to access. The same would be true if for example on the 4th data point you try to access 5 or more bars ago.

                  Typically you would review your code and look at all of the BarsAgo [0] indexes or other references to lookback period and make sure that you prevent your code from executing until it has processed that many bars. The way to prevent your code from executing is by comparing the systems CurrentBar value to the number of bars you determine and if less then that to then "return";. In C# when it hits the "return;" it will not process any code below that so you would want your bars check to occur at the top of OnBarUpdate().

                  As you have two data series (the chart primary series and the added 5 minute series), you will need to check the current bar value on both series using CurrentBars[] where the index would point to BarsArray[0] or BarsArray[1], please see this link in the help guide: https://ninjatrader.com/support/help...urrentbars.htm
                  Paul H.NinjaTrader Customer Service

                  Comment


                    #10
                    Thanks PaulH but I eliminated the code HAOPEN and just removed that signal and it works but in strategy and market replay it is filling one bar early on the market replay compared to strategy both in Entering and exiting a position. It also occasionally fills the order twice in the same bar. I know it is just a tweak away from working as I intend it to. The strategy of course is very successful compared to the market replay and it seems to relate to the difference on the one bar.

                    Comment


                      #11
                      Hello set2win,

                      Thanks for your reply.

                      What calculate setting is the strategy running under? (Calculate.OnBarClose, Calculate.OnPriceChange, Calculate.OnEachTick)

                      Regarding entry/exit bars, are you trying to compare market replay to strategy analyzer?
                      Paul H.NinjaTrader Customer Service

                      Comment


                        #12
                        I'm using Calculate.OnBArClose and yes between strategy analzer andthe market replay with market replay going 1 bar sooner. I did add if (CurrentBar < BarsRequiredToTrade) return; And I'm not getting any double entries now.

                        Comment


                          #13
                          Hello set2win,

                          Thanks for your reply.

                          If your code has not changed much from post #7, I would suggest that you pull this part in under BarsInProgress == 0

                          H1 = High[0];
                          L1 = Low[0];
                          C1 = Close[0];
                          O1 = Open[0];

                          As it is in the open, when the 5 minute bar call OnBarUpdate() it will populate those values with the 5 minute data.


                          Paul H.NinjaTrader Customer Service

                          Comment


                            #14
                            I think this code is finally working both in Strategy Analyzer and Market Replay. I'm not entirely sure it works like it works in Thinkorswim but it does produce results.
                            I added two parameter so user can choose AGG1 which is the lower aggregation and AGG2 which is the higher and it is only going to function with a timeframe lower than or the same as the lower AGG1.
                            For example selecting 2 and 5 min intervals you should select 2 min or 1 min for your data series not 5,4, 3 or anything higher than 2.
                            Also there is an option to select Trading Long or Trade Short or both. If anyone has any ways to enhance let me know. Thanks again for help on this PaulH.
                            Attached Files

                            Comment


                              #15
                              Hello set2win,

                              Thanks for your reply.

                              By posting your strategy here you are inviting the community to share, if they find this thread.

                              If you would like to share on a broader basis, you are welcome to post this in the NT user apps of the NinjaTrader Ecosystem through this forum section: https://ninjatrader.com/support/foru...app-submission
                              Paul H.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by sidlercom80, 10-28-2023, 08:49 AM
                              170 responses
                              2,273 views
                              0 likes
                              Last Post sidlercom80  
                              Started by Irukandji, Yesterday, 02:53 AM
                              2 responses
                              17 views
                              0 likes
                              Last Post Irukandji  
                              Started by adeelshahzad, Today, 03:54 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post adeelshahzad  
                              Started by CortexZenUSA, Today, 12:53 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post CortexZenUSA  
                              Started by CortexZenUSA, Today, 12:46 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post CortexZenUSA  
                              Working...
                              X