Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Scaling into a position

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

    Scaling into a position

    Hey there,

    I've done a bunch of different searches but can't seem to find a simple example of scaling in based on an indicator. Imagine a bounded indicator from 0 to 100 - I want to scale in at different levels of the indicator. Can someone point me to a simple example of something like this, or just an example of scaling in based on anything (other than the automated scaling that comes from allowing multiple entries)?

    Thanks in advance,

    Damian

    #2
    Damian,

    All you need to do is bump up the EntriesPerDirection value then just scale in how you want.

    You may do something like checking cross overs.

    Code:
    if (CrossAbove(SMA(20), 100, 1))
       EnterLong();
    if (CrossAbove(SMA(20), 150, 1))
       EnterLong();
    You entered long when SMA crosses above 100. You scale in a second time when SMA crosses above 150.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the quick follow-up - not quite what I want to do but close.

      What I want to do is go long, say 25% of the total portfolio when it is at one level, go long 50% if it is at a lower level, 75%, etc.

      The issue I see is that let's say the indicator jumps from not buying to buying in the extreme - in this case, I'd want to go long 100%.

      Would this method still work? Would I just see 3 entries?

      Comment


        #4
        Yes. You will see 3.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Terrific - thanks for the response - how do I define using the whole account vs. the default value for position size?

          Comment


            #6
            When you go EnterLong/ExitLong just punch in the quantity you want to use.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Josh View Post
              When you go EnterLong/ExitLong just punch in the quantity you want to use.
              Ok, but if I want to use a % of the total portfolio/account?

              Comment


                #8
                You need to calculate it yourself and then pass in the quantity.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_Josh View Post
                  You need to calculate it yourself and then pass in the quantity.
                  Is there a section of the manual I can look at that shows me how to access the account object to get the total portfolio amount? I've read the account section in the help file and I couldn't find any mention of it. What I want to do is pretty simple:

                  myPosition = Total account value * 0.25

                  Thanks!

                  Comment


                    #10
                    You set AccountSize to what you want in Initialize() and then that is your amount to work with.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_Josh View Post
                      You set AccountSize to what you want in Initialize() and then that is your amount to work with.
                      Ok - so in Initialize(), I put:

                      AccountSize = 10000;

                      Now, let's say that I want to create another variable that holds 25% of whatever the current AccountSize is - remembering, of course, that this should change (go up or down) when the system is in process.

                      I was assuming I'd put something like this OnBarUpdate - but it doesn't work.

                      Buyshares = AccountSize * 0.25;

                      Thoughts?

                      Comment


                        #12
                        What part doesn't work? AccountSize does go up and down as the system trades. As you get realized PnL it gets added/removed from AccountSize.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_Josh View Post
                          What part doesn't work? AccountSize does go up and down as the system trades. As you get realized PnL it gets added/removed from AccountSize.
                          Yeah - I get that.

                          Here's the code I've got so far:

                          protected override void OnBarUpdate()
                          {
                          double buyShares = (AccountSize * 0.25)/Close[0];
                          // Condition set 1
                          if (somecondition)
                          {
                          buyShares = (AccountSize * 0.25)/Close[0];

                          Now what I thought this would do is take 25% of the account value and divide it by the close of the instrument being backtested. But when I backtest this, starting with AccountSize initialized to $10,000, I get every trade as 1 share - as opposed to the default which trades the entire AccountSize amount.

                          Thoughts appreciated!

                          Comment


                            #14
                            You not only need to have calculated out the value you need to actually pass that along into your Enter() methods.

                            When you pass it along you can't pass a double either. You would need to pass it along as an int. You can do this by casting it to an int.

                            EnterLong((int) buyShares);
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #15
                              Originally posted by NinjaTrader_Josh View Post
                              You not only need to have calculated out the value you need to actually pass that along into your Enter() methods.

                              When you pass it along you can't pass a double either. You would need to pass it along as an int. You can do this by casting it to an int.

                              EnterLong((int) buyShares);
                              Ok that got it - really appreciate the help on this - I know it took a lot of back and forth.

                              Best,

                              Damian

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              648 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              369 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              108 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              572 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              573 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X