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 size for Initialize()

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

    tick size for Initialize()

    Hello! What should I use to return ticket size of instrument (futures), that could be used in Initialize().
    Example:
    SetStopLoss("Long Entry 1", CalculationMode.Ticks, MyDouble*TickSize, false);

    MyDouble=0.0123. It should be in ticks for Stop target, =123.

    Unfortunately TickSize doesn't work in Initialize().

    #2
    I have no idea if this will work, but maybe try using TickSize in OnStartUp()?

    Comment


      #3
      To all,

      Yes, TickSize should not be used in Initialize(). Unfortunately there aren't any supported work arounds available, but someone may have a solution here.
      Adam P.NinjaTrader Customer Service

      Comment


        #4
        Originally posted by Radical View Post
        I have no idea if this will work, but maybe try using TickSize in OnStartUp()?
        Please write here how I can do it? These two versions don't work, because I don't know how to assign TickSize to ts ---> ts = TickSize

        protected override void OnStartUp()
        {
        private object ts = TickSize;
        }

        protected override void OnStartUp()
        {
        ts = TickSize;
        }

        Comment


          #5
          rat-tat! rat-tat! rat-tat! Please don't leave me alone

          Comment


            #6
            Try 'double ts = TickSize;' in OnStartUp()

            Comment


              #7
              before "protected override void Initialize()" I inserted
              "protected override void OnStartUp()
              {
              double ts = TickSize;
              }
              But error "The name `ts` does not exist in the current context"
              Where should I declair `ts`? In "#region Properties"? as private double or just as double?

              Comment


                #8
                alexstox,

                Where are you using the variable ts? I suspect you would need to declare :

                private double ts;

                in the "variables" section to make it accessible by the other methods.

                A variable declared within a method like OnStartup() or OnBarUpdate() will only be accessible in OnStartup() or OnBarUpdate() respectively the way you are declaring it.

                Please let me know if I may assist further.
                Adam P.NinjaTrader Customer Service

                Comment


                  #9
                  public class LWMP : Strategy
                  {
                  #region Variables
                  private double TS = TickSize;
                  #endregion

                  error: An object reference is required for the non-static field, method, or property `NinjaTrader.Strategy.StrategyBase.TickSize.Get`


                  P.S. The problem is I can't get TickSize in Initialize(), but there are conditions that use it.
                  For example:
                  protected override void Initialize()
                  {
                  SetProfitTarget("Long Entry 1", CalculationMode.Ticks, 2*A_big/TS);
                  Last edited by alexstox; 04-18-2012, 08:11 AM.

                  Comment


                    #10
                    alexstox,

                    This is the issue : private double TS = TickSize;

                    Here :

                    Code:
                    public class LWMP : Strategy
                    {
                    #region Variables
                    private double TS = TickSize; 
                    #endregion
                    
                    //other code and methods
                    
                    }
                    The TickSize variable is only accessible in the OnBarUpdate() method, though some people seem to get it to work in OnStartup() which is unsupported currently.

                    Basically, you need to declare your variable :

                    Code:
                    public class LWMP : Strategy
                    {
                    #region Variables
                    private double TS; 
                    #endregion
                    
                    // other code and methods
                    
                    }
                    Then assign it in another method like :

                    Code:
                    private override void OnBarUpdate()
                    {
                    
                    TS = TickSize;
                    
                    //other code
                    
                    }
                    Please let me know if I may assist further.
                    Last edited by NinjaTrader_AdamP; 04-18-2012, 08:13 AM.
                    Adam P.NinjaTrader Customer Service

                    Comment


                      #11
                      The problem is I can't get TickSize in Initialize(), but there are conditions that use it.
                      For example:
                      protected override void Initialize()
                      {
                      SetProfitTarget("Long Entry 1", CalculationMode.Ticks, 2*A_big/TS);

                      When I do like you wrote - Backtest work bad, incorrect. When I just use 0.0001 instead of TS - everything is OK. So, what can you advise? How can I use TickSize in Profit and Stop targets? I need it to be divide by TickSize to get {2*0.0112/0.0001=224} ticks for targets.

                      Comment


                        #12
                        alexstox,

                        Unfortunately TickSize is not accessible in the Initialize() method.



                        Please keep in mind you can also specify a stop loss in the OnBarUpdate() method, where TickSize would be accessible, and it will apply this stop loss to your orders.



                        Please let me know if I may assist further.
                        Adam P.NinjaTrader Customer Service

                        Comment


                          #13
                          A bit off top...

                          But,how to achieve -/+ ticksize within the same condition?

                          So for Value[0][0] > Value[0][1] +/- ticksize

                          So,it would be true n ticks above OR n ticks below

                          Thanks to All

                          Comment


                            #14
                            Originally posted by outsource View Post
                            A bit off top...

                            But,how to achieve -/+ ticksize within the same condition?

                            So for Value[0][0] > Value[0][1] +/- ticksize

                            So,it would be true n ticks above OR n ticks below

                            Thanks to All
                            Don't do it in initialize??

                            Comment


                              #15
                              Originally posted by outsource View Post
                              A bit off top...

                              But,how to achieve -/+ ticksize within the same condition?

                              So for Value[0][0] > Value[0][1] +/- ticksize

                              So,it would be true n ticks above OR n ticks below

                              Thanks to All
                              By separating them.
                              Code:
                              Value[0][0] < Value[0][1] - TickSize  || Value[0][0] > Value[0][1] + TickSize

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by rtwave, 04-12-2024, 09:30 AM
                              2 responses
                              20 views
                              0 likes
                              Last Post rtwave
                              by rtwave
                               
                              Started by tsantospinto, 04-12-2024, 07:04 PM
                              5 responses
                              67 views
                              0 likes
                              Last Post tsantospinto  
                              Started by cre8able, Today, 03:20 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post cre8able  
                              Started by Fran888, 02-16-2024, 10:48 AM
                              3 responses
                              49 views
                              0 likes
                              Last Post Sam2515
                              by Sam2515
                               
                              Started by martin70, 03-24-2023, 04:58 AM
                              15 responses
                              115 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Working...
                              X