Advertisement IC Markets

Equity Curve Versus R-Curve: Two Views of the Same Account

Document your personal trading journey. Track daily equity curves, review winning and losing streaks, share trade screenshots, and get constructive feedback.
PTScalper
Site Admin
Posts: 4805
Joined: Mon Jul 20, 2026 1:28 pm

Re: Equity Curve Versus R-Curve: Two Views of the Same Account

Post by PTScalper »

Here it is Ctrader version:

Code: Select all

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class LiquiditySweep : Indicator
    {
        [Parameter("Pivot Left Bars", DefaultValue = 5)]
        public int LeftBars { get; set; }

        [Parameter("Pivot Right Bars", DefaultValue = 5)]
        public int RightBars { get; set; }

        private double _lastHigh = double.NaN;
        private double _lastLow = double.NaN;
        private int _lastHighIndex;
        private int _lastLowIndex;

        public override void Calculate(int index)
        {
            // Wait until we have enough bars to form a pivot
            if (index < LeftBars + RightBars)
                return;

            int pivotIndex = index - RightBars;

            // 1. Identify Pivot High
            bool isPivotHigh = true;
            for (int i = pivotIndex - LeftBars; i <= index; i++)
            {
                if (i == pivotIndex) continue;
                if (Bars.High[i] >= Bars.High[pivotIndex])
                {
                    isPivotHigh = false;
                    break;
                }
            }

            if (isPivotHigh)
            {
                _lastHigh = Bars.High[pivotIndex];
                _lastHighIndex = pivotIndex;
            }

            // 2. Identify Pivot Low
            bool isPivotLow = true;
            for (int i = pivotIndex - LeftBars; i <= index; i++)
            {
                if (i == pivotIndex) continue;
                if (Bars.Low[i] <= Bars.Low[pivotIndex])
                {
                    isPivotLow = false;
                    break;
                }
            }

            if (isPivotLow)
            {
                _lastLow = Bars.Low[pivotIndex];
                _lastLowIndex = pivotIndex;
            }

            // 3. Draw and dynamically extend structural lines
            if (!double.IsNaN(_lastHigh))
            {
                // Using a static name "ResLine" automatically updates/extends the existing line on each tick
                var resLine = Chart.DrawTrendLine("ResLine", _lastHighIndex, _lastHigh, index, _lastHigh, Color.FromArgb(120, Color.Red));
                resLine.LineStyle = LineStyle.Lines;
            }

            if (!double.IsNaN(_lastLow))
            {
                var supLine = Chart.DrawTrendLine("SupLine", _lastLowIndex, _lastLow, index, _lastLow, Color.FromArgb(120, Color.Green));
                supLine.LineStyle = LineStyle.Lines;
            }

            // 4. Sweep Detection Logic
            // Checks if the current bar swept the previous structure but rejected and closed inside.
            if (!double.IsNaN(_lastHigh) && Bars.High[index] > _lastHigh && Bars.Close[index] < _lastHigh)
            {
                Chart.DrawIcon("SweepHigh_" + index, ChartIconType.DownArrow, index, Bars.High[index] + (Symbol.PipSize * 3), Color.Red);
            }

            if (!double.IsNaN(_lastLow) && Bars.Low[index] < _lastLow && Bars.Close[index] > _lastLow)
            {
                Chart.DrawIcon("SweepLow_" + index, ChartIconType.UpArrow, index, Bars.Low[index] - (Symbol.PipSize * 3), Color.Green);
            }
        }
    }
}
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
Recommended broker for automated trading & scalping IC Markets
PTScalper
Site Admin
Posts: 4805
Joined: Mon Jul 20, 2026 1:28 pm

Re: Equity Curve Versus R-Curve: Two Views of the Same Account

Post by PTScalper »

Key Differences from Pine Script

Line Extension: By passing static string names ("ResLine" and "SupLine") into Chart.DrawTrendLine, the cTrader API automatically handles the garbage collection of the old line segments and dynamically stretches the line to the current index on every tick, keeping your DOM perfectly clean.

Icon Anchoring: Icons are uniquely named ("SweepHigh_" + index) so they remain permanently stamped on the chart where historical sweeps occurred, offset by 3 pips to keep the wicks visible.
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
Post Reply