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

Fixing a value like a double or int

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

    Fixing a value like a double or int

    Hi,

    I have a strategy that i want to create a stop loss for. The stop loss should be created by looking at an indicator at the entry time, and then fixing this value.

    I use

    double StopPts = Bollinger(BarsArray[0],StopRatio, BollDays).Upper[0]

    i need the [0] to always represent the entry bar. As you see i use bars array. I enter on 5min data and exit on 1min.

    I've tried
    double StopPts = Bollinger(BarsArray[0],StopRatio, BollDays).Upper[BarssinceEntry()]

    It compiles, but i get a multi time frame error

    **NT** Error on calling 'OnBarUpdate' method for strategy 'BollRSIStopRatio/5505b53c30d04cf986f58b2788a7129c': You must use the overload that has a 'BarsInProgress' parameter when calling the BarsSinceEntry() method in the context of a multi-time frame and instrument strategy.


    I need to either fix the BarsSinceEntry, or know how to "Special Paste" (I'm more an excel user :-P) the StopPts so it stays put for the duration of the trade.

    Cheers

    #2
    Hello Aussiemike,

    Thank you for your post.

    You will have to use the following syntax for the BarsSinceEntry() method as you have multiple time frames and/or instruments in your strategy:
    Code:
    [I]BarsSinceEntry(int barsInProgressIndex, string signalName, int entriesAgo)[/I]

    Please let me know if you have any questions.

    Comment


      #3
      Hi Patrick,

      Thanks. I have it running now, but unfortunately the value is still changing.

      double StopPts = Bollinger(BarsArray[0],StopRatio, BollDays).Upper[BarsSinceEntry(0,"",0)];

      Output window...
      18/12/2012 17:45:00
      Entry ************************StopPts :1429.22585027069
      18/12/2012 17:45:00
      Close[0]: 1442.5
      TradePts: -0.25
      StopPts :1439.25102993419 ???This is different value???
      Math.Abs(TradePts): 0.25
      18/12/2012 17:46:00
      Close[0]: 1442
      TradePts: 0.25
      StopPts :1439.25102993419
      Math.Abs(TradePts): 0.25
      18/12/2012 17:47:00
      Close[0]: 1441.5
      TradePts: 0.75
      StopPts :1439.25102993419
      Math.Abs(TradePts): 0.75
      18/12/2012 17:48:00
      Close[0]: 1441.25
      TradePts: 1
      StopPts :1439.25102993419
      Math.Abs(TradePts): 1
      18/12/2012 17:49:00
      Close[0]: 1441.75
      TradePts: 0.5
      StopPts :1439.25102993419
      Math.Abs(TradePts): 0.5
      18/12/2012 17:50:00
      Close[0]: 1442
      TradePts: 0.25
      StopPts :1439.96691878351 ???Again diff value with new 5min bar???


      Cheers

      Comment


        #4
        Hello Aussiemike,

        Thank you for you patience.

        Will the Stop Points be the difference in ticks between the Close and the Bollinger or the Entry Price and the Bollinger?

        Comment


          #5
          Patrick,

          The stop will be between 2 boll lines, but this is a simple minus equation. I need to stop the bollingers from updating on the next bar.

          Cheers

          Comment


            #6
            Ok i have something

            My condition for entry is met on the 5min bar that starts at 17:40 and ends 17:45 i use XXX.Last So the entry is on 5min granularity. I dont really enter until 17:46 the start of the next bar. for 17:45-17:49 it is using the 17:45 bar that gave the conditions to enter, but after that it is using the actual bar entered. After the first change at 17:50 the value stays constant.

            Still causing me issues.

            This output relates to the attached picture. I'm just referencing the one boll band as it makes it easier to look at the level rather than the points when using the chart dialogue box

            Entry ************************StopPts :1429.64234683461
            18/12/2012 17:45:00
            Close[0]: 1442.5
            TradePts: -0.25
            StopPts :1440.18011632986
            Math.Abs(TradePts): 0.25
            18/12/2012 17:46:00
            Close[0]: 1442
            TradePts: 0.25
            StopPts :1440.18011632986
            Math.Abs(TradePts): 0.25
            18/12/2012 17:47:00
            Close[0]: 1441.5
            TradePts: 0.75
            StopPts :1440.18011632986
            Math.Abs(TradePts): 0.75
            18/12/2012 17:48:00
            Close[0]: 1441.25
            TradePts: 1
            StopPts :1440.18011632986
            Math.Abs(TradePts): 1
            18/12/2012 17:49:00
            Close[0]: 1441.75
            TradePts: 0.5
            StopPts :1440.18011632986
            Math.Abs(TradePts): 0.5
            18/12/2012 17:50:00
            Close[0]: 1442
            TradePts: 0.25
            StopPts :1441.05752103241
            Math.Abs(TradePts): 0.25
            18/12/2012 17:51:00
            Close[0]: 1442
            TradePts: 0.25
            StopPts :1441.05752103241
            Math.Abs(TradePts): 0.25
            18/12/2012 17:52:00
            Close[0]: 1441.25
            TradePts: 1
            StopPts :1441.05752103241
            Math.Abs(TradePts): 1
            18/12/2012 17:53:00
            Close[0]: 1441.25
            TradePts: 1
            StopPts :1441.05752103241
            Math.Abs(TradePts): 1
            18/12/2012 17:54:00
            Close[0]: 1440.75
            TradePts: 1.5
            StopPts :1441.05752103241
            Math.Abs(TradePts): 1.5
            18/12/2012 17:55:00
            Close[0]: 1441.5
            TradePts: 0.75
            StopPts :1441.05752103241
            Math.Abs(TradePts): 0.75
            18/12/2012 17:56:00
            Close[0]: 1441
            TradePts: 1.25
            StopPts :1441.05752103241
            Math.Abs(TradePts): 1.25
            18/12/2012 17:57:00
            Close[0]: 1441
            TradePts: 1.25
            StopPts :1441.05752103241
            Math.Abs(TradePts): 1.25
            18/12/2012 17:58:00
            Close[0]: 1441.5
            TradePts: 0.75
            StopPts :1441.05752103241
            Math.Abs(TradePts): 0.75
            18/12/2012 17:59:00
            Close[0]: 1441.75
            TradePts: 0.5
            StopPts :1441.05752103241
            Math.Abs(TradePts): 0.5
            18/12/2012 18:00:00
            Close[0]: 1441.5
            TradePts: 0.75
            StopPts :1441.05752103241
            Math.Abs(TradePts): 0.75
            18/12/2012 18:01:00
            Close[0]: 1441
            TradePts: 1.25
            StopPts :1441.05752103241
            Math.Abs(TradePts): 1.25
            Attached Files

            Comment


              #7
              Hello Aussiemike,

              Thank you for your response.

              Please set CalculateOnBarClose to False and advise if this resolves the matter.

              For information on CalculateOnBarClose please visit the following link: http://www.ninjatrader.com/support/h...onbarclose.htm

              I look forward to your response.

              Comment


                #8
                I'm backtesting so i believe COBC = true is only way?

                I changed it anyway, and no result.

                Cheers

                Comment


                  #9
                  Hello Aussiemike,

                  Thank you for your response.

                  That is correct, Backtests will always be CalculateOnBarClose = true.

                  Could you perhaps provide a 'toy' sample of your code with the entry and exit calculations that I may test on my end? If so, please attach to your response.

                  If you prefer you can always sent the 'toy' sample to support[at]ninjatrader[dot]com with 'ATTN: Patrick' in the subject line and a reference to this thread in the body of the e-mail: http://www.ninjatrader.com/support/f...ad.php?t=54784

                  I look forward to your response.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Tin34, Today, 03:30 AM
                  2 responses
                  15 views
                  0 likes
                  Last Post Tin34
                  by Tin34
                   
                  Started by sastrades, Yesterday, 09:59 AM
                  2 responses
                  29 views
                  0 likes
                  Last Post brucerobinson  
                  Started by ETFVoyageur, Today, 12:52 AM
                  1 response
                  15 views
                  0 likes
                  Last Post Leeroy_Jenkins  
                  Started by lollers, Today, 03:26 AM
                  0 responses
                  10 views
                  0 likes
                  Last Post lollers
                  by lollers
                   
                  Started by aliyahany, Today, 03:16 AM
                  0 responses
                  2 views
                  0 likes
                  Last Post aliyahany  
                  Working...
                  X