Description
New update (17/09/2021) Better performance
Not necessarily a trend based indicator.
Using the RSI indicator as reference, levels are being implimented on the Chart, higher, lower and center.
With three types of parameters, the higher the more precise they might be, but the fewer levels will be shown.
Notice: aside frome the center levels, for better use of the support and resistence levels, the higher the type the better, levels are only been shown, as prices reach a certain axis.
Chartshot: EURUSD, h1
04:23:13 (UTC+0) on Jun 9th, 2021
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 LevelsPerHours : Indicator
{
[Parameter("Period", Group = "Main Settings", DefaultValue = 5)]
public int Period { get; set; }
[Parameter("FromLast", Group = "Main Settings", DefaultValue = 15)]
public int SinceLast { get; set; }
[Parameter("Oppaccity", Group = "Main Settings", DefaultValue = 40)]
public int Opacc { get; set; }
[Parameter("ColorOption1", Group = "ColorSett", DefaultValue = "Yellow")]
public string ColoOp1 { get; set; }
[Parameter("ColorOption2", Group = "ColorSett", DefaultValue = "Crimson")]
public string ColoOp2 { get; set; }
[Parameter("ColorOption3", Group = "ColorSett", DefaultValue = "Purple")]
public string ColoOp3 { get; set; }
[Parameter("ColorOption4", Group = "ColorSett", DefaultValue = "Blue")]
public string ColoOp4 { get; set; }
[Parameter(DefaultValue = 1, MinValue = 1, MaxValue = 3)]
public int SwitchOption { get; set; }
[Parameter("SpacePerPips", DefaultValue = 3)]
public int Space { get; set; }
private RelativeStrengthIndex _rsi;
private DateTime _openTime, _closingTime;
protected override void Initialize()
{
_rsi = Indicators.RelativeStrengthIndex(Bars.ClosePrices, SwitchOption == 1 ? 35 : SwitchOption == 2 ? 65 : SwitchOption == 3 ? 120 : 120);
var onBars = MarketData.GetBars(TimeFrame.Monthly);
_openTime = onBars.OpenTimes.Last(SinceLast);
_closingTime = _openTime.AddHours(Period);
// Initialize and create nested indicators
}
private void GetCenterLevels(ref double level1, ref double level2)
{
double result1 = level1;
double result2 = level2;
double pip = Symbol.PipSize * Space;
if (Functions.HasCrossedAbove(_rsi.Result, 50, 1))
{
result1 = Bars.HighPrices.Last(1);
result2 = Bars.HighPrices.Last(1) - pip;
;
}
else
{
if (Functions.HasCrossedBelow(_rsi.Result, 50, 1))
{
result1 = Bars.LowPrices.Last(1);
result2 = Bars.LowPrices.Last(1) + pip;
}
}
level1 = result1;
level2 = result2;
}
private double _center1, _center2;
private double _higher1, _higher2;
private double _lower1, _lower2;
public override void Calculate(int index)
{
if (Bars.OpenTimes.Last(1) < _closingTime && Bars.OpenTimes.LastValue >= _closingTime)
{
_openTime = Bars.OpenTimes.LastValue;
}
_closingTime = _openTime.AddHours(Period);
GetCenterLevels(ref _center1, ref _center2);
GetHigherLower(ref _higher1, ref _higher2, ref _lower1, ref _lower2);
var colo1 = Color.FromArgb(Opacc, Color.FromName(_rsi.Result.LastValue >= 50 ? ColoOp1 : _rsi.Result.LastValue < 50 ? ColoOp2 : ColoOp2).R, Color.FromName(_rsi.Result.LastValue >= 50 ? ColoOp1 : _rsi.Result.LastValue < 50 ? ColoOp2 : ColoOp2).G, Color.FromName(_rsi.Result.LastValue >= 50 ? ColoOp1 : _rsi.Result.LastValue < 50 ? ColoOp2 : ColoOp2).B);
var colo2 = Color.FromArgb(Opacc, Color.FromName(ColoOp3).R, Color.FromName(ColoOp3).G, Color.FromName(ColoOp3).B);
var colo3 = Color.FromArgb(Opacc, Color.FromName(ColoOp4).R, Color.FromName(ColoOp4).G, Color.FromName(ColoOp4).B);
Chart.DrawRectangle("Draw1" + _openTime, _openTime, _center1, _closingTime, _center2, colo1).IsFilled = true;
Chart.DrawRectangle("Draw2" + _openTime, _openTime, _higher1, _closingTime, _higher2, _higher2 > _center1 ? colo2 : Color.Transparent).IsFilled = true;
Chart.DrawRectangle("Draw3" + _openTime, _openTime, _lower1, _closingTime, _lower2, _lower2 < _center2 ? colo3 : Color.Transparent).IsFilled = true;
}
private void GetHigherLower(ref double level1, ref double level2, ref double level3, ref double level4)
{
double result1 = level1;
double result2 = level2;
double result3 = level3;
double result4 = level4;
double pip = Symbol.PipSize * Space;
if (Functions.HasCrossedAbove(_rsi.Result, 55, 1))
{
result1 = Bars.HighPrices.Last(1);
result2 = Bars.HighPrices.Last(1) - pip;
}
else
{
if (Functions.HasCrossedBelow(_rsi.Result, 45, 1))
{
result3 = Bars.LowPrices.Last(1);
result4 = Bars.LowPrices.Last(1) + pip;
}
}
level1 = result1;
level2 = result2;
level3 = result3;
level4 = result4;
}
}
}
D.
d.deel
Joined on 06.01.2021
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: LevelsPerHours.algo
- Rating: 5
- Installs: 3387
- 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.
MZ
appreciate it
D.
:)
AA
Awesome indicator, thanks for share
vERY GOOD, BEST i HAVE COME ACROSS ON HERE SO FAR.