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 mishhh, 05-25-2010, 08:54 AM
    19 responses
    6,189 views
    0 likes
    Last Post rene69851  
    Started by gwenael, Today, 09:29 AM
    0 responses
    1 view
    0 likes
    Last Post gwenael
    by gwenael
     
    Started by Karado58, 11-26-2012, 02:57 PM
    8 responses
    14,829 views
    0 likes
    Last Post Option Whisperer  
    Started by Option Whisperer, Today, 09:05 AM
    0 responses
    1 view
    0 likes
    Last Post Option Whisperer  
    Started by cre8able, Yesterday, 01:16 PM
    3 responses
    11 views
    0 likes
    Last Post cre8able  
    Working...
    X