How are multiple take profit rules prioritized?

In MagicTradeBot, when multiple Take Profit rules are defined for a trade, the bot executes them based on the profit percentage targets (TargetProfitPer). This ensures that profits are taken in a logical and sequential order as the market moves in your favor.


🧠 Priority Mechanism

  1. Profit Percentage First

    • Rules with lower TargetProfitPer are evaluated and executed before higher ones.
    • Example: If you have rules set for 10% and 20% profit:

      - TargetProfitPer: 10  
        SellPer: 40
        RuleName: "Target - Short"
        IsEnabled: true
        EnableSmartTP: true
        TrailingGapPer: 2
        MinProfitLock: 4
        UseDynamicGap: true
      - TargetProfitPer: 20  
        SellPer: 100
        RuleName: "Target - Short"
        IsEnabled: true
        EnableSmartTP: true
        TrailingGapPer: 2
        MinProfitLock: 4
        UseDynamicGap: true
      
    • The 10% TP rule triggers first, selling 40% of the position.
    • The 20% TP rule triggers next, closing the remaining 60% of the position.
  2. Sequential Execution

    • Each rule is evaluated independently, but in ascending order of TargetProfitPer
    • This allows staggered profit-taking, which is especially useful in volatile markets
  3. Partial vs Full Take Profit

    • Rules with partial TP (SellPer < 100) execute first, gradually reducing position size
    • Rules with full TP (SellPer = 100) close the remaining position once higher profit targets are reached
  4. Smart TP Integration

    • If Smart TP is enabled:

      • Trailing logic is applied after the target profit is reached
      • The bot may delay execution until the trailing gap or minimum profit lock conditions are met

🔄 Example Flow

  • Open trade: 1 BTC
  • Take Profit rules:

    1. TargetProfitPer: 10, SellPer: 40
    2. TargetProfitPer: 20, SellPer: 100

Scenario:

  1. Price rises +10% → Bot sells 0.4 BTC (40%)
  2. Price continues to +20% → Bot sells remaining 0.6 BTC (100% of remaining)
  3. Smart TP active → If price pulls back slightly, trailing logic may execute before final closure

This ensures profits are secured incrementally, while still allowing upside potential for remaining positions.


📌 Key Points

  • Rules are prioritized by TargetProfitPer (lowest → highest)
  • Partial TP rules execute first, followed by higher targets or full TP
  • Smart TP can adjust exact execution timing dynamically
  • Sequential prioritization ensures structured and disciplined profit-taking

📎 Related Topics