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

Tick strategy

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

    Tick strategy

    Hey guys
    I'm trying to make my first strategy. The main idea is current tick is higher than previous and previous is higher than tick before this. But but it doesn't work when I use Strategy Analyzer. The is no trades.

    And some questions: For this strategy should I use in parameters window Type: Ticks, Value: 1, Min. bars required: 3, right? Stoploss and profittarget, is this value in ticks?

    Code:
            protected override void Initialize()
            {
                CalculateOnBarClose = false;
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                if (Close[CurrentBar] <  Close[CurrentBar-1])
                    return;
                if ((Close[CurrentBar] >  Close[CurrentBar-1]) && (Close[CurrentBar-1] > Close[CurrentBar-2]))
                {
                    EnterLong();
                }
    
            }





    #2
    Hello Leeroy_Jenkins,

    I would expect this strategy to have an indexing error due to the Close[CurrentBar-1] without any check that CurrenBar is greater than 1.

    Below is a link to a forum post that describes an index error.
    Hello ninjatrader team I have looked at all the documentation published about it and I can not find a solution. My intention is to extract a series of data


    Do you see any errors appearing when running the script in the Strategy Analyzer?

    Are you connected for historical data with a provider that supports the data type you are using for the backtest?

    On the Chart display of the Strategy Analyzer do you see bars of data appearing on the chart?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello Leeroy_Jenkins,

      I would expect this strategy to have an indexing error due to the Close[CurrentBar-1] without any check that CurrenBar is greater than 1.

      Below is a link to a forum post that describes an index error.
      Hello ninjatrader team I have looked at all the documentation published about it and I can not find a solution. My intention is to extract a series of data


      Do you see any errors appearing when running the script in the Strategy Analyzer?

      Are you connected for historical data with a provider that supports the data type you are using for the backtest?

      On the Chart display of the Strategy Analyzer do you see bars of data appearing on the chart?
      Where I can find error records? After testing I don't have any warnings about errors.

      On the Chart I can see ticks.

      I use Continuum (demo) and Market Replay Data.

      Comment


        #4
        Originally posted by Leeroy_Jenkins View Post
        I'm trying to make my first strategy.
        Welcome to the forums!

        By the look of your code (and your subject line), I'm going to guess that you might benefit from some basics.

        Why?
        Because no one ever uses "Close[CurrentBar]" in their code.

        Why?
        Because CurrentBar isn't really an index value, it is a counter value telling you how many bars the chart
        contains.

        Index values 'x' that you use inside the brackets, like "Close[x]" are called 'BarsAgo' indexes. These values
        are backwards in that 0 refers to the most recently closed bar, 1 means the next most recently closed
        bar, index value 2 is the bar just before that, etc.

        Summary:
        CurrentBars is a counter, and is always increasing by 1 for each new bar added to the chart. This value is
        almost never useful as a BarsAgo index value -- since using Close[CurrentBar] refers to the first bar of
        the chart, which could be many days and thousands of bars ago. We are usually interested in the last bar
        on the chart (which are usually visible on the right side of your chart) and is considered the most recently
        closed bar (other than the real-time active bar under development) and at the time upon which it is the
        last closed bar it is referenced using BarsAgo index value of 0 -- after the next bar closes these BarsAgo
        index values shift by 1, and this same bar is now referenced using BarsAgo index of 1, then 2, 3, 4, etc.
        The 0 index value is always being "moved" to the right to reference the most recently closed bar, so
        everything else "to the left" gets incremented by 1 to make room for the new bar at BarsAgo index 0.

        Study this:
        https://ninjatrader.com/support/help...rice_data2.htm

        Last edited by bltdavid; 01-22-2019, 06:04 PM. Reason: One link is enough

        Comment


          #5
          Originally posted by bltdavid View Post
          Thanks you very much. It works.

          But my profit target doesn't work. All trades have Exit name "Exit on close".
          Last edited by Leeroy_Jenkins; 01-24-2019, 04:54 AM. Reason: profit target problem

          Comment


            #6
            I find out that Strategy master might doesn't work properly with profit/stop loss so I used

            Code:
            SetStopLoss(CalculationMode.Ticks, 1);
            SetProfitTarget(CalculationMode.Ticks, 3);
            and it works fine.

            Thanks for helping. Btw this strategy is horrible
            Last edited by Leeroy_Jenkins; 01-24-2019, 05:17 AM. Reason: solved problem

            Comment


              #7
              Hello Leeroy_Jenkins,

              Just something to keep in mind, a tick 1 stop loss is very very close to the entry price. In a fast moving market when live trading there can be slippage and when the order is received by the exchange it could possibly end up on the wrong side and be rejected.

              Below is a link to the help guide on the Close series which uses barsAgo values for the indexes.


              As well as a link to a forum post with tips about getting started with NinjaScript.


              bltdavid, thank you for your helpful insight.
              Chelsea B.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Shansen, 08-30-2019, 10:18 PM
              25 responses
              949 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Started by JonesJoker, 04-22-2024, 12:23 PM
              8 responses
              41 views
              0 likes
              Last Post JonesJoker  
              Started by timko, Today, 06:45 AM
              0 responses
              3 views
              0 likes
              Last Post timko
              by timko
               
              Started by Waxavi, 04-19-2024, 02:10 AM
              2 responses
              39 views
              0 likes
              Last Post poeds
              by poeds
               
              Started by chbruno, Yesterday, 04:10 PM
              1 response
              44 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Working...
              X