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
//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);
}

Comment