120
121
122
using System;
using [Link];
using [Link];
using [Link];
using [Link];
namespace [Link]
{
[Indicator(IsOverlay = true, AutoRescale = false, AccessRights =
[Link])]
public class PriceAlarmSound : Indicator
{
const Colors AskColor = [Link];
const Colors BidColor = [Link];
[Parameter()]
public double Price { get; set; }
[Parameter("Spot price (Bid: 1, Ask: 2)", DefaultValue = 1, MinValue = 1,
MaxValue = 2)]
public double BidOrAsk { get; set; }
[Output("Bid Target", Color = BidColor, LineStyle = [Link])]
public IndicatorDataSeries BidTarget { get; set; }
[Output("Ask Target", Color = AskColor, LineStyle = [Link])]
public IndicatorDataSeries AskTarget { get; set; }
[Output("Played Notification", Color = [Link], LineStyle =
[Link])]
public IndicatorDataSeries PlayedNotificationLine { get; set; }
bool spotPriceWasAbove;
int tickCount;
bool triggered;
static HashSet<Notification> PlayedNotifications = new
HashSet<Notification>();
protected override void Initialize()
{
if (Price == 0)
[Link](Symbol).Updated += AnimateWarning;
if (BidOrAsk == 1)
spotPriceWasAbove = [Link] > Price;
else
spotPriceWasAbove = [Link] > Price;
if (NotificationWasPlayed())
{
triggered = true;
}
}
private void AnimateWarning()
{
if (tickCount++ % 2 == 0)
[Link]("warning", "Please specify the Price",
[Link], [Link]);
else
[Link]("warning", "Please specify the Price",
[Link], [Link]);
}
public override void Calculate(int index)
{
if (triggered)
{
PlayedNotificationLine[index] = Price;
return;
}
if (BidOrAsk == 1)
BidTarget[index] = Price;
else
AskTarget[index] = Price;
if (IsRealTime)
{
var color = BidOrAsk == 1 ? BidColor : AskColor;
var spotPrice = BidOrAsk == 1 ? [Link] : [Link];
var distance = [Link]([Link](Price - spotPrice) /
[Link], 1);
[Link]("distance", " " + distance + " pips left",
index, Price, [Link], [Link], color);
if (spotPriceWasAbove && spotPrice <= Price || !spotPriceWasAbove
&& spotPrice >= Price)
{
var windowsFolder =
[Link]([Link]);
[Link]([Link](windowsFolder, "Media",
"[Link]"));
triggered = true;
FillLine(BidTarget, [Link]);
FillLine(AskTarget, [Link]);
FillLine(PlayedNotificationLine, Price);
[Link]("distance");
[Link](CreateNotification());
}
}
}
private void FillLine(IndicatorDataSeries dataSeries, double price)
{
for (var i = 0; i < [Link]; i++)
dataSeries[i] = price;
}
private bool NotificationWasPlayed()
{
return [Link](CreateNotification());
}
private Notification CreateNotification()
{
return new Notification
{
Symbol = [Link],
Price = Price,
BidIsSpotPrice = BidOrAsk == 1
};
}
}
struct Notification
{
public string Symbol;
public double Price;
public bool BidIsSpotPrice;
}
}