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

fix a value

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

    fix a value

    Good evening,
    I should create a variable that stops me a value, for example, Low [4] and then calculate the stopLoss:

    OnBarUpdate ()

    if ((Close [0]> Close [1])

    variable1 = Low [4]

    In this way, the value does not stop.
    How can I do?
    Thank you.
    Roberto

    #2
    Hello,

    Where are you setting your stop loss? Is this in Initialize() or some where in OnBarUpdate()?

    If you wish to dynamically assign a StopLoss value, this would have to be in a method such as OnBarUpdate that is called more frequently. Initialize() is only called once when the strategy is started.

    You can also set your StopLoss in OnOrderUpdate() or OnExecution() to submit your protective orders. Please see our Reference Sample on this topic for more information:

    The OnOrderUpdate() and OnExecution() methods are reserved for experienced programmers. Instead of using Set() methods to submit stop-loss and profit target orders, you can submit and update them manually through the use of IOrder and IExecution objects in the OnOrderUpdate() and OnExecution() methods. The OnOrderUpdate()
    MatthewNinjaTrader Product Management

    Comment


      #3
      Sorry, I was not clear in the request.
      I write using Google Traslation.
      I want to fix the value of a price assigned to a Variables in OnBarUpdate (). The price assigned I need then for use in another part of the code for deffinere the exit.
      For example:

      # region Positions
      private void GoLong ()
      {
      SetStopLoss (CalculationMode.Price, Variable0 - (1 TickSize *)));
      }
      # endregion


      protected override void OnBarUpdate ()



      if (Close [0]> Close [1])
      Variable0 = Low [1]; / / Low [1] = 8 (for example)

      if (...........)
      GoLong ();

      I want to set the price 8 to use then in the region GoLong position (). SetStopLoss always take the value of Low [1] at that moment, instead of the value 8 fixed. How can I do to fix the value 8 ?

      Ciao
      Roberto

      Comment


        #4
        Hello,

        If you would just want a fixed value of 8 from your entry price, you would use the CalculationMode.Ticks and use a value of 8:

        SetStopLoss (CalculationMode.Ticks, 8);

        If you wanted it to be 8 ticks from the Low[1], you could use

        SetStopLoss(CalculationMode.Ticks, Low[1] - (8 * TickSize));
        MatthewNinjaTrader Product Management

        Comment


          #5
          set a value and do not update

          Sorry Matthew,
          I can not understand me.
          I want that the value of the variable at the time the input is fixed with the value, for example of the Low [1]. Then later, I want to recall the value of the variable to determine the exit.
          If I do:

          # Region Positions
          private void GoLong ()

          {
          SetStopLoss (CalculationMode.Price, Variable0 - (1 TickSize *)));
          }
          # endregion


          protected override void OnBarUpdate ()



          if (Close [0]> Close [1])
          Variable0 = Low [1]; / / assign to variable0 the value of Low [1], at this time

          if (...........)
          GoLong ();

          In this way, when the booster variabile0 some of the bars later, does not take the value previously assigned to the Variable0, but the Low [1] of the moment.
          If low [1] for example was 8 (30 bars before), when calling the variable, the code does not take 8 but the value of Low [1] at the time.
          How do I fix the value and do not update?
          Thank you.
          Hello.
          Roberto

          Comment


            #6
            Hello,

            Rather than referencing Low[1], you would need to locate the exact Low[barsAgo] value you wish to reference.

            You can do this by creating a loop and storing that barsAgo value.

            Please see our Reference Sample on Referencing the Correct Bar:

            MatthewNinjaTrader Product Management

            Comment


              #7
              Thanks !
              Roberto

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by funk10101, Today, 09:43 PM
              0 responses
              6 views
              0 likes
              Last Post funk10101  
              Started by pkefal, 04-11-2024, 07:39 AM
              11 responses
              37 views
              0 likes
              Last Post jeronymite  
              Started by bill2023, Yesterday, 08:51 AM
              8 responses
              44 views
              0 likes
              Last Post bill2023  
              Started by yertle, Today, 08:38 AM
              6 responses
              26 views
              0 likes
              Last Post ryjoga
              by ryjoga
               
              Started by algospoke, Yesterday, 06:40 PM
              2 responses
              24 views
              0 likes
              Last Post algospoke  
              Working...
              X