Description
Stoch Matrix.
This indicator increases the base period of the Stochastic (PercentK) based on the multiplier (Periods Multi STOCH) and continues to increase as many times as (Nbrs Stoch Load) is defined. In the end, the indicator creates a stochastic matrix.
Stochastics with values > 80 are in green, stochastics with values < 20 are in red, and the rest are in blue.
The stochastic in the middle (visible lines) represents the average of all Stochastic.
The goal is to make this indicator performant while maintaining the ability to create 1000 matrix lines.
If someone know how to make it more faster, you Welcome.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo
{
[Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class STOCHALLINONELoadMore : Indicator
{
//[Parameter("Nbrs Stoch Load ", DefaultValue = 28, Group = " Ribbon/BarsColors Setting")]
//public int NbrsStochLoad { get; set; }
[Parameter("Percent K", DefaultValue = 9, Group = "Stoch Setting")]
public int PeriodK { get; set; }
[Parameter("Percent K", DefaultValue = 3, Group = "Stoch Setting")]
public int PeriodD { get; set; }
[Parameter("Percent K", DefaultValue = 9, Group = "Stoch Setting")]
public int KSlowing { get; set; }
[Parameter("Nbrs Stoch Load", DefaultValue = 25, Group = "Nbrs Load")]
public int StochLoad { get; set; }
[Parameter("Periods Multi STOCH ", DefaultValue = 1.1, Group = "Nbrs Load")]
public double PeriodsMulti { get; set; }
[Parameter("Extra Level", DefaultValue = 80, Group = "Extra Level")]
public int HighLevel { get; set; }
[Parameter("Extra Level", DefaultValue = 20, Group = "Extra Level")]
public int LowLevel { get; set; }
[Output("Result", PlotType = PlotType.Line, LineColor = "Green", Thickness = 1)]
public IndicatorDataSeries Result { get; set; }
[Output("Signal", PlotType = PlotType.Line, LineColor = "Red", Thickness = 1)]
public IndicatorDataSeries Signal { get; set; }
private StochasticOscillator[] stoch;
private IndicatorDataSeries[] resK, resD;
public IndicatorDataSeries totalLoad;
private int[] periodsStoch;
private double resIndicatorK, resIndicatorD, load;
protected override void Initialize()
{
resK = new IndicatorDataSeries[StochLoad];
resD = new IndicatorDataSeries[StochLoad];
stoch = new StochasticOscillator[StochLoad];
periodsStoch = new int[StochLoad];
totalLoad = CreateDataSeries();
resIndicatorK = 0.00;
resIndicatorD = 0.00;
load = 100 / StochLoad;
for (int i = 0; i < resK.Length; i++)
{
periodsStoch[i] = (int)(Math.Round(Math.Pow(PeriodsMulti, i) * PeriodK));
resK[i] = CreateDataSeries();
resD[i] = CreateDataSeries();
stoch[i] = Indicators.StochasticOscillator(Bars, periodsStoch[i], PeriodD, KSlowing, MovingAverageType.Simple);
}
}
public override void Calculate(int index)
{
resIndicatorK = 0.00;
resIndicatorD = 0.00;
for (int i = 0; i < resK.Length; i++)
{
resK[i][index] = stoch[i].PercentK[index];
resD[i][index] = stoch[i].PercentD[index];
if (!double.IsNaN(resK[i][index]))
{
if (resK[i][index] >= 80)
{
if (IndicatorArea.FindObject("stoch" + i + index) != null)
IndicatorArea.RemoveObject("stoch" + i + index);
IndicatorArea.DrawTrendLine("stoch" + i + index, index, i * load, index - 1, i * load, Color.FromArgb(100, "8901FF01"), 5, LineStyle.DotsVeryRare);
}
else if (resK[i][index] < 80 && resK[i][index] >= 50)
{
if (IndicatorArea.FindObject("stoch" + i + index) != null)
IndicatorArea.RemoveObject("stoch" + i + index);
IndicatorArea.DrawTrendLine("stoch" + i + index, index, i * load, index - 1, i * load, Color.FromArgb(100,"8C02AFF1"), 5, LineStyle.DotsVeryRare);
}
else if (resK[i][index] < 50 && resK[i][index] >= 20)
{
if (IndicatorArea.FindObject("stoch" + i + index) != null)
IndicatorArea.RemoveObject("stoch" + i + index);
IndicatorArea.DrawTrendLine("stoch" + i + index, index, i * load, index - 1, i * load, Color.FromArgb(100,"A3FF6000"), 5, LineStyle.DotsVeryRare);
}
else if (resK[i][index] < 20)
{
if (IndicatorArea.FindObject("stoch" + i + index) != null)
IndicatorArea.RemoveObject("stoch" + i + index);
IndicatorArea.DrawTrendLine("stoch" + i + index, index, i * load, index - 1, i * load, Color.FromArgb(100,"A3FF6000"), 5, LineStyle.DotsVeryRare);
}
resIndicatorK += resK[i][index];
resIndicatorD += resD[i][index];
}
}
if (index == periodsStoch[resK.Length - 1])
IndicatorArea.DrawVerticalLine("StartIndicator" + index, index, "8901FF01", 5, LineStyle.DotsVeryRare);
Result[index] = (resIndicatorK / StochLoad);
Signal[index] = (resIndicatorD / StochLoad);
}
}
}
YE
YesOrNot
Joined on 10.10.2022 Blocked
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: Stoch Matrix.algo
- Rating: 0
- Installs: 398
- Modified: 12/12/2023 21:38
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.
I andrea, i just add the description.