Description
The indicator displays the ratio of yesterday's range to today's range.
As Toby Crabel noted, "If yesterday's range was narrower than the previous day's, it may lead to an explosive movement today."
According to my dear mentor Iba, "If the current range is narrower than the previous one, the time trigger to close the position is based on the loss/rebalance trend force for the current trend and must happen."
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo
{
[Levels(0)]
[Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
public class mSRangeContraction : Indicator
{
[Parameter("Threshold (50.0)", DefaultValue = 50.0)]
public double inpThreshold { get; set; }
[Parameter("Show RC (yes)", DefaultValue = true)]
public bool inpShowRC { get; set; }
[Parameter("Calculation Mode (current)", DefaultValue = enumCalculationMode.Current)]
public enumCalculationMode inpCalculationMode { get; set; }
[Output("SRange", LineColor = "Black", PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries outSRC { get; set; }
[Output("SRange Contraction", LineColor = "Red", PlotType = PlotType.Points, Thickness = 5)]
public IndicatorDataSeries outRC { get; set; }
[Output("Threshold", LineColor = "Silver", PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries outThreshold { get; set; }
private IndicatorDataSeries _hld, _src, _rc;
private int lookback;
protected override void Initialize()
{
lookback = inpCalculationMode == enumCalculationMode.Current ? 0 : 1;
_hld = CreateDataSeries();
_src = CreateDataSeries();
_rc = CreateDataSeries();
}
public override void Calculate(int i)
{
_hld[i] = Bars.HighPrices[i-1-lookback] != Bars.LowPrices[i-1-lookback] ? 1 : 0;
_src[i] = _hld[i] == 1 ? 100.0 * (Bars.HighPrices[i-lookback] - Bars.LowPrices[i-lookback]) / (Bars.HighPrices[i-1-lookback] - Bars.LowPrices[i-1-lookback]) : 0;
_rc[i] = inpShowRC == true && _src[i] < inpThreshold ? _src[i] : double.NaN;
outSRC[i] = _src[i];
outRC[i] = _rc[i];
outThreshold[i+100] = inpThreshold;
}
}
public enum enumCalculationMode
{
Current,
Previous
}
}
mfejza
Joined on 25.01.2022
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: mSRangeContraction.algo
- Rating: 5
- Installs: 522
- Modified: 21/03/2023 19:38
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.
No comments found.