Description
//+------------------------------------------------------------------+
//| SupportResistance |
//| Copyright © 2016, UCHE OBI |
//| Developer:UCHE OBI |
//| Skype: OBI.UCHE |
//| email:ucheceleste@Gmail.com |
//+------------------------------------------------------------------+
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
SupportResistance : Indicator
{
[Parameter(DefaultValue = 10)]
public
int
range {
get
;
set
; }
[Parameter(DefaultValue = 3)]
public
int
confirmations {
get
;
set
; }
[Output(
"Res"
, Color = Colors.Black, LineStyle = LineStyle.DotsVeryRare)]
public
IndicatorDataSeries resistance {
get
;
set
; }
[Output(
"Sup"
, Color = Colors.Black, LineStyle = LineStyle.DotsVeryRare)]
public
IndicatorDataSeries support {
get
;
set
; }
public
double
res;
public
double
sup;
private
MarketSeries Series;
protected
override
void
Initialize()
{
// Initialize and create nested indicators
Series = MarketSeries;
}
public
override
void
Calculate(
int
index)
{
// Calculate value at specified index
// Result[index] = ...
var upline = (Series.Close.Maximum(range) + Series.High.Maximum(range)) / 2;
var dnline = (Series.Close.Minimum(range) + Series.Low.Minimum(range)) / 2;
resistance[index] =
double
.NaN;
support[index] =
double
.NaN;
if
(resbarsconfirmed(upline, index) >= confirmations)
{
res = upline;
ChartObjects.DrawLine(
"resline"
+ upline.ToString(), Series.OpenTime[index], upline, Series.OpenTime[index - range], upline, Colors.DarkRed, 2, LineStyle.Solid);
}
if
(supbarsconfirmed(dnline, index) >= confirmations)
{
sup = dnline;
ChartObjects.DrawLine(
"supline"
+ dnline.ToString(), Series.OpenTime[index], dnline, Series.OpenTime[index - range], dnline, Colors.DarkBlue, 2, LineStyle.Solid);
}
}
private
int
resbarsconfirmed(
double
line,
int
index)
{
int
touches = 0;
for
(
int
i = index; i > index - range; i--)
{
if
(Series.Low[i] < line && Series.High[i] >= line && Series.Close[i] < line)
touches += 1;
if
(Series.Close[i] > line)
touches = 0;
}
return
touches;
}
private
int
supbarsconfirmed(
double
line,
int
index)
{
int
touches = 0;
for
(
int
i = index; i > index - range; i--)
{
if
(Series.High[i] > line && Series.Low[i] <= line && Series.Close[i] > line)
touches += 1;
if
(Series.Close[i] < line)
touches = 0;
}
return
touches;
}
}
}
//+------------------------------------------------------------------+
//| SupportResistance |
//| Copyright © 2016, UCHE OBI |
//| Developer:UCHE OBI |
//| Skype: OBI.UCHE |
//| email:ucheceleste@Gmail.com |
//+------------------------------------------------------------------+
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 SupportResistance : Indicator
{
[Parameter(DefaultValue = 10)]
public int range { get; set; }
[Parameter(DefaultValue = 3)]
public int confirmations { get; set; }
[Output("Res", Color = Colors.Black, LineStyle = LineStyle.DotsVeryRare)]
public IndicatorDataSeries resistance { get; set; }
[Output("Sup", Color = Colors.Black, LineStyle = LineStyle.DotsVeryRare)]
public IndicatorDataSeries support { get; set; }
public double res;
public double sup;
private MarketSeries Series;
protected override void Initialize()
{
// Initialize and create nested indicators
Series = MarketSeries;
}
public override void Calculate(int index)
{
// Calculate value at specified index
// Result[index] = ...
var upline = (Series.Close.Maximum(range) + Series.High.Maximum(range)) / 2;
var dnline = (Series.Close.Minimum(range) + Series.Low.Minimum(range)) / 2;
resistance[index] = double.NaN;
support[index] = double.NaN;
if (resbarsconfirmed(upline, index) >= confirmations)
{
res = upline;
ChartObjects.DrawLine("resline" + upline.ToString(), Series.OpenTime[index], upline, Series.OpenTime[index - range], upline, Colors.DarkRed, 2, LineStyle.Solid);
}
if (supbarsconfirmed(dnline, index) >= confirmations)
{
sup = dnline;
ChartObjects.DrawLine("supline" + dnline.ToString(), Series.OpenTime[index], dnline, Series.OpenTime[index - range], dnline, Colors.DarkBlue, 2, LineStyle.Solid);
}
}
private int resbarsconfirmed(double line, int index)
{
int touches = 0;
for (int i = index; i > index - range; i--)
{
if (Series.Low[i] < line && Series.High[i] >= line && Series.Close[i] < line)
touches += 1;
if (Series.Close[i] > line)
touches = 0;
}
return touches;
}
private int supbarsconfirmed(double line, int index)
{
int touches = 0;
for (int i = index; i > index - range; i--)
{
if (Series.High[i] > line && Series.Low[i] <= line && Series.Close[i] > line)
touches += 1;
if (Series.Close[i] < line)
touches = 0;
}
return touches;
}
}
}
cxc_g
Joined on 23.11.2022
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: SupportResistance.algo
- Rating: 0
- Installs: 1857
- Modified: 23/11/2022 04:34