Oscillator of Moving Average (OsMA) v2 free

by kamilsz in category Trend at 04/01/2021
Description

With Colors and current value

Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgocTrader
´╗┐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;
            }
        }
    }
}
Comments
0