Description
Hello again,
Money never sleeps, good night at all.
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 HLAveragesBoxesOverlayFibo : Indicator
{
[Output("Result1", LineColor = "Red")]
public IndicatorDataSeries Result1 { get; set; }
[Output("Result2", LineColor = "Green")]
public IndicatorDataSeries Result2 { get; set; }
[Output("Result3", LineColor = "Red")]
public IndicatorDataSeries Result3 { get; set; }
[Output("Result4", LineColor = "Green")]
public IndicatorDataSeries Result4 { get; set; }
[Output("Result5", LineColor = "DimGray")]
public IndicatorDataSeries Result5 { get; set; }
[Output("Result6", LineColor = "DimGray")]
public IndicatorDataSeries Result6 { get; set; }
[Output("Result7", LineColor = "DimGray")]
public IndicatorDataSeries Result7 { get; set; }
[Output("Result8", LineColor = "DimGray")]
public IndicatorDataSeries Result8 { get; set; }
private Bars tf;
private int idx;
private int previousIdx;
private int buyPeriod;
private int sellPeriod;
private double buyAverage;
private double sellAverage;
private double minsp, maxbp;
private double minbp, maxsp;
protected override void Initialize()
{
tf = MarketData.GetBars(Bars.TimeFrame);
}
public override void Calculate(int index)
{
idx = tf.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
if (idx > previousIdx)
{
buyPeriod++;
sellPeriod++;
}
buyAverage = Bars.HighPrices.Sum(buyPeriod) / buyPeriod;
sellAverage = Bars.LowPrices.Sum(sellPeriod) / sellPeriod;
if (Bars.HighPrices[idx] >= buyAverage)
{
buyPeriod = 1;
buyAverage = Bars.HighPrices[idx];
}
if (Bars.LowPrices[idx] <= sellAverage)
{
sellPeriod = 1;
sellAverage = Bars.LowPrices[idx];
}
maxbp = Bars.HighPrices.Maximum(buyPeriod);
minbp = Bars.LowPrices.Minimum(buyPeriod);
maxsp = Bars.HighPrices.Maximum(sellPeriod);
minsp = Bars.LowPrices.Minimum(sellPeriod);
Result1[index] = buyAverage;
Result2[index] = sellAverage;
if (sellPeriod > buyPeriod)
{
Result3[index] = maxsp;
Result4[index] = minsp;
Result5[index] = maxsp - (maxsp - minsp) * 0.114;
Result6[index] = maxsp - (maxsp - minsp) * 0.236;
Result7[index] = maxsp - (maxsp - minsp) * 0.382;
Result8[index] = maxsp - (maxsp - minsp) * 0.5;
}
if (sellPeriod < buyPeriod)
{
Result3[index] = maxbp;
Result4[index] = minbp;
Result5[index] = minbp + (maxbp - minbp) * 0.114;
Result6[index] = minbp + (maxbp - minbp) * 0.236;
Result7[index] = minbp + (maxbp - minbp) * 0.382;
Result8[index] = minbp + (maxbp - minbp) * 0.5;
}
previousIdx = idx;
}
}
}
srm_bcn
Joined on 01.09.2019
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: HLAveragesBoxesOverlayFibo.algo
- Rating: 0
- Installs: 1447
- 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.
No comments found.