Description
OrglobalFx ATR Risk Calculator V1.0
Telegram: @orglobalng
Displays Stoploss based x * ATR
Displays risk
Displays present bar size in pips
Displays atr for weekly, daily, hour4 and hour1
Displays current spread
Displays volume per trade. Calculated based on risk%, balance etc.
// OrglobalFx ATR Risk Calculator V1.0
// Stoploss based x * ATR
// Displays risk
// Displays present bar size in pips
//Displays atr for weekly, daily, hour4 and hour1
// Displays current spread
// Displays volume per trade. Calculated based on risk%, balance etc.
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
using System.Net;
namespace cAlgo.Indicators
{
[Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
public class OrglobalFxATRRiskCalculator_v1_0 : Indicator
{
[Parameter()]
public DataSeries Source { get; set; }
[Parameter("MA Type", DefaultValue = MovingAverageType.Exponential)]
public MovingAverageType MaType { get; set; }
[Parameter("ATR Period", DefaultValue = 20)]
public int AtrPeriod { get; set; }
[Parameter("Risk Percentage", Group = "Risk", DefaultValue = 1, MinValue = 0.1, MaxValue = 10, Step = 0.1)]
public double _initialRisk { get; set; }
[Parameter("Stoploss (xATR)", DefaultValue = 1.5)]
public double _xatr { get; set; }
public double _tradetargetdaily, _tradetarget, _riskAmount, _pipValue, _riskUnits, _initialTakeProfit, _initialStopLoss, _initialTradeVolume, _atrtakeprofit, Weekly_ATR;
public double Daily_ATR, H4_ATR, H1_ATR, _netprofit, _spread, _stoploss, _candlesize;
private AverageTrueRange __atr, atr, ATR_Weekly, ATR_Daily, ATR_H4, ATR_H1;
private IchimokuKinkoHyo _ichi;
protected override void Initialize()
{
/////////////////////////////ATR Display////////////////////////////
atr = Indicators.AverageTrueRange(AtrPeriod, MaType);
__atr = Indicators.AverageTrueRange(AtrPeriod, MaType);
ATR_Weekly = Indicators.AverageTrueRange(MarketData.GetBars(TimeFrame.Weekly), AtrPeriod, MaType);
ATR_Daily = Indicators.AverageTrueRange(MarketData.GetBars(TimeFrame.Daily), AtrPeriod, MaType);
ATR_H4 = Indicators.AverageTrueRange(MarketData.GetBars(TimeFrame.Hour4), AtrPeriod, MaType);
ATR_H1 = Indicators.AverageTrueRange(MarketData.GetBars(TimeFrame.Hour), AtrPeriod, MaType);
_ichi = Indicators.IchimokuKinkoHyo(9, 26, 52);
}
public override void Calculate(int index)
{
var ATR = Math.Round((atr.Result.Last(0) / Symbol.PipSize), 0);
var TradeAmount = Math.Round((Account.Equity * (_initialRisk / 100)) / ((3 * ATR) * Symbol.PipValue), 2);
TradeAmount = Math.Round(Symbol.NormalizeVolumeInUnits(TradeAmount, RoundingMode.Down), 2);
////////////////////////////////////ATRDisplay////////////////////////////////////////////////////////////////
Weekly_ATR = Math.Round((ATR_Weekly.Result.LastValue / Symbol.PipSize), 0);
Daily_ATR = Math.Round((ATR_Daily.Result.LastValue / Symbol.PipSize), 0);
H4_ATR = Math.Round((ATR_H4.Result.LastValue / Symbol.PipSize), 0);
H1_ATR = Math.Round((ATR_H1.Result.LastValue / Symbol.PipSize), 0);
_riskAmount = Math.Round((Account.Equity * (_initialRisk / 100)), 0);
_pipValue = Math.Round(_riskAmount / (ATR * 3), 2);
_riskUnits = _riskAmount / (3 * ATR * Symbol.PipValue);
_candlesize = Math.Abs(Bars.LowPrices.LastValue - Bars.HighPrices.LastValue);
_candlesize = (int)Math.Round(_candlesize / Symbol.PipSize, 3);
_initialTradeVolume = Symbol.NormalizeVolumeInUnits(_riskUnits / 2, RoundingMode.Down);
_initialTakeProfit = Math.Round(ATR, 0);
_initialStopLoss = Math.Round(_xatr * _initialTakeProfit, 0);
_atrtakeprofit = Math.Round(_initialTakeProfit * _pipValue, 0);
var _lotsize = TradeAmount;
_spread = Math.Round(Symbol.Spread / Symbol.PipSize, 2);
string Text = "\n" + SymbolName;
Text += "\n (" + Chart.TimeFrame + ") " + _initialTakeProfit + "pips";
Text += "\n(SL) " + _initialStopLoss;
//Text += "\n(PipVal) " + _pipValue + "$";
Text += "\n(Volume) " + _lotsize;
Text += "\n(W1 ATR) " + Weekly_ATR + "pips";
Text += "\n(D1 ATR) " + Daily_ATR + "pips";
Text += "\n(H4 ATR) " + H4_ATR + "pips";
Text += "\n(H1 ATR) " + H1_ATR + "pips";
Text += "\n(Risk$) " + Math.Round(_riskAmount, 0) + Account.Currency;
Text += "\n(Spread) " + _spread + "pips";
Text += "\n(CandleSize) " + _candlesize + "pips";
;
Chart.DrawStaticText("Symbols", Text, VerticalAlignment.Top, HorizontalAlignment.Left, Color.Silver);
}
}
}
Orglobalfx01
Joined on 03.03.2021
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: OrglobalFx ATR Risk Calculator_v1_0.algo
- Rating: 5
- Installs: 1602
- Modified: 13/10/2021 09:54
Note that publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section, please use the Copyright Infringement Notification form to submit a claim.
Comments
Log in to add a comment.
this is very good and that's what I need, thank you so much!