Description
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.API.Requests;
using System;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class RiskPositionSizeIndicator : Indicator
{
[Parameter("Risk Percentage", DefaultValue = 1, MinValue = 0, MaxValue = 100)]
public double RiskPercentage { get; set; }
[Parameter("Stop Loss in Pips", DefaultValue = 50, MinValue = 1)]
public int StopLossInPips { get; set; }
[Parameter("Take Profit in Pips (Risk-Reward 3:1)", DefaultValue = 150, MinValue = 1)]
public int TakeProfitInPips { get; set; }
protected override void Initialize()
{
// Initialization
}
public override void Calculate(int index)
{
// Getting the current account balance
double accountBalance = Account.Balance;
// Calculating position size considering the percentage risk
double riskAmount = accountBalance * RiskPercentage / 100;
double positionSize = Symbol.QuantityToVolume(Symbol.NormalizeVolume(Symbol.QuantityToVolume(riskAmount / Symbol.PipValue / StopLossInPips)));
// Displaying the position size and target price level on the chart
ChartObjects.DrawText("PositionSize", $"Position Size: {positionSize}", StaticPosition.TopLeft, Colors.White);
ChartObjects.DrawText("TakeProfit", $"Take Profit: {Symbol.Bid + TakeProfitInPips * Symbol.PipSize}", StaticPosition.TopRight, Colors.White);
}
}
}
The author decided to hide the source code.
chartistusd
Joined on 05.04.2024
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: New Indicator.algo
- Rating: 0
- Installs: 161
- Modified: 06/04/2024 17:16