Description
With Colors and current value
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo.Indicators
{
[Levels(0.0)]
[Indicator(IsOverlay = false, ScalePrecision = 5, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class OSMA : Indicator
{
[Parameter(DefaultValue = 12)]
public int shortCycle { get; set; }
[Parameter(DefaultValue = 26)]
public int longCycle { get; set; }
[Parameter(DefaultValue = 9)]
public int signalPeriod { get; set; }
[Output("Main", PlotType = PlotType.Histogram, LineColor = "green")]
public IndicatorDataSeries Result { get; set; }
[Output("Main2", PlotType = PlotType.Histogram, LineColor = "red")]
public IndicatorDataSeries Result2 { get; set; }
MacdHistogram macd;
ChartHorizontalLine hl;
ChartText ct;
protected override void Initialize()
{
macd = Indicators.MacdHistogram(shortCycle, longCycle, signalPeriod);
hl = IndicatorArea.DrawHorizontalLine("current", 0.0, Color.LightGray);
ct = IndicatorArea.DrawText("currentText", "0.0", Bars.LastBar.OpenTime, 0.0, Color.LightGray);
}
public override void Calculate(int index)
{
var result = macd.Signal[index] - macd.Histogram[index];
hl.Y = result;
ct.Text = "" + Math.Round(result, 2);
ct.Y = result;
ct.Time = Bars.LastBar.OpenTime;
if (result > 0)
{
Result[index] = result;
}
else
{
Result2[index] = result;
}
}
}
}
KA
kamilsz
Joined on 23.12.2020
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: Oscillator of Moving Average (OsMA) with Colors.algo
- Rating: 0
- Installs: 1618
- 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.