ClickAlgo Volatility Alert

by Paul_Hayes in category Volatility at 13/03/2015
Description

This indicator alerts user with message and sound when high volatility occurs, its also displays current spread and total depth of market volume for the buyers and sellers.    


Depth of Market

The Depth of Market is the total of all volume as shown below:

Volatility Alert with Warning Sound

Volatility Message With No Alert


You can show both the volatility and spread or just spread or just volatility, this can be selected from the parameters below.

INDICATOR PARAMETER

CURRENT FEATURES

  • Configure the volatility depending on your scalping requirements.
  • Sound alert, configurable on/off.
  • Position warning message anywhere on screen.
  • Configure color of warning text to suit your background color.
  • Option to display actual volatility amount in pips to be shown with message to show price movement
  • Show or hide volatility message
  • Show or hide the current bid/ask spread size.
  • Show or Hide Depth of Market (total)
  • Configure the color of the current spread size text.

* Use this Indicator with the Market Trading Clock http://ctdn.com/algos/indicators/show/687 to manage volatility when an exchange opens.


Visit Us

Phone: 0044 20 3289 6573

* All international calls are local rates (low cost)

www.ClickAlgo.com

Creative Trading with Technology

 facebook2  twitter  linkedIn  googlePlus  

 


 

Download
3246 downloads
How to install
Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgocTrader
// -------
// PURPOSE
// -------
// Alerts user when there is high volatility in the market over a period of seconds.
// Userful signal when not looking at charts or when not at computer, configurable audible sound alerts for each currency.
// Good for scalping.

// Author: Paul Hayes    
// Date:   24/12/2015
// Version 1.5
//
// Coding Guidlines: https://github.com/dotnet/corefx/wiki/Framework-Design-Guidelines-Digest
//
// Bug fix: display formatting issue.

using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ScalpersBuddy : Indicator
    {
        #region user defined parameters

        [Parameter("Alert ON", DefaultValue = true)]
        public bool AlertOn { get; set; }

        [Parameter("Sound ON", DefaultValue = true)]
        public bool PlaySound { get; set; }

        [Parameter("Volatility Pips", DefaultValue = 10, MaxValue = 20, MinValue = 1)]
        public int VolatilityPips { get; set; }

        [Parameter("Media File", DefaultValue = "c:\\windows\\media\\notify.wav")]
        public string MediaFile { get; set; }

        [Parameter("Display Position, 1-8", DefaultValue = 2, MinValue = 1, MaxValue = 3)]
        public int WarningPostion { get; set; }

        [Parameter("Warning Color", DefaultValue = "Red")]
        public string WarningColor { get; set; }

        [Parameter("Show Volatility", DefaultValue = true)]
        public bool ShowVolatility { get; set; }

        [Parameter("Show Spread", DefaultValue = true)]
        public bool ShowSpread { get; set; }

        [Parameter("Show Depth of Market", DefaultValue = true)]
        public bool ShowDepthOfMarket { get; set; }

        [Parameter("Spread Color", DefaultValue = "White")]
        public string SpreadColor { get; set; }

        #endregion

        #region Private properties

        private MarketSeries mSeries;
        private StaticPosition position;
        private Colors warningTextColor;
        private Colors spreadTextColor;
        private bool errorOccured = false;
        private string lowerPosition = string.Empty;
        private MarketDepth marketDepth;

        #endregion

        const string errorMsg = "\n\n\n\n\n Scalpers Buddy Indicator: An error has occurred, view log events window for more information.";


        #region cTrader Events

        protected override void Initialize()
        {
            try
            {
                // Get the time-frame series of data
                mSeries = MarketData.GetSeries(Symbol, TimeFrame.Minute);
                warningTextColor = (Colors)Enum.Parse(typeof(Colors), WarningColor, true);
                spreadTextColor = (Colors)Enum.Parse(typeof(Colors), SpreadColor, true);

                if (ShowDepthOfMarket)
                {
                    //  Get Market Depth
                    marketDepth = MarketData.GetMarketDepth(Symbol);

                    // subscribe to event Updated
                    marketDepth.Updated += MarketDepthUpdated;
                }

            } catch (Exception e)
            {
                errorOccured = true;
                Print("Scalpers Buddy: " + e.Message);
            }

            // position alert message on screen
            switch (WarningPostion)
            {
                case 1:
                    position = StaticPosition.TopLeft;
                    break;
                case 2:
                    position = StaticPosition.TopCenter;
                    break;
                case 3:
                    position = StaticPosition.TopRight;
                    break;
                case 4:
                    position = StaticPosition.Right;
                    lowerPosition = "\n\n";
                    break;
                case 5:
                    position = StaticPosition.BottomRight;
                    lowerPosition = "\n\n";
                    break;
                case 6:
                    position = StaticPosition.BottomCenter;
                    lowerPosition = "\n\n";
                    break;
                case 7:
                    position = StaticPosition.BottomLeft;
                    lowerPosition = "\n\n";
                    break;
                case 8:
                    position = StaticPosition.Left;
                    lowerPosition = "\n\n";
                    break;
                default:
                    position = StaticPosition.TopLeft;
                    break;
            }
        }

        public override void Calculate(int index)
        {
            if (errorOccured)
            {
                ChartObjects.DrawText("error-label", errorMsg, StaticPosition.TopCenter, Colors.Red);
                return;
            }

            // get the last highest price value
            double high = (mSeries.High.LastValue);
            // get the last lowest price value
            double low = (mSeries.Low.LastValue);

            // difference between high and low divided by the current instruments pip size = sudden movement in pips
            double pips = (high - low) / Symbol.PipSize;

            string pipsVolatility = "(Volatility: " + pips.ToString("0.00") + " pips)";

            // display error message to screen.
            if (ShowVolatility)
            {
                ChartObjects.DrawText("volatilityMsg", pipsVolatility += lowerPosition, position, spreadTextColor);
            }

            // if pip movement > volatility setting 
            if (Math.Ceiling(pips) > VolatilityPips)
            {
                if (AlertOn)
                {
                    ChartObjects.DrawText("alertMsg", pipsVolatility, position, warningTextColor);
                }

                if (PlaySound)
                {
                    if (MediaFile != string.Empty)
                        Notifications.PlaySound(MediaFile);
                }
            }
            else
            {
                ChartObjects.RemoveObject("alertMsg");
            }

            // if user wants to see the current bid/ask spread size, * feature separate from volatility alert.
            if (ShowSpread)
            {
                var spread = Math.Round(Symbol.Spread / Symbol.PipSize, 2);
                string s = string.Format("{0:N2}", spread);

                ChartObjects.DrawText("spreadMsg", "\nSpread: " + s, position, spreadTextColor);
            }
        }

        #endregion

        #region market depth

        private void MarketDepthUpdated()
        {
            double bidVolume = 0;
            double askVolume = 0;

            foreach (var entry in marketDepth.BidEntries)
            {
                double dVolume = Math.Round(entry.Volume / 1000000.0, 2);
                bidVolume += dVolume;
            }

            foreach (var entry in marketDepth.AskEntries)
            {
                double dVolume = Math.Round(entry.Volume / 1000000.0, 2);
                askVolume += dVolume;
            }

            ChartObjects.DrawText("Bid", "\n\n\nBuyers: " + bidVolume.ToString() + "m", position, Colors.Green);
            ChartObjects.DrawText("ask", "\n\nSellers: " + askVolume.ToString() + "m", position, Colors.Red);
        }

        #endregion
    }
}
Comments

GoldnOil - March 14, 2015 @ 22:39

Hi !

Can you add "user comments" to your code above.  will be useful to understand and give feedback on its working.

regards.

SKhan

Paul_Hayes - March 15, 2015 @ 19:38

Hi SKhan,

 

I will have it ready by Monday, it would be good if anybody could correct the logic if incorrect so that we have a good working tool for all to use, I am new to this industry and the cAlgo object model, so still learning its features.

Paul.

Paul_Hayes - March 16, 2015 @ 06:36

Hi,

As promised an updated version of this indicator has been uploaded together with additional error handling and a code clean up.

Paul.

Paul_Hayes - March 16, 2015 @ 07:50

NEW FEATURE: Show the current bid/ask spread size in pips on screen.

Paul_Hayes - April 19, 2015 @ 11:48

Update: Fixed the overlapping of displayed text when set in different positions

Paul_Hayes - April 24, 2015 @ 07:30

Update: Removed sound alert feature as this caused cTrader to freeze.

Paul_Hayes - April 28, 2015 @ 18:26

Sound alert re-added, after investigation it was found that this indicator did not freeze the platform.

TRADER100D1M - May 11, 2015 @ 02:34

I'm testing the indicator, thank you

TRADER100D1M - May 11, 2015 @ 14:20

Good morning, you have an indicator of reports that shows in the corner at the discretion of news and importance. Thank You Note: you can create it with the great quality of its indicators. SUCCESS for you

Paul_Hayes - May 11, 2015 @ 17:18

I could try and create an indicator that shows the next news release with importance and previous, consensus and actual result, this what you want?

 

TRADER100D1M - May 12, 2015 @ 06:49

Yes it would be great because then I would know the moment the news instance time left for her to leave

Paul_Hayes - May 12, 2015 @ 19:01

ok, i will try and add this as an optional feature

Paul_Hayes - May 13, 2015 @ 09:40

Hi trader100D1M,

you may want to use the dailyFX news release indicator, its very good and does what you want.

http://ctdn.com/algos/indicators/show/431

 

dimiaverilla - November 15, 2015 @ 06:20

Brilliant work mate. Thank you.

Paul_Hayes - December 24, 2015 @ 12:32

Update: Depth of market added, thanks to idea by Dimi

dimiaverilla - December 30, 2015 @ 06:58

Thanks Paul. This is one indicator I can't go without now. You're a champ.

tmc. - January 10, 2016 @ 22:19

I haven't tried this indicator but doesn't it spam emails with each tick when higher than defined volatility?

Paul_Hayes - January 11, 2016 @ 08:38

The idea was that it would send an email to the address you specify in the parameters of the indicator warning of high volatility on an instrument, so it is not spam.

But thank you for bringing the multiple emails to my attention, I have now removed the email feature as it was just a nice to have.

Serpico - September 28, 2016 @ 08:24

Hello Mr Paul.

 

Thanks for all your contributions to this comunity, Im not getting any accurate readings or data of market depth on Pepperstone

 

Thanks

4.17