Engulfing Indicator Help

Created at 12 Jul 2017, 15:22
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
ST

Storm31

Joined 10.10.2016

Engulfing Indicator Help
12 Jul 2017, 15:22


I would gratly appreciate if anyone could help with some simple code that would chage the codde below to show Rngullfing Bars instead of Inside Bars?

Thanks in advance ot anyone that can help.

 

using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
 
namespace cAlgo
{
 
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class InsideBarPatternRecognition : Indicator
    {
        [Output("Up Point", Color = Colors.Orange, PlotType = PlotType.Points, Thickness = 5)]
        public IndicatorDataSeries UpPoint { get; set; }
        [Output("Down Point", Color = Colors.Orange, PlotType = PlotType.Points, Thickness = 5)]
        public IndicatorDataSeries DownPoint { get; set; }
 
        public override void Calculate(int index)
        {
            var motherCandleHigh = MarketSeries.High.Last(2);
            var motherCandleLow = MarketSeries.Low.Last(2);
            var motherCandleOpen = MarketSeries.Open.Last(2);
            var motherCandleClose = MarketSeries.Close.Last(2);
 
            var childCandleHigh = MarketSeries.High.Last(1);
            var childCandleLow = MarketSeries.Low.Last(1);
            var childCandleOpen = MarketSeries.Open.Last(1);
            var childCandleClose = MarketSeries.Close.Last(1);
 
            if (childCandleHigh < motherCandleHigh && childCandleLow > motherCandleLow && Math.Abs(motherCandleOpen - motherCandleClose) > Math.Abs(childCandleOpen - childCandleClose))
                DrawPoint(index);
        }
// Draws a point next to the parent bar
        private void DrawPoint(int index)
        {
            UpPoint[index - 2] = MarketSeries.High[index - 2] + 0.0005;
            DownPoint[index - 2] = MarketSeries.Low[index - 2] - 0.0005;
        }
    }
}


@Storm31
Replies

croucrou
14 Jul 2017, 21:46

RE:
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
 
namespace cAlgo
{
 
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class InsideBarPatternRecognition : Indicator
    {
        [Output("Up Point", Color = Colors.Orange, PlotType = PlotType.Points, Thickness = 5)]
        public IndicatorDataSeries UpPoint { get; set; }
        [Output("Down Point", Color = Colors.Orange, PlotType = PlotType.Points, Thickness = 5)]
        public IndicatorDataSeries DownPoint { get; set; }
 
        public override void Calculate(int index)
        {
            var motherCandleHigh = MarketSeries.High.Last(1);
            var motherCandleLow = MarketSeries.Low.Last(1);
            var motherCandleOpen = MarketSeries.Open.Last(1);
            var motherCandleClose = MarketSeries.Close.Last(1);
 
            var childCandleHigh = MarketSeries.High.Last(2);
            var childCandleLow = MarketSeries.Low.Last(2);
            var childCandleOpen = MarketSeries.Open.Last(2);
            var childCandleClose = MarketSeries.Close.Last(2);
 
            if (childCandleHigh < motherCandleHigh && childCandleLow > motherCandleLow && Math.Abs(motherCandleOpen - motherCandleClose) > Math.Abs(childCandleOpen - childCandleClose))
                DrawPoint(index);
        }
// Draws a point next to the parent bar
        private void DrawPoint(int index)
        {
            UpPoint[index - 2] = MarketSeries.High[index - 2] + 0.0005;
            DownPoint[index - 2] = MarketSeries.Low[index - 2] - 0.0005;
        }
    }
}

 


@croucrou

firemyst
24 Feb 2020, 06:36

I don't believe these code samples are correct.

For example, with the Engulfing candle, the body of the second candle must engulf the entire body of the first.

However, according to the code, it's just checking that the length of the first body is less than the length of the second candle's body.

Here's an example where the code will return "true" for an engulfing candle, but it technically isn't since the body of the bigger candle doesn't engulf the first.

Treat the plus (+) signs as the body, and the pipes (|) as the wicks.

Yes, the second candle's body is longer than the first, but body doesn't engulf the first:

1st   2nd

        |

|      +

|      +

|      +

+     |

|      |

       |

 

So, to correct the code above, I believe the above code samples need to check that the opening and closing prices of the first candle also fall within the opening/closing prices of the second candle.

Similarly with the Inide Candle -- the body of the second candle must fall within the open/close of the first candle, not just be smaller.

Unless someone else has a different understanding?

 

 

 


@firemyst