Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

2% Rule

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

    2% Rule

    Hi,

    I was trying to create a method that would place a trade for the appropriate number of shares to implement the 2% rule.

    2% Rule: Definition as Investing Strategy, With Examples (investopedia.com)

    Does this look like a good start? Does anybody have any suggestions?

    Thanks,
    Erik

    Code:
    //PercentToBuy is a strategy property that defaults to 2.
    //LongOrShort is an enum that can be set to Long or Short.
    
            protected void EnterPercentage(double riskPerTrade, LongOrShort go) {
                double CashValue = Account.Get(AccountItem.CashValue, Currency.UsDollar);
                double TotalRiskAllowed = CashValue * (PercentToBuy / 100);
                int SharesToBuy = Convert.ToInt32(TotalRiskAllowed / riskPerTrade);
                SharesToBuy = Math.Max(1, SharesToBuy);
                Print("Enter " + PercentToBuy + "%  -->  " + SharesToBuy);
                if (go == LongOrShort.Long) EnterLong(SharesToBuy);
                else EnterShort(SharesToBuy);
            }​

    #2
    Hello Erik,

    As it appears you are asking for advise for a custom calculation, this thread will remain open for the community to provide opinions or suggestions for custom calculations.

    That said, CashValue * (PercentToBuy / 100) would provide that percent of the cash value.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    44 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    124 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    65 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    42 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X