Category Other  Published on 08/11/2015

Position size for balance's % risk

Description

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.

 


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)
                DisplayPositionSizeRiskOnChart();
        }

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

        }
    }
}


CO
colga645

Joined on 01.06.2015 Blocked

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: Position Risk krp.algo
  • Rating: 5
  • Installs: 7626
  • Modified: 13/10/2021 09:54
Comments
Log in to add a comment.
matt92's avatar
matt92 · 5 years ago

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

OM
Omega · 5 years ago

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?

 

Thanks


D

EX
exportwork · 8 years ago

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.

Regards,

Paras sharma (Email: exportwork@yahoo.com )

DO
Dore · 8 years ago

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 

Thanks

Bob

KA
ka.wcs · 8 years ago

Hello,

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.

Andrew

 

JO
Jonkey · 9 years ago

Thank you, Simple but effective.