price alarm

Created at 03 Jun 2013, 17:45
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
RE

remz

Joined 25.04.2013

price alarm
03 Jun 2013, 17:45


Dear Support,

I have found this price alarm indicator, /algos/indicators/show/203 , but it doesn't play the sound when it reaches the level. Would you have some solution for this problem? Or do you plan in the near future to build in a price alarm? I believe many traders would welcome an alarm. Thank you.

Regards,

Remz


@remz
Replies

cAlgo_Fanatic
05 Jun 2013, 10:11

It uses the windows file tada.wav which is located in the C:\Windows\Media folder. You can try increasing the volume or changing to any of the other files within this folder, since the sound of this file is very subtle.

If you need help with the code let us know.

We do have price alarms in our future plans.


@cAlgo_Fanatic

remz
05 Jun 2013, 10:51

RE:
cAlgo_Fanatic said:

It uses the windows file tada.wav which is located in the C:\Windows\Media folder. You can try increasing the volume or changing to any of the other files within this folder, since the sound of this file is very subtle.

If you need help with the code let us know.

We do have price alarms in our future plans.

You are right, it's very subtle. The volume is ok, I guess it's something else. I can't code, so I just changed the tada.wav to another file (kereslek.wav) from the same folder, saved and built the indicator.

Notifications.PlaySound(Path.Combine(windowsFolder, "Media", "kereslek.wav"));

The indi is working, but it still doesn't play the sound, so I guess it's not so simple. Is there any easy way to change the file, that a non-programmer could change or there might be some other problem?

Thank you!


@remz

cAlgo_Fanatic
05 Jun 2013, 14:33

The indicator has been tested and does play the sound. Are you adding a price level in the input parameters? If so, please send us all the parameters you are using with it so that we can test it again. Also, please make sure your speakers are working properly and the platform sound is ON.

In order to modify the code so that you can add the filename as an input parameter add the following code:

        // ...
        const Colors BidColor = Colors.Red;
        
        // Add New Input Variable "Filename"
        [Parameter(DefaultValue = "tada.wav")]
        public string Filename { get; set; }

        [Parameter()]
        public double Price { get; set; }
        // ...


and modify the code that plays the soundfile to this:

Notifications.PlaySound(Path.Combine(windowsFolder, "Media", Filename));



 


@cAlgo_Fanatic

remz
06 Jun 2013, 10:16

RE:
cAlgo_Fanatic said:

The indicator has been tested and does play the sound. Are you adding a price level in the input parameters? If so, please send us all the parameters you are using with it so that we can test it again. Also, please make sure your speakers are working properly and the platform sound is ON.

In order to modify the code so that you can add the filename as an input parameter add the following code:

        // ...
        const Colors BidColor = Colors.Red;
        
        // Add New Input Variable "Filename"
        [Parameter(DefaultValue = "tada.wav")]
        public string Filename { get; set; }

        [Parameter()]
        public double Price { get; set; }
        // ...


and modify the code that plays the soundfile to this:

Notifications.PlaySound(Path.Combine(windowsFolder, "Media", Filename));



 

Sound was on, speakers were ok, and I added price level, indi worked but still no sound. I deleted and downloaded again the indi, built it, now it is working perfectly, but I won't be able to (can't) modify the code and with this default sound it is of no use. Would you be able to change the uploaded price alarm indi to play some proper alarm sound, and play it until turned off manually?

Thank you! 


@remz

cAlgo_Fanatic
07 Jun 2013, 12:42

You already modified it earlier when you changed the filename :). Just copy the indicator (so you always have the original).

Try to modify the code according to the earlier post which explains how to make the filename an input parameter. 

Once again:

Add this code:

[Parameter(DefaultValue = "filename.wav")]
public string Filename { get; set; }

The above should be added outside of any method, e.g. where the other [Parameter] attributes are, for instance right before this:

[Parameter()]
public double Price { get; set; }

Then just like you modified to use a different filename 

Notifications.PlaySound(Path.Combine(windowsFolder, "Media", "kereslek.wav"));

Do the same but instead of "kereslek.wav" type Filename (without any quotes, Filename is a variable name)

So it should look like this:

Notifications.PlaySound(Path.Combine(windowsFolder, "Media", Filename));

Then when you add an instance you can provide the filename (which should be within the Media folder).

To start learning c# visit the following sites:

http://www.csharp-station.com/Tutorial.aspx

http://msdn.microsoft.com/en-us/library/67ef8sbd.aspx

 

 


@cAlgo_Fanatic

remz
07 Jun 2013, 16:32

RE:
cAlgo_Fanatic said:

You already modified it earlier when you changed the filename :). Just copy the indicator (so you always have the original).

Try to modify the code according to the earlier post which explains how to make the filename an input parameter. 

Once again:

Add this code:

[Parameter(DefaultValue = "filename.wav")]
public string Filename { get; set; }

The above should be added outside of any method, e.g. where the other [Parameter] attributes are, for instance right before this:

[Parameter()]
public double Price { get; set; }

Then just like you modified to use a different filename 

Notifications.PlaySound(Path.Combine(windowsFolder, "Media", "kereslek.wav"));

Do the same but instead of "kereslek.wav" type Filename (without any quotes, Filename is a variable name)

So it should look like this:

Notifications.PlaySound(Path.Combine(windowsFolder, "Media", Filename));

Then when you add an instance you can provide the filename (which should be within the Media folder).

To start learning c# visit the following sites:

http://www.csharp-station.com/Tutorial.aspx

http://msdn.microsoft.com/en-us/library/67ef8sbd.aspx

 

 

I modified it and I think it's working as it should, I can change the filename (see the attachment). However apart of the default tada.wav it doesn't play any sound, and I have tried 3 different ones. Anyway, thank you for the help!


@remz

daemon
19 Jun 2013, 12:40

It is meant to play anything in the Media folder(C:\Windows\Media). So the files you try need to be located there otherwise it won't find them. check for error messages in the log.

You can change the code to find the file in a different folder or just provide the path as an input.

Check this out:

/api/internals/inotifications/playsound-5292


@daemon

remz
24 Jun 2013, 10:45

RE:
daemon said:

It is meant to play anything in the Media folder(C:\Windows\Media). So the files you try need to be located there otherwise it won't find them. check for error messages in the log.

You can change the code to find the file in a different folder or just provide the path as an input.

Check this out:

/api/internals/inotifications/playsound-5292


Thank you for trying to help, but I also have other issues with C-trader and until all of them are fixed I will have to use MT4.


@remz

cAlgo_Fanatic
24 Jun 2013, 12:12

Hello,

We will consider adding a default sound file into the API. In the meantime:

It seems that you may be trying to access files in a folder other than the one used in the indicator you downloaded.
To confirm please modify the code to the sample code below so that you will be providing the full path.

Notifications.PlaySound(@"C:\SampleDestination\SampleSound.mp3");
// for instance with the above example it would be: 
Notifications.PlaySound(@"C:\Windows\Media\tada.wav");

What other issues are you having with cTrader? We appreciate and always take user feedback into consideration.


@cAlgo_Fanatic

remz
24 Jun 2013, 17:18

RE:
cAlgo_Fanatic said:

Hello,

We will consider adding a default sound file into the API. In the meantime:

It seems that you may be trying to access files in a folder other than the one used in the indicator you downloaded.
To confirm please modify the code to the sample code below so that you will be providing the full path.

Notifications.PlaySound(@"C:\SampleDestination\SampleSound.mp3");
// for instance with the above example it would be: 
Notifications.PlaySound(@"C:\Windows\Media\tada.wav");

What other issues are you having with cTrader? We appreciate and always take user feedback into consideration.

using System;
using System.IO;
using System.Collections.Generic;
using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AutoRescale = false)]
    public class PriceAlarmSound : Indicator
    {    
        const Colors AskColor = Colors.DeepSkyBlue;
        const Colors BidColor = Colors.Red;             
        
        [Parameter(DefaultValue = "filename.wav")]
        public string Filename { get; set; } 
        
        [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 = LineStyle.Lines)]
        public IndicatorDataSeries BidTarget { get; set; }

        [Output("Ask Target", Color = AskColor, LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries AskTarget { get; set; }
        
        [Output("Played Notification", Color = Colors.Gray, LineStyle = LineStyle.Lines)]
        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)
                MarketData.GetMarketDepth(Symbol).Updated += AnimateWarning;
            
            if (BidOrAsk == 1)
                spotPriceWasAbove = Symbol.Bid > Price;
            else
                spotPriceWasAbove = Symbol.Ask > Price;
                
            if (NotificationWasPlayed())
            {
                triggered = true;
            }
        }

        private void AnimateWarning()
        {
            if (tickCount++ % 2 == 0)
                ChartObjects.DrawText("warning", "Please specify the Price", StaticPosition.Center, Colors.Red);
            else
                ChartObjects.DrawText("warning", "Please specify the Price", StaticPosition.Center, Colors.White);
        }

        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 ? Symbol.Bid : Symbol.Ask;
                var distance = Math.Round(Math.Abs(Price - spotPrice) / Symbol.PipSize, 1);                    
                
                ChartObjects.DrawText("distance", " " + distance + " pips left", index, Price, VerticalAlignment.Center, HorizontalAlignment.Right, color);
                if (spotPriceWasAbove && spotPrice <= Price
                      || !spotPriceWasAbove && spotPrice >= Price)                
                {                    
                    var windowsFolder = Environment.GetFolderPath(Environment.SpecialFolder.Windows);
                    Notifications.PlaySound(Path.Combine(windowsFolder, "Media", Filename));
                    triggered = true;
                    FillLine(BidTarget, double.NaN);
                    FillLine(AskTarget, double.NaN);
                    FillLine(PlayedNotificationLine, Price);
                    ChartObjects.RemoveObject("distance");
                    PlayedNotifications.Add(CreateNotification());
                }                
            }
        }
        
        private void FillLine(IndicatorDataSeries dataSeries, double price)
        {
            for (var i = 0; i < MarketSeries.Close.Count; i++)
                dataSeries[i] = price;
        }
        
        private bool NotificationWasPlayed()
        {
            return PlayedNotifications.Contains(CreateNotification());
        }
        
        private Notification CreateNotification()
        {
            return new Notification()
            {
                Symbol = Symbol.Code,
                Price = Price,
                BidIsSpotPrice = BidOrAsk == 1
            };
        }
    }
        
    struct Notification
    {
        public string Symbol;
        public double Price;
        public bool BidIsSpotPrice;
    }
}

Hello Support,

this is the code I have in my C-algo, modified according to your earlier suggestions. I have the filename window line, where I can manually modify the filename. And it is working fine if I use the "tada.wav", but if I change it to any other file (and I only changed it to files that are in the same folder), it is working but does not play any sound.

My other issues with C-trader (I have a live account):

-the alarm sound should be running until switched off, not just a one time alerting. It's unlikely that I notice a one time notice when I am away from the computer, but if the sound is played continuously I will notice it.

-C-trader loses connection, happened several times. My internet connection is very good, I run bloomberg tv all day so I immediately know if there is any connection loss. It just loses connection and does not come back. I have to turn the program off and log back in.

-lack of historical data, you need years of data even on lower timeframes to see if a system could work

-I use Ichimoku Kinko Hyo, and neither that are available for download are fully functional. There should be the option to turn off certain elements (lines) if someone doesn't uses all of them. Plus the kumo cannot be filled.

-it is only a suggestion: in the quick trade execution settings, there could be another line. Like a breakeven value in pips. Or the best would be something, when the trade reaches X pips in profit the SL should be set to Y pips.

For all mentioned above I still have to use MT4 parallel to C-trader. I look at MT4 and I only use C-trader for execution, mainly for its quick trade option.

Thank you for your consideration.


@remz

cAlgo_Fanatic
28 Jun 2013, 18:04

About the connection problems we are working hard on fixing the few remaining issues and optimizing the platfoms even further.

More historical data will be added soon for backtesting.

A breakeven value is also under implementation.

 


@cAlgo_Fanatic

cAlgo_Fanatic
24 Jul 2013, 14:44

The backtesting period range has been expanded to 2.5 years for the major currency pairs. We plan to expand it more in the future. 


@cAlgo_Fanatic

halibard
20 Feb 2015, 18:50

Sorry to write this in your post, but I would like to know how can I make it to also send an e-mail but still play a sound? Thank you.


@halibard

Spotware
25 Feb 2015, 17:20

For sending emails you can use Notifications.SendEmail function.


@Spotware