Description
Random Walk Index technical indicator was originally developed by Michael Poulos.
The RWI compares a security's price movements to random movements in an effort to determine if it's in a statistically significant trend. It can be used to generate decisive signals based on the strength of the underlying price trend.
In this original version, the levels 0 and 1 are considered as logical trigger values. Additionally, the calculation method is generated using ATR or Range methods.
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo
{
[Levels(0)]
[Indicator(IsOverlay = false, AutoRescale = true, AccessRights = AccessRights.None)]
public class mRWI : Indicator
{
[Parameter("Period (13)", DefaultValue = 13, MinValue = 2)]
public int inpPeriod { get; set; }
[Parameter("ATR SmoothType (ema)", DefaultValue = MovingAverageType.Exponential)]
public MovingAverageType inpSmoothType { get; set; }
[Parameter("Result Type (atr)", DefaultValue = enumResultTypes.ATR)]
public enumResultTypes inpResultType { get; set; }
[Output("RWI Bulls", LineColor = "Green", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
public IndicatorDataSeries outBulls { get; set; }
[Output("RWI Bears", LineColor = "Red", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
public IndicatorDataSeries outBears { get; set; }
private AverageTrueRange _atr;
private IndicatorDataSeries _range, _rwibulls, _rwibears;
protected override void Initialize()
{
_atr = Indicators.AverageTrueRange(inpPeriod, inpSmoothType);
_range = CreateDataSeries();
_rwibulls = CreateDataSeries();
_rwibears = CreateDataSeries();
}
public override void Calculate(int i)
{
_range[i] = Bars.HighPrices[i] - Bars.LowPrices[i];
_rwibulls[i] = (Bars.HighPrices[i] - (i>inpPeriod ? Bars.LowPrices[i-inpPeriod] : Bars.LowPrices[i])) / ((inpResultType == enumResultTypes.ATR ? _atr.Result[i] : _range[i]) * Math.Sqrt(inpPeriod));
_rwibears[i] = ((i>inpPeriod ? Bars.HighPrices[i-inpPeriod] : Bars.LowPrices[i]) - Bars.LowPrices[i]) / ((inpResultType == enumResultTypes.ATR ? _atr.Result[i] : _range[i]) * Math.Sqrt(inpPeriod));
outBulls[i] = _rwibulls[i];
outBears[i] = _rwibears[i];
}
}
public enum enumResultTypes
{
ATR,
Range
}
}
mfejza
Joined on 25.01.2022
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: mRWI.algo
- Rating: 0
- Installs: 451
- Modified: 02/06/2023 19:42
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.