Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ATR based Position Size On Second Entry

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

    ATR based Position Size On Second Entry

    I attached a simple MA crossover strategy to help get my question across.

    Let's say I want to pyramid into a position, and have the # of shares/contracts be based on ATR for both entries - for ex. with account size of 100,000 risking 2% would be
    mySize= (100000 * (.02)/ATR(14)[0] * 2) .......EnterLong(mySize,"firstentry);....EnterLong (mySize,"second entry");

    I want to capture the ATR value at the time of the first entry, not recalculate it at the second entry since the position size will now be different, subject to the differences of the change of the ATR value.

    Can anyone point me in the right direction?
    Attached Files

    #2
    Hello,

    I haven't fully checked it but at first glance your logic appears correct.

    Instead of
    int mySize = (int) (10000 * (.02) / ATR (14)[0]);

    you could do
    int mySize = (int) (10000 * (.02) / EntryATR);

    If you did this you would also need to recalculate the mySize variable just before the first EnterLong()

    Let me know if I can be of further assistance.
    LanceNinjaTrader Customer Service

    Comment


      #3
      Do you think I could do like a mySize2 = NTFilled(firstEntry); then for second entry it would be EnterLong (mySize2,"secondEntry";? I haven't played with the NTFilled yet so I am not sure how it works.

      Thanks.

      Comment


        #4
        You might consider storing two different variables and using them accordingly. Alternatively you could put the calculation inside the Enter method. Depending on how often and when it's called one I can't say which will work better for you.

        Additionally you might want to look into this example for advanced order handling. It's likely more than you need based on what I've seen here, but it could certainly help if you want to add more complexity. This will also give you a better idea for how you can size based on amount filled.

        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()
        LanceNinjaTrader Customer Service

        Comment


          #5
          Here's what I did for anyone reading this later. When I print into an output window mySize and mySize2 are the same, which is what I wanted. Without the MarketPosition.Flat it didn't work, I think it was calculating on every bar update. And just to be clear, this isn't a strat that I am trading, it was created for testing ideas. If anyone has a more eloquently way to code this I would be grateful for any help. For now this will do.


          if (SMA(10)[0] >= SMA(25)[0]
          && Close[0] > SMA(10)[0]
          && Position.MarketPosition == MarketPosition.Flat //to calculate size once)
          {
          int mySize = (int) (10000 * (.02) / (ATR (14)[0]*2));
          Print (mySize + "is mySize");
          EnterLong(mySize, "FirstPosition");
          mySize2 = mySize;
          Print (mySize2 + "is mySize2");
          }

          if (Position.MarketPosition == MarketPosition.Long && SMA(10)[0] >= SMA(25)[0]
          && Close[0] > SMA(10)[0] && Close[0] > myN // variable for second entry not included here)
          {EnterLong((int)mySize2, "SecondPosition");}

          Thanks to any and everyone who has taken the time to help out those not as far down the path! Your time and patience is appreciated.

          Comment


            #6
            Thanks for the feedback. Let me know if there is anything further I can be of assistance with.
            LanceNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by andrewtrades, Today, 04:57 PM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by chbruno, Today, 04:10 PM
            0 responses
            5 views
            0 likes
            Last Post chbruno
            by chbruno
             
            Started by josh18955, 03-25-2023, 11:16 AM
            6 responses
            436 views
            0 likes
            Last Post Delerium  
            Started by FAQtrader, Today, 03:35 PM
            0 responses
            7 views
            0 likes
            Last Post FAQtrader  
            Started by rocketman7, Today, 09:41 AM
            5 responses
            19 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Working...
            X