Category Other  Published on 07/10/2020

NNFX infos on chart - V3

Description

this is the bugfixed version 3 (reference to DOSC removed) of the No Nonsense Forex Infos on chart for cTrader. Thanks for reporting this little nasty misbehaviour! In the meantime, my

 

NNFX (manual) Strategy Tester for cTrader is developing, see the screenshots. But I'm struggeling with the implemantion of the $EVZ function to adjust the risk and trading based on the value of the EVZ value.

 

 

 

 

 

 

 

 

 

 


using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NNFXInfosonchartV2 : Indicator
    {
        [Parameter("Risk Percentage", Group = "Risk", DefaultValue = 2, MinValue = 0.5, MaxValue = 2, Step = 0.25)]
        public double _initialRisk { get; set; }

        [Parameter("Accountinfo", DefaultValue = true)]
        public bool _accountInfo { get; set; }

        public double _riskAmount;
        public double _pipValue;
        public double _riskUnits;
        public double _initialTakeProfit;
        public double _initialStopLoss;
        public double _initialTradeVolume;

        public IndicatorDataSeries Result;
        private AverageTrueRange _atr;



        protected override void Initialize()
        {
            _atr = Indicators.AverageTrueRange(20, MovingAverageType.Exponential);
            Result = CreateDataSeries();
        }



        public override void Calculate(int index)
        {

            _riskAmount = Math.Round((Account.Equity * _initialRisk) / 100, 0);
            _pipValue = Math.Round(_riskAmount / (getATRPips() * 1.5), 2);
            _riskUnits = _riskAmount / (1.5 * getATRPips() * Symbol.PipValue);

            _initialTradeVolume = Symbol.NormalizeVolumeInUnits(_riskUnits / 2, RoundingMode.Down);
            _initialTakeProfit = Math.Round(getATRPips(), 0);
            _initialStopLoss = Math.Round(getATRPips() * 1.5, 0);


            string Text = "(ATR) " + _initialTakeProfit + " - ";
            Text += "(SL) " + _initialStopLoss + " - ";
            Text += "(Equity) " + Math.Round(Account.Equity, 0) + "$ - ";
            Text += "(PipVal) " + _pipValue + "$ - ";
            Text += "(Risk) " + _initialRisk + "% - ";
            Text += "(Risk$) " + Math.Round(_riskAmount, 0) + "$ - ";
            Text += "(Units) " + _initialTradeVolume * 2 + " - go, GET it !";
            ;




            Chart.DrawStaticText("Symbols", Text, VerticalAlignment.Top, HorizontalAlignment.Left, Color.Silver);

            if (IsBacktesting && _accountInfo)
            {
                Chart.DrawStaticText("Dashboard1", "Backtest " + Account.PreciseLeverage + ":1 " + Account.Currency, VerticalAlignment.Top, HorizontalAlignment.Right, Color.Green);
            }
            if (Account.IsLive && _accountInfo)
            {
                Chart.DrawStaticText("Dashboard1", "RealMoney " + Account.PreciseLeverage + ":1 " + Account.Currency, VerticalAlignment.Top, HorizontalAlignment.Right, Color.Red);
            }
            if (!Account.IsLive && !IsBacktesting && _accountInfo)
            {
                Chart.DrawStaticText("Dashboard1", "Forward " + Account.PreciseLeverage + ":1 " + Account.Currency, VerticalAlignment.Top, HorizontalAlignment.Right, Color.Yellow);
            }

        }

        private double getATRPips()
        {

            return _atr.Result.LastValue / Symbol.PipSize;
        }
    }
}


xabbu's avatar
xabbu

Joined on 20.07.2020

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: NNFX Infos on chart V.3.algo
  • Rating: 0
  • Installs: 1279
  • Modified: 13/10/2021 09:54
Comments
Log in to add a comment.
No comments found.