0% found this document useful (0 votes)
81 views3 pages

Price Alarm Sound Indicator Code

This C# code defines a PriceAlarmSound indicator class that plays a sound notification when the market price reaches a specified price level. It takes parameters for the price level and whether it refers to the bid or ask price. It draws target lines and animates text to show the distance to the target. When the price crosses the target, it plays a sound, fills the target lines, and records that a notification was triggered to prevent duplicate alerts.

Uploaded by

GayanAsanka
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views3 pages

Price Alarm Sound Indicator Code

This C# code defines a PriceAlarmSound indicator class that plays a sound notification when the market price reaches a specified price level. It takes parameters for the price level and whether it refers to the bid or ask price. It draws target lines and animates text to show the distance to the target. When the price crosses the target, it plays a sound, fills the target lines, and records that a notification was triggered to prevent duplicate alerts.

Uploaded by

GayanAsanka
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

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;
}
}

You might also like