Adding Pop-up Alert to Indicator
Adding Pop-up Alert to Indicator
15 Dec 2021, 23:54
Hi all,
I'm interested to modify a indicator I found in order to adjust with my trading style. The original indicator is [here].
I installed cAlgo.API.Alert to the indicator by using Visual Studio and modify the original code. I would like to get a pop-up alert whenever CCI line (green) is crossing Signal line (red). However, the pop up alert is not showing whenever the condition is meet. I don't have basic programming and just learn through forum and other online source. Is my code correct? If yes, is there any setting in ctrader that I should change so the pop up will show? Thank you in advance.
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
using cAlgo.API.Alert;
using cAlgo.API.Alert.Utility;
namespace cAlgo.Indicators
{
[Cloud("CCI Line", "Signal", Opacity = 0.4)]
[Levels(0)]
[Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AutoRescale = true, ScalePrecision = 3, AccessRights = AccessRights.None)]
public class CCI_TickVolume : Indicator
{
[Parameter("CCI Periods", DefaultValue = 30)]
public int cciPeriod { get; set; }
[Parameter("WWS Period", DefaultValue = 8)]
public int wwsPeriod { get; set; }
[Parameter("TickVolume EMA Period", DefaultValue = 10)]
public int tkePeriod { get; set; }
[Parameter("TickVolume DEMA Period", DefaultValue = 10)]
public int tkdPeriod { get; set; }
[Parameter("TickVolume TEMA Period", DefaultValue = 5)]
public int tktPeriod { get; set; }
[Output("Up Bar", LineColor = "#FFAEDFC8", PlotType = PlotType.Histogram, Thickness = 5)]
public IndicatorDataSeries upBar { get; set; }
[Output("Down Bar", LineColor = "#FFFFBBBD", PlotType = PlotType.Histogram, Thickness = 5)]
public IndicatorDataSeries downBar { get; set; }
[Output("CCI Line", LineColor = "#FF16BB47", PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries cciline { get; set; }
[Output("Signal", LineColor = "#FFFF3236")]
public IndicatorDataSeries wwsline { get; set; }
[Output("Level 0", LineColor = "#9d159d", LineStyle = LineStyle.LinesDots, Thickness = 1)]
public IndicatorDataSeries level0 { get; set; }
public IndicatorDataSeries tkv;
public IndicatorDataSeries _xOpen, _xClose, _xHigh, _xLow;
private IndicatorDataSeries UpTick, DnTick, TVI_Calculate;
private ExponentialMovingAverage EMA_UpTick;
private ExponentialMovingAverage EMA_DnTick;
private ExponentialMovingAverage DEMA_UpTick;
private ExponentialMovingAverage DEMA_DnTick;
private ExponentialMovingAverage TVI;
private CommodityChannelIndex cci;
private WellesWilderSmoothing cci_wws;
private double O, C, H, L;
protected override void Initialize()
{
var index = Bars.ClosePrices.Count - 1;
_xOpen = CreateDataSeries();
_xClose = CreateDataSeries();
_xHigh = CreateDataSeries();
_xLow = CreateDataSeries();
tkv = CreateDataSeries();
UpTick = CreateDataSeries();
DnTick = CreateDataSeries();
TVI_Calculate = CreateDataSeries();
cci = Indicators.CommodityChannelIndex(cciPeriod);
cci_wws = Indicators.WellesWilderSmoothing(cci.Result, wwsPeriod);
EMA_UpTick = Indicators.ExponentialMovingAverage(UpTick, tkePeriod);
EMA_DnTick = Indicators.ExponentialMovingAverage(DnTick, tkePeriod);
DEMA_UpTick = Indicators.ExponentialMovingAverage(EMA_UpTick.Result, tkdPeriod);
DEMA_DnTick = Indicators.ExponentialMovingAverage(EMA_DnTick.Result, tkdPeriod);
TVI = Indicators.ExponentialMovingAverage(TVI_Calculate, tktPeriod);
}
public override void Calculate(int index)
{
level0[index] = 0;
wwsline[index] = cci_wws.Result[index];
cciline[index] = cci.Result[index];
UpTick[index] = (Bars.TickVolumes[index] + (Bars.ClosePrices[index] - Bars.OpenPrices[index]) / Symbol.TickSize) / 2;
DnTick[index] = Bars.TickVolumes[index] - UpTick[index];
TVI_Calculate[index] = 100 * ((DEMA_UpTick.Result[index] - DEMA_DnTick.Result[index]) / (DEMA_UpTick.Result[index] + DEMA_DnTick.Result[index]));
tkv[index] = TVI.Result[index];
if (tkv.IsRising())
{
upBar[index] = cci.Result[index];
}
else
{
downBar[index] = cci.Result[index];
}
O = Bars.OpenPrices[index];
C = Bars.ClosePrices[index];
H = Bars.HighPrices[index];
L = Bars.LowPrices[index];
var xClose = (((Math.Min(O, C) + L) / 2) + ((Math.Max(O, C) + H) / 2)) / 2;
double xOpen;
if (index > 7)
xOpen = (_xOpen[index - 1] + _xClose[index - 1]) / 2;
else
xOpen = (O + C) / 2;
_xClose[index] = xClose;
_xOpen[index] = xOpen;
_xHigh[index] = Math.Max(Math.Max(H, xOpen), xClose);
_xLow[index] = Math.Min(Math.Min(L, xOpen), xClose);
//my modification
if (cciline[index - 1] > wwsline[index - 1] && cciline[index] < wwsline[index] )
Notifications.ShowPopup(Bars.TimeFrame, Symbol, "Sell", "CCI Crossover Signal", Symbol.Bid, "Overbought", Server.Time);
else if (cciline[index - 1] < wwsline[index - 1] && cciline[index] > wwsline[index] )
Notifications.ShowPopup(Bars.TimeFrame, Symbol, "Buy", "CCI Crossover Signal", Symbol.Bid, "Oversold", Server.Time);
}
}
}
Replies
agung.ghani
16 Dec 2021, 12:24
( Updated at: 16 Dec 2021, 15:13 )
RE:
amusleh said:
Hi,
Did you set your indicator access right to FullAccess? Its None, change it to FullAccess.
Great. It's working. Many thanks for your help.
However, I just realized that the pop up alert is repeated 4 times every time the indicator is triggered. I didn't see any loop condition in the code. What is the possible reason that pop up alert is triggered four times?
Best regards
@agung.ghani
amusleh
17 Dec 2021, 09:24
RE: RE:
agung.ghani said:
amusleh said:
Hi,
Did you set your indicator access right to FullAccess? Its None, change it to FullAccess.
Great. It's working. Many thanks for your help.
However, I just realized that the pop up alert is repeated 4 times every time the indicator is triggered. I didn't see any loop condition in the code. What is the possible reason that pop up alert is triggered four times?
Best regards
Hi,
You have to call the ShowPopup only once per bar, and only for new bars not for historical bars.
The popup will be shows as many times you call the ShowPopup method.
@amusleh
agung.ghani
17 Dec 2021, 20:34
RE: RE: RE:
amusleh said:
agung.ghani said:
amusleh said:
Hi,
Did you set your indicator access right to FullAccess? Its None, change it to FullAccess.
Great. It's working. Many thanks for your help.
However, I just realized that the pop up alert is repeated 4 times every time the indicator is triggered. I didn't see any loop condition in the code. What is the possible reason that pop up alert is triggered four times?
Best regards
Hi,
You have to call the ShowPopup only once per bar, and only for new bars not for historical bars.
The popup will be shows as many times you call the ShowPopup method.
How to call the the value per bar? Is there any example?
@agung.ghani
amusleh
20 Dec 2021, 10:08
Hi,
Please read the library Wiki, there you will find a sample: Proper Implementation · afhacker/ctrader-alert_popup Wiki (github.com)
@amusleh
amusleh
16 Dec 2021, 11:14
Hi,
Did you set your indicator access right to FullAccess? Its None, change it to FullAccess.
@amusleh