Risk according to percent of Equity and Stop Loss

Questions about MultiCharts and user contributed studies.
Eduardo
Posts: 21
Joined: 22 May 2020

Risk according to percent of Equity and Stop Loss

Postby Eduardo » 28 May 2020

I'm trying to program a little function but I'm stuck and I wonder if anybody could give me a hand. I've seen several posts about the topic but none about exactly what I need. I only trade Forex.

I would like to trade a fixed percent of my Equity on each order, say 1%. So, according to the Stop Loss price (distance), I would like to get the Lot Size (shares/units) to trade.

I came up with this formula but I don't think it's working well. Can you please take a look at it or let me know if there is a better way to do it?
Thank you!

Code: Select all

//Example of how to use it: // UnitsToTrade = SharesByPercentRisk(1, 200, "Long"); // If ... buy UnitsToTrade shares next bar at market Inputs: PercentageRisk(NumericSimple), // The percentage I want to trade ie: 1 or 2 SLdistance(NumericSimple), // Distance from Market price Direction(StringSimple); // Long or Short Variables: AccountEquity(0), // will hold the account equity at the moment MarketPrice(0), // MarketPrice at the moment: Bid price for shorts and Ask price for Longs SLPrice(0), // Price where the SL will be set according to the distance input Risk(0), // Receives the integer and turns it into a percentage NumberOfShares(0); // final result of formula Risk = PercentageRisk/100; AccountEquity= GetRTAccountEquity(GetAccount(1)); if Direction= "Long" then begin MarketPrice = CurrentAsk; SLPrice = MarketPrice - SLdistance * TickSize; NumberOfShares = AccountEquity* Risk / ((MarketPrice - SLPrice)*TickSize); End Else if Direction= "Short" then Begin MarketPrice = CurrentBid; SLPrice = MarketPrice + SLdistance * TickSize; NumberOfShares = AccountEquity* Risk / ((SLPrice - MarketPrice)*TickSize); End; SharesByPercentRisk = Round(NumberOfShares,0);

User avatar
Vlada MultiCharts
Posts: 293
Joined: 22 Apr 2020
Has thanked: 8 times
Been thanked: 76 times

Re: Risk according to percent of Equity and Stop Loss

Postby Vlada MultiCharts » 25 Aug 2020

Hello Eduardo,

You can use the Portfolio Money Management settings in Portfolio Trader or the Portfolio Money Management signal.
Please note that the risk is calculated on one bar (tick) and the orders are executed later, so there is a possibility of exceeding the risk limits.

You can also use the Percent of Equity parameter in Portfolio Trader -> Signals -> Properties tab -> Trade Size section.


Return to “MultiCharts”