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);
}
}
}
colga645
Joined on 01.06.2015 Blocked
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: Position Risk krp.algo
- Rating: 5
- Installs: 7586
- Modified: 13/10/2021 09:54
Comments
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
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 )
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
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
Thank you, Simple but effective.
Do you have a version that does this using volume (unit size) instead ot lot size. Thanks