Needed a popup with this indicator
Created at 07 Aug 2020, 16:36
VI
Needed a popup with this indicator
07 Aug 2020, 16:36
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
using System.Collections.Generic;
using System.Net;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.Internet)]
public class AlertForIndicator : Indicator
{
[Parameter("Fast Line", Group = "Source")]
public DataSeries Fast { get; set; }
[Parameter("Slow Line", Group = "Source")]
public DataSeries Slow { get; set; }
[Parameter("Long Signal", Group = "Signal", DefaultValue = false)]
public bool Long { get; set; }
[Parameter("Short Signal", Group = "Signal", DefaultValue = false)]
public bool Short { get; set; }
[Parameter("Arrow on Chart", Group = "Signal", DefaultValue = true)]
public bool Arrow { get; set; }
[Parameter("Backtest", Group = "Signal", DefaultValue = false)]
public bool Bckt { get; set; }
[Parameter("Email", Group = "Notification", DefaultValue = false)]
public bool SendEmail { get; set; }
[Parameter("Telegram", Group = "Notification")]
public bool SendTelegram { get; set; }
[Parameter("Sound ON", Group = "Notification", DefaultValue = true)]
public bool PlaySound { get; set; }
[Parameter("Media File Location", Group = "Notification", DefaultValue = "c:\\windows\\media\\Alarm01.Wav")]
public string MediaFile { get; set; }
[Parameter("From", Group = "Email", DefaultValue = "from@example.com")]
public string Sender { get; set; }
[Parameter("To", Group = "Email", DefaultValue = "to@example.com")]
public string Receiver { get; set; }
[Parameter("Subject", Group = "Email", DefaultValue = "my subject")]
public string Subject { get; set; }
[Parameter("Message", Group = "Email", DefaultValue = "")]
public string EmailBody { get; set; }
[Parameter("ChatId", Group = "Telegram", DefaultValue = "")]
public string ChatId { get; set; }
[Parameter("Token", Group = "Telegram", DefaultValue = "")]
public string BotToken { get; set; }
[Parameter("Cross Up Color", Group = "Colors", DefaultValue = "Lime")]
public string ColorArrowUP { get; set; }
[Parameter("Cross Down Color", Group = "Colors", DefaultValue = "Orange")]
public string ColorArrowDW { get; set; }
string TelgramURL;
protected override void Initialize()
{
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
TelgramURL = string.Format("https://api.telegram.org/bot{0}/sendMessage?chat_id={1}&text=", BotToken, ChatId);
}
int LastBar = 0;
public override void Calculate(int index)
{
if (index <= LastBar)
return;
LastBar = index;
string message = Symbol.Name + "\n" + Symbol.Bid + "\n" + TimeFrame;
if (Long && Fast.HasCrossedAbove(Slow, 0))
{
if (PlaySound)
Notifications.PlaySound(MediaFile);
if (SendEmail)
Notifications.SendEmail(Sender, Receiver, Subject, EmailBody + " " + message + " " + "Cross Long Signal");
if (Arrow)
Chart.DrawIcon(Bckt ? "Up" + index : "Up", ChartIconType.UpArrow, index, Bars[LastBar - 5].Low, Color.FromName(ColorArrowUP));
if (SendTelegram)
SendMessage(message + "\n" + "Cross Long Signal" + "\n" + EmailBody);
}
else if (Short && Fast.HasCrossedBelow(Slow, 0))
{
if (PlaySound)
Notifications.PlaySound(MediaFile);
if (SendEmail)
Notifications.SendEmail(Sender, Receiver, Subject, EmailBody + " " + message + " " + "Cross Short Signal");
if (Arrow)
Chart.DrawIcon(Bckt ? "Down" + index : "Down", ChartIconType.DownArrow, index, Bars[LastBar - 5].High, Color.FromName(ColorArrowDW));
if (SendTelegram)
SendMessage(message + "\n" + "Cross Short Signal" + "\n" + EmailBody);
}
}
void SendMessage(string s)
{
var request = WebRequest.Create(TelgramURL + s);
request.ContentType = "application/x-www-form-urlencoded";
request.Method = "POST";
var response = request.GetResponse();
}
}
}
Hi
This is a simple alert indicator but the popup option is not added in this script, can somebody help me with that, needed a popup script included in the script.
PanagiotisCharalampous
10 Aug 2020, 07:50
Hi vikkineshwar,
You can use a MessageBox for this task.
Best Regards,
Panagiotis
Join us on Telegram
@PanagiotisCharalampous