NONE TREND IS NOT PRINTING
NONE TREND IS NOT PRINTING
07 May 2024, 20:44
hello
am trying to make this code print TrendType.None, is it possible? NEED HELP
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.Indicators
{
[Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
public class ZupaTrend : Indicator
{
[Parameter("Period (10)", DefaultValue = 10, Group = "SuperTrend")]
public int inpPeriod { get; set; }
[Parameter("Multiplier (3)", DefaultValue = 3.0, Group = "SuperTrend")]
public double inpMultiplier { get; set; }
[Parameter("ShowContinualLine (yes)", DefaultValue = true, Group = "Additional")]
public bool inpShowContinualLine { get; set; }
[Output("Main", LineColor = "Gray", PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries outMain { get; set; }
[Output("UpTrend", LineColor = "Green", PlotType = PlotType.DiscontinuousLine, Thickness = 2)]
public IndicatorDataSeries outUpTrend { get; set; }
[Output("DownTrend", LineColor = "Red", PlotType = PlotType.DiscontinuousLine, Thickness = 2)]
public IndicatorDataSeries outDownTrend { get; set; }
private Supertrend _supertrend;
private double threshold = 1.0;
private int currentTrend = 0;
protected override void Initialize()
{
_supertrend = Indicators.Supertrend(inpPeriod, inpMultiplier);
}
public override void Calculate(int i)
{
if (i < inpPeriod)
{
return;
}
if (inpShowContinualLine == true)
{
outMain[i] = (!double.IsNaN(_supertrend.UpTrend[i]) ? _supertrend.UpTrend[i] : _supertrend.DownTrend[i]);
}
else
{
outMain[i] = double.NaN;
}
outUpTrend[i] = _supertrend.UpTrend[i];
outDownTrend[i] = _supertrend.DownTrend[i];
TrendType currentTrendType = GetCurrentTrendType(outUpTrend[i], outDownTrend[i]);
switch (currentTrendType)
{
case TrendType.Bullish:
Print("Bullish");
break;
case TrendType.Bearish:
Print("Bearish");
break;
case TrendType.None:
if (Math.Abs(_supertrend.UpTrend[i] - _supertrend.DownTrend[i]) <= threshold)
{
Print("None");
}
break;
}
}
private TrendType GetCurrentTrendType(double upTrend, double downTrend)
{
if (Bars.ClosePrices.Last() > _supertrend.UpTrend.Last())
{
return TrendType.Bullish;
}
else if (Bars.ClosePrices.Last() < _supertrend.DownTrend.Last())
{
return TrendType.Bearish;
}
else
{
double diff = Math.Abs(upTrend - downTrend);
if (diff <= threshold)
{
return TrendType.None;
}
if (currentTrend == 0)
{
currentTrend = 1;
}
else if (currentTrend == 1)
{
currentTrend = -1;
}
if (currentTrend == 1)
{
return TrendType.Bullish;
}
else if (currentTrend == -1)
{
return TrendType.Bearish;
}
}
return TrendType.None;
}
private enum TrendType
{
Bullish,
Bearish,
None
}
}
}
PanagiotisCharalampous
08 May 2024, 05:40
Hi there,
When do you expect this to happen? As far as I remember, one of these conditions will always be true
Best regards,
Panagiotis
@PanagiotisCharalampous