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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    81 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    42 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    64 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    68 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    55 views
    0 likes
    Last Post CarlTrading  
    Working...
    X