Market analyzer outputs 1 when I don't want.
I have identified 2 high swings on MACD line, if the last swing is smaller in value then the previous one, then market analyzer returns 1, which is what I want. First I thought it works perfect, but soon realized that 1 is also returned when last swing is higher in value than the previou one, which is what I don't want.
Here's the code:
protected override void Initialize() { Add(new Plot(Color.Green, PlotStyle.Line, "Plot0")); CalculateOnBarClose = true; } protected override void OnBarUpdate() { //Last swing: int prevMacdHighBar = Swing(MACD(12, 25, 9).Avg, 2).SwingHighBar(0,1,150); double prevMacdHigh = Swing(MACD(12, 25, 9).Avg, 2).SwingHigh[prevMacdHighBar]; //Previous swing: int prevMacdHighBar2 = Swing(MACD(12, 25, 9).Avg, 2).SwingHighBar(0,2,150); double prevMacdHigh2 = Swing(MACD(12, 25, 9).Avg, 2).SwingHigh[prevMacdHighBar2]; if (prevMacdHigh2 > prevMacdHigh) { Plot0.Set(1); } }
This test is carried out on each bar and even if in the past the "prevMacdHigh2 > prevMacdHigh" was true, but it's not true on the last 2 swings then I don't want 1 in the market analyzer.
Please advise
Comment