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

how to refer to the price of previous entry?

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

    how to refer to the price of previous entry?

    Hello,masters,

    Is there any way I can refer to "the price of previous entry buy point" by using Ninja Script Wizard?

    For example:
    I want to buy another 100 shares once the current price drop 5% "below the previous buy entry point. So I want to add a condition in the wizard which says:
    when current price< previous entry price*(1-5%)
    then buy 100 shares more

    Since I am not sure "how many bars ago" I entered the previous buy point. Is there any other way refer to the "previous entry price"?

    thanks,
    Justmake

    #2
    Unfortunately not, you can only referece the open positions' average entry price.
    RayNinjaTrader Customer Service

    Comment


      #3
      Hello,Ray,

      Thanks for reply. Is there any way for me to refer to the previous entry price in
      Ninja Script language?

      thanks,
      Justmake

      Comment


        #4
        You can save the current position's avg entry price into a temporary variable. That will grant you access to it in the future. Definitely doable with custom programming in NinjaScript.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Thanks for the answer,Josh.
          Do you offer the service of writing customized ninja script ?
          how would you charge it?
          Justmake

          Comment


            #6
            No.

            Here is a current list of available NinjaScript consultants available for contract work.

            RayNinjaTrader Customer Service

            Comment


              #7
              Let say the strategy isfilled with quantity of 2.

              When i'm trying this, see attachment..

              it doesnt work?
              Attached Files

              Comment


                #8
                Hi no111,

                Can you clarify a little on what you are intending to do?

                Position.AvgPrice will return the average price of a strategy's position.

                More info at - http://www.ninjatrader-support.com/H....html?AvgPrice
                TimNinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_Tim View Post
                  Hi no111,

                  Can you clarify a little on what you are intending to do?

                  Position.AvgPrice will return the average price of a strategy's position.

                  More info at - http://www.ninjatrader-support.com/H....html?AvgPrice
                  I want to add on the position if close[1] > close[0]

                  Comment


                    #10
                    Hi no111,

                    This can be done using the wizard as well, and the logic descrsibes....

                    "if the close of the previous bar is greater than the close of the current bar"
                    Attached Files
                    TimNinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_Tim View Post
                      Hi no111,

                      This can be done using the wizard as well, and the logic descrsibes....

                      "if the close of the previous bar is greater than the close of the current bar"
                      I know, thanks.
                      But I want that only if there is already a position of 2.
                      How do I set that.

                      My purpose is to average in..

                      Comment


                        #12
                        Hello no111,

                        This is controlled through EntriesPerDirection and EntryHandling properties. These properties can be hard coded or set when you run the strategy.

                        If you want to access the current position, you can access this in the wizard under Strategy > Current Position size.
                        Ryan M.NinjaTrader Customer Service

                        Comment


                          #13
                          Max. entries: 66.

                          When RSI is below 25; 2 long.

                          So the nextbar should be added by 3 because of: if (Position.Quantity == 2)
                          {
                          EnterLong(3, "long3");
                          }

                          But it doesn't.. what is wrong?


                          PHP Code:
                          protected override void Initialize()
                                  {
                                       
                          EntriesPerDirection 66
                                      
                          EntryHandling EntryHandling.AllEntries
                                      
                          Add(SMA(200));
                                      
                          Add(RSI(23));

                                      
                          CalculateOnBarClose true;
                                  }

                                  
                          /// <summary>
                                  /// Called on each bar update event (incoming tick)
                                  /// </summary>
                                  
                          protected override void OnBarUpdate()
                                  {

                                      
                          // Condition set 2
                                      
                          if (Close[0] > SMA(200)[0]
                                          && 
                          RSI(23).Avg[0] < 25
                                          
                          && RSI(23).Avg[1] < 25)
                                      {
                                          
                          EnterLong(2"long2");
                                      }
                                      

                                      
                          // Condition set 3
                                      
                          if (Position.Quantity == 2)
                                      {
                                          
                          EnterLong(3"long3");
                                      }

                                      
                          // Condition set 4
                                      
                          if (RSI(23).Avg[0] > 70
                                          
                          && Position.MarketPosition == MarketPosition.Long)
                                      {
                                          
                          ExitLong("exit""");
                                      }
                                  }

                                  
                          #region Properties
                                  
                          [Description("")]
                                  [
                          Category("Parameters")]
                                  public 
                          bool MyInput0
                                  
                          {
                                      
                          get { return myInput0; }
                                      
                          set myInput0 value; }
                                  }
                                  
                          #endregion
                              
                          }

                          Comment


                            #14
                            Does anyone know how to fix this?

                            Comment


                              #15
                              Hi no111,

                              If the only condition is Quantitiy==2, you could simply enter with 5 contracts initially.

                              If you're looking to add more conditions to that, start by adding Print()s to ensure your condition is being met and entered.
                              More info at - http://www.ninjatrader.com/support/f...ead.php?t=3418

                              Also, it may take another bar for it to recognize the initial contracts.

                              Check for any errors in the Log tab while running the script.
                              TimNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by elderan, Yesterday, 08:03 PM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by samish18, Yesterday, 08:57 AM
                              8 responses
                              25 views
                              0 likes
                              Last Post samish18  
                              Started by DJ888, 04-16-2024, 06:09 PM
                              3 responses
                              10 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Started by RookieTrader, Today, 07:41 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post RookieTrader  
                              Started by maybeimnotrader, Yesterday, 05:46 PM
                              1 response
                              19 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Working...
                              X