Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trade size based on PnL and scaling out

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

    Trade size based on PnL and scaling out

    My strategy determines the order size based on the profit earned to that point in the day. If it is above a threshold, it trades 2, then 3, etc. That part of the logic is functional as confirmed by printing the 'TradeSize' variable to the output window.

    Unfortunately, my strategy is not entering the proper quantity.

    I checked the sample of scaling out from the forum, and believe that I have correctly applied the salient points.

    I have the following in my Initialize section:
    EntriesPerDirection =1;
    EntryHandling = EntryHandling.UniqueEntries;
    TradeSize = MinTradeSize;
    SetStopLoss("", CalculationMode.Ticks, Stop, false);
    SetProfitTarget("ZLRe1", CalculationMode.Ticks, Target1);
    SetProfitTarget("ZLRe2", CalculationMode.Ticks, Target2);
    I then have the following logic in my long entries section

    if(Position.MarketPosition == MarketPosition.Flat)
    {
    EnterLongLimit(1,KeltnerEMAChannelTrend(4, 1.5, 21).Midline[0], "ZLRe1");
    if(TradeSize >= 2) EnterLongLimit(1, KeltnerEMAChannelTrend(4, 1.5, 21).Midline[0], "ZLRe2");
    if(TradeSize == 3) EnterLongLimit(1, KeltnerEMAChannelTrend(4, 1.5, 21).Midline[0], "ZLRe3");
    }


    I figure I am missing something simple... Can anyone spot it?

    Rod

    #2
    Hello,

    From your EnterLongLimits, it appears you are always using a qty of 1.

    You should be setting the quantity dynamically to the TradeSize variable

    Code:
    if(TradeSize == 3) EnterLongLimit(TradeSize, KeltnerEMAChannelTrend(4, 1.5, 21).Midline[0], "ZLRe3");
    edit: Excuse me, I understand you're scaling in then... so that wouldn't be correct.

    Have you enabled the TraceOrders property to trace if these orders are being ignored, and if so, for what reason? More information on TraceOrders can be found below:

    MatthewNinjaTrader Product Management

    Comment


      #3
      Also, under what condition is TradeSize set to another value?

      You are currently checking this only when the Position == Flat, so if you're looking to scale in using these additional order quantities, you would need to do this outside of the flat position condition.
      MatthewNinjaTrader Product Management

      Comment


        #4
        TradeSize is determined prior to the long or short entry sections of the code. As I mentioned, the TradeSize code appears to be working properly

        Here is the entire code:

        /// Trade Size
        double PnL = GetAccountValue(AccountItem.RealizedProfitLoss);
        int SizeMultiplier = (int)Math.Floor(PnL / pnL2incrSize); //revise
        Print("PnL " + PnL.ToString());
        Print("SizeMult " + SizeMultiplier.ToString());


        if (PnL2incrSize == 0)
        TradeSize = MinTradeSize;
        else if (PnL > 0)
        TradeSize = Math.Min(MinTradeSize + SizeMultiplier,MaxTradeSize);
        else if (PnL > PnL2STOP)
        TradeSize = MinTradeSize;

        Comment


          #5
          Can you please try adding a Print() statement within the Conditional statement you are placing the orders?

          if(Position.MarketPosition == MarketPosition.Flat)
          {
          Print(TradeSize);
          }

          It would be important to know what the trade size variable is at at the condition you are expecting it to place trades at the new trade size.
          MatthewNinjaTrader Product Management

          Comment


            #6
            I have confirmed that the value of TradeSize is correct.

            Comment


              #7
              I have no idea what happened, as I have not changed any of the logic since opening this thread, but the strategy logic is working now in replay mode.

              Go figure

              Comment

              Latest Posts

              Collapse

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