Position size for balance's % risk free

by colga645 in category Other at 08/11/2015

In indicator display position size for specified currency pair and balance's % risk (stop loss). It does not take into account spread or fees, so simply adjust % to accommodate those. I like to have this displayed o the chart, it helps me with risk management through different currency pairs.


Please let me know by comment if it is useful for you or how would you improve.


Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgocTrader
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;

//calculate position size for current balance and specified risk (stop loss) per position; 
//does not take not account commission or spread though, simply adjust risk % to accommodate those

namespace cAlgo.Indicators
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class PositionRiskkrp : Indicator

        //percentage of current balance that can be risked (stop loss size in pips) on one position
        [Parameter("Stop Loss Risk %", DefaultValue = 5)]
        public int stopLossRiskPercent { get; set; }

        [Parameter("Stop Loss in Pips", DefaultValue = 10)]
        public int stopLossInPips { get; set; }

        public override void Calculate(int index)
            if (index == 0)

        private void DisplayPositionSizeRiskOnChart()

            double costPerPip = (double)((int)(Symbol.PipValue * 10000000)) / 100;

            double positionSizeForRisk = (Account.Balance * stopLossRiskPercent / 100) / (stopLossInPips * costPerPip);

            string text = stopLossRiskPercent + "% x " + stopLossInPips + "pip = " + Math.Round(positionSizeForRisk, 2) + " lot";

            ChartObjects.DrawText("positionRisk", text, StaticPosition.TopRight, Colors.Yellow);