Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 00nevest, Today, 02:27 PM
    0 responses
    1 view
    0 likes
    Last Post 00nevest  
    Started by Jonafare, 12-06-2012, 03:48 PM
    5 responses
    3,986 views
    0 likes
    Last Post rene69851  
    Started by Fitspressorest, Today, 01:38 PM
    0 responses
    2 views
    0 likes
    Last Post Fitspressorest  
    Started by Jonker, Today, 01:19 PM
    0 responses
    2 views
    0 likes
    Last Post Jonker
    by Jonker
     
    Started by futtrader, Today, 01:16 PM
    0 responses
    9 views
    0 likes
    Last Post futtrader  
    Working...
    X