HOW CAN I DISPLAY ON MY CUSTOM INDICATOR ONLY NOT BROKEN BULLISH/BEARISH ENGULFING?
HOW CAN I DISPLAY ON MY CUSTOM INDICATOR ONLY NOT BROKEN BULLISH/BEARISH ENGULFING?
04 Jul 2023, 13:46
Hi, I would like to know how can I tell to my indicator to mark ONLY the bullish/bearish engulfing which aren't already taken out from the market, I will share a pic for a better understanding:
My code:
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(AccessRights = AccessRights.None)]
public class ENGULFING : Indicator
{
[Parameter(DefaultValue = 0.0)] // Parameter which don't have any function
public double Parameter { get; set; }
[Output("Main")]
public IndicatorDataSeries Result { get; set; }
protected override void Initialize()
{
}
public override void Calculate(int index)
{ // Two bool variables that contain the description of bullish and bearish Engulfing
var bullishEngulfing = Bars.HighPrices[index] > Bars.HighPrices[index - 1] && Bars.LowPrices[index] < Bars.LowPrices[index -1] && Bars.ClosePrices[index] > Bars.OpenPrices[index];
var bearishEngulfing = Bars.HighPrices[index] > Bars.HighPrices[index - 1] && Bars.LowPrices[index] < Bars.LowPrices[index -1] && Bars.ClosePrices[index]< Bars.OpenPrices[index];
if ( bullishEngulfing ) // I gave to the variable bullishEngulfing the value of 1 (if is true)
{
Result[index] = 1;
}
else if (bearishEngulfing) // I gave to the variable bearishEngulfing the value of -1 (if is true)
{
Result[index] = -1;
}
else // If none of the above codition are true the result will be 0
{
Result[index] = 0;
}
// Chart up arrow
if (Result[index] == 1)
{
Chart.DrawIcon(index.ToString(), ChartIconType.UpArrow, index, Bars.LowPrices[index] - 20 * Symbol.PipSize, "Green");
}
// Chart down arrow
if (Result[index] == -1)
{
Chart.DrawIcon(index.ToString(), ChartIconType.DownArrow, index, Bars.HighPrices[index] + 20 * Symbol.PipSize, "Red");
}
}
}
}
Thanks for reading until here, I reallly hope you can help me, have an awesome day :)
Replies
gabrielelimarilli
05 Jul 2023, 10:22
RE:
firemyst said:
One way to do it is you need to keep track of your engulfing candles. You might want to use something like two Dictionary<int,double>() objects (one for bull candles and one for bear candles) where the key is the "bar's index" and the value is the high/low of the price.
On every new bar:
1) check every value in the bullish dictionary
2) if current price > the price of an entry in the dictionary (each value), a) delete the indicator icon at the specified bar (the key value) and b) delete the key/value pair from the dictionary as you know you don't have to check it ever again.
3) repeat steps 1-2 above for the bearish dictionary
4) if the previous bar is a bullish engulfing candle add the bar's index as the "key" to the bullish dictionary with the high price as the "value"
5) if the previous bar is a bearish engulfing candle add the bar's index as the "key" to the bearish dictionary with the low price as the "value"
Hi, thank you so much for the answer, unfortunatly I'm a noob coder and I have no Idea how to do it, if you kindly can show me an example on how should be done in a pratical way I will be very thankfull to you :). Thanks again, have a nice day .
Just for curiosity, where did you learnt calgo so well?
@gabrielelimarilli
firemyst
05 Jul 2023, 03:23
One way to do it is you need to keep track of your engulfing candles. You might want to use something like two Dictionary<int,double>() objects (one for bull candles and one for bear candles) where the key is the "bar's index" and the value is the high/low of the price.
On every new bar:
1) check every value in the bullish dictionary
2) if current price > the price of an entry in the dictionary (each value), a) delete the indicator icon at the specified bar (the key value) and b) delete the key/value pair from the dictionary as you know you don't have to check it ever again.
3) repeat steps 1-2 above for the bearish dictionary
4) if the previous bar is a bullish engulfing candle add the bar's index as the "key" to the bullish dictionary with the high price as the "value"
5) if the previous bar is a bearish engulfing candle add the bar's index as the "key" to the bearish dictionary with the low price as the "value"
@firemyst