Category Trading  Published on 16/06/2024

MxFxBook Sentiment Widget Pane

Description

Hi,

Here's a Sentiment Widget Pane that updates once every minute.

 

A few things to note. The widget comes with built in links. 

  • The symbol link e.g. USDCAD opens a new detached pane with all the currency sentiment from myfxbook. Very nice!

 

  • Avoid the top row links (They can't be removed). The top banner links open inside the pane, requiring you to either change the currency to force a reset or wait a minute for auto-refresh. 

 

Enjoy!

 

Cheers,

Clark




 

 

 


// -------------------------------------------------------------------------------------------------
// Code by Naseem Regragui
// https://www.linkedin.com/in/naseemregragui/
// https://github.com/clarkregragui/
//
// Use at your own risk.
// -------------------------------------------------------------------------------------------------

using System.ComponentModel.DataAnnotations;
using cAlgo.API;
using cAlgo.API.Internals;
using System.Text.RegularExpressions;
using System.Linq;
using System;

namespace cAlgo.Plugins
{


    public enum CurrencyPairs
    {
        EURUSD = 1,
        GBPUSD = 2,
        USDJPY = 3,
        GBPJPY = 4,
        USDCAD = 5,
        EURAUD = 6,
        EURJPY = 7,
        AUDCAD = 8,
        AUDJPY = 9,
        AUDNZD = 10,
        AUDUSD = 11,
        CADJPY = 12,
        EURCAD = 13,
        EURCHF = 14,
        EURCZK = 15,
        EURGBP = 17,
        EURHUF = 18,
        EURNOK = 19,
        EURNZD = 20,
        EURPLN = 21,
        EURSEK = 22,
        EURTRY = 23,
        GBPCAD = 24,
        GBPCHF = 25,
        NZDCAD = 26,
        NZDJPY = 27,
        NZDUSD = 28,
        USDCHF = 29,
        USDCZK = 31,
        USDHUF = 34,
        USDMXN = 36,
        USDNOK = 37,
        USDPLN = 38,
        USDSEK = 40,
        USDSGD = 41,
        USDTHB = 42,
        USDTRY = 43,
        USDZAR = 45,
        CHFJPY = 46,
        AUDCHF = 47,
        GBPNZD = 48,
        NZDCHF = 49,
        XAGUSD = 50,
        XAUUSD = 51,
        CADCHF = 103,
        GBPAUD = 107,
        SGDJPY = 131,
        GBPNOK = 137,
        EURZAR = 1233,
        AUDSGD = 1234,
        GBPSEK = 1236,
        CHFSGD = 1245,
        EURSGD = 1246,
        GBPSGD = 1247,
        XAUGBP = 1815,
        NOKJPY = 1863,
        ZARJPY = 1893,
        GBPTRY = 2012,
        USDRUB = 2076,
        SEKJPY = 2090,
        EURMXN = 2114,
        XAUAUD = 2115,
        XAUEUR = 2119,
        XAUJPY = 2521,
        XAUCHF = 2603,
        GBPMXN = 2872,
        XAGAUD = 3005,
        NOKSEK = 3240,
        XAGEUR = 3473,
        XPTUSD = 5079,
        XPDUSD = 5435,
        USDCNH = 5779
    }


    [Plugin(AccessRights = AccessRights.None)]
    public class SentimentWebViewPlugin : Plugin
    {


        private WebView SentimentWebView = new();

        protected override void OnStart()
        {

            
            var block = Asp.SymbolTab.AddBlock("Community Sentiment");
            block.Index = 2;
            block.Height = 200;
            block.IsExpanded = true;
            Asp.SymbolTab.SymbolChanged += OnSymbolChangedEvent;

            block.Child = SentimentWebView;
            SentimentWebView.NavigateToStringAsync(GetWidget());


            Timer.Start(TimeSpan.FromMinutes(1));

         }
 
         protected override void OnTimer()
         {
            SentimentWebView.NavigateToStringAsync(GetWidget());
         }

        public void OnSymbolChangedEvent(AspSymbolChangedEventArgs args)
        {
            SentimentWebView.NavigateToStringAsync(GetWidget());
        }

        private string GetWidget()
        {

            string symbolname = Enum.GetNames(typeof(CurrencyPairs)).FirstOrDefault(cp => Regex.IsMatch(Asp.SymbolTab.Symbol.Name, $".*{cp}.*"));

            if (symbolname != null)
            {
                var parseResult = Enum.TryParse(symbolname, out CurrencyPairs activeSymbol);
                if (parseResult)
                {


                    var htmlWidget = @$"<HTML>
                <!-- myfxbook.com outlook widget - Start -->
                <div>
                    <script class=""powered"" type=""text/javascript""
                            src=""https://widgets.myfxbook.com/scripts/fxOutlook.js?type=0&symbols=,{(int)activeSymbol}""></script>
                </div>
                <div style=""font-size: 10px"">
                <a href=""https://www.myfxbook.com"" title="""" class=""myfxbookLink"" target=""_self"" rel=""noopener"">
                            Powered by Myfxbook.com</a>
                </div>
                <script type=""text/javascript"">showOutlookWidget()</script>
                <!-- myfxbook.com outlook widget - End -->
                </HTML>";

                    return htmlWidget;
                }
                else
                {
                    return "";
                }
            }
            else
            {
                return "";
            }
        }
    }
}

CL
Clark22

Joined on 17.05.2024

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: SentimentWebView_withSourceCode.algo
  • Rating: 5
  • Installs: 350
  • Modified: 16/06/2024 16:24
Comments
Log in to add a comment.
No comments found.