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


Jonkey - November 09, 2015 @ 05:36

Thank you, Simple but effective.

ka.wcs - December 19, 2015 @ 10:29


A great help.

If we could get 2 lines on the screen (to drag and drop them) with differents colors, (one for the OPEN position (Lime ?), one for the SL position (Red ?)), and calculate directly the lotsize from the Risk % and theses 2 lines's difference in pips, it would be a nice improvement.

I've the .MQ4 for this, if it can help.

I've try to convert it with 2cAlgo, but it can't, saying it's a MQ5 code (?)

Thanks for this.



Dore - February 12, 2016 @ 00:54

How can I change the color.  I like to use a white background & the yellow is hard to see.  I also like the suggestion from ka.wcs that would be very useful 



exportwork - March 15, 2016 @ 22:56

Hi colga645,

I saw your great work here at ctrader forum.

Can the below link of mt4 position sizing indicator and script be made for ctrader platform (it is a position sizing automatic risk lots calculation and market order placement):

Earn forex website forum link ( they have already made it for mt4 platform but not ctrader platform): http://www.earnforex.com/metatrader-indicators/Position-Size-Calculator/

it's very very useful. Please feel free to reply at my below email.


Paras sharma (Email: exportwork@yahoo.com )

Omega - February 10, 2019 @ 00:54

Hi there,


Nice little software, I've put this on the GER30 (DAX) and US30 (Dow) but it doesn't work, are you able to adjust so that it does work on the indices?




matt92 - August 08, 2019 @ 01:17

Do you have a version that does this using volume (unit size) instead ot lot size. Thanks