Category Other  Published on 15/12/2014

Exposure Currency

Description

// ----------------------------------------------------------------------------------------    
If you open multiple positions in a hedge strategy.

This indicator show volume exposure each currency to other currency.
// ----------------------------------------------------------------------------------------                                                                                                                                     

 

 


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

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class MijoExposureCurrencyView : Robot
    {
        private int MAX_PAIRS = 100;

        protected override void OnStart()
        {
            Timer.Start(1);
            //Calc_Exposure();
        }

        protected override void OnTick()
        {
            //Calc_Exposure();
        }

        protected override void OnTimer()
        {
            Calc_Exposure();
        }

        void Calc_Exposure()
        {
            string _used = "";
            string n = "\n";
            int _max_pairs = 0;
            int i = 0;
            double[] _exposure = new double[MAX_PAIRS];

            for (i = 0; i < MAX_PAIRS; i++)
            {
                _exposure[i] = 0;
            }

            for (i = (Positions.Count - 1); i >= 0; i--)
            {

                Symbol symbol = MarketData.GetSymbol(Positions[i].SymbolCode);
                string _pair = Positions[i].SymbolCode.Substring(0, 3);
                int _pi = _used.IndexOf(_pair, 0, _used.Length);

                if (_pi >= 0)
                {
                    _pi /= 3;
                }
                else
                {
                    _pi = _used.Length / 3;
                    _used = string.Concat(_used, _pair);
                    _max_pairs++;
                }

                if (Positions[i].TradeType == TradeType.Buy)
                {
                    _exposure[_pi] += Positions[i].Volume * symbol.TickSize;
                }
                else
                {
                    _exposure[_pi] -= Positions[i].Volume * symbol.TickSize;
                }

                _pair = Positions[i].SymbolCode.Substring(3, 3);
                _pi = _used.IndexOf(_pair, 0, _used.Length);

                if (_pi >= 0)
                {
                    _pi /= 3;
                }
                else
                {
                    _pi = _used.Length / 3;
                    _used = string.Concat(_used, _pair);
                    _max_pairs++;
                }

                if (Positions[i].TradeType == TradeType.Sell)
                {
                    _exposure[_pi] += Positions[i].Volume * symbol.TickSize * symbol.Bid;
                }
                else
                {
                    _exposure[_pi] -= Positions[i].Volume * symbol.TickSize * symbol.Ask;
                }
            }

            ChartObjects.DrawText("Mijo_Exposure", n + "-=Exposure=-", StaticPosition.TopLeft, Colors.Yellow);

            for (i = 0; i < _max_pairs; i++)
            {
                n = n + "\n";
                _exposure[i] = _exposure[i] * 1000;

                if (_used.Substring(i * 3, 3) == "JPY")
                {
                    _exposure[i] = _exposure[i] * 0.01;
                }

                if (_exposure[i] > 0)
                {
                    ChartObjects.DrawText("Mijo_Exposure_" + _used.Substring(i * 3, 3), n + " " + _used.Substring(i * 3, 3) + ": " + _exposure[i].ToString("0"), StaticPosition.TopLeft, Colors.Lime);
                }
                else
                {
                    if (_exposure[i] < 0)
                    {
                        ChartObjects.DrawText("Mijo_Exposure_" + _used.Substring(i * 3, 3), n + " " + _used.Substring(i * 3, 3) + ": " + _exposure[i].ToString("0"), StaticPosition.TopLeft, Colors.BlueViolet);
                    }
                    else
                    {
                        ChartObjects.DrawText("Mijo_Exposure_" + _used.Substring(i * 3, 3), n + " " + _used.Substring(i * 3, 3) + ": " + _exposure[i].ToString("0"), StaticPosition.TopLeft, Colors.Yellow);
                    }
                }
            }
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}


MI
mijo212

Joined on 12.10.2013

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: Mijo Exposure Currency View.algo
  • Rating: 0
  • Installs: 3166
  • Modified: 13/10/2021 09:54
Comments
Log in to add a comment.
BO
bojesim268 · 1 year ago

One of the more impressive blogs Ive seen. Thanks so much for keeping the internet classy for a change. Youve got style, class, bravado. I mean it. Please keep it up because without the internet is definitely lacking in intelligence.cummins EGR delete kit

BO
bojesim268 · 1 year ago

Hello! I just now would like to offer a huge thumbs up for the wonderful info you might have here on this post. I am returning to your website for additional soon.High Top Canvas Shoes

HE
hecar35256 · 1 year ago

Certain dissertation web sites over the internet courses currently have evidently unveiled while in the web-site.Wockhardt syrup

HE
heciraf296 · 1 year ago

You have outdone yourself this time. It is probably the best, most short step by step guide that I have ever seen. cash flow loans

TA
tariq254500 · 1 year ago

Good blog! I truly love how it is simple on my eyes and the data are well written. I’m wondering how I could be notified when a new post has been made. I have subscribed to your feed which must do the trick! Have a great day! link server sensasional

TA
tariq254500 · 1 year ago

contact lens are not only for fashion but it can also protect your eyes from dust and UV radiation. Sailing in Puerto Plata

NA
naveelansari525 · 1 year ago

Learn how you can find and get a copy of how to get my w2 online for free during the 2022 2023 tax filing season Many companies, including the military, have made their employee s W 2 forms easy to get online.

NA
naveelansari525 · 1 year ago

I must show thanks to this writer just for bailing me out of such a condition. Right after checking throughout the the web and seeing advice that were not helpful, I believed my entire life was done. Existing devoid of the solutions to the difficulties you have fixed through your good post is a critical case, as well as the kind that could have in a wrong way damaged my career if I hadn’t encountered your blog. Your primary talents and kindness in touching all the pieces was very useful. I am not sure what I would have done if I hadn’t come across such a step like this. I’m able to at this time relish my future. Thanks very much for this reliable and results-oriented help. I will not think twice to recommend the blog to anybody who desires guide about this area.slotzeus88

AB
abdullahjameel9137 · 1 year ago

Your blog is one of a kind, i love the way you organize the topics.”:*,, kolkata ff

KH
khatriboyz347 · 1 year ago

Get the best deals on Championship Rings for sale Buy champion rings from nba rings for sale, NFL rings and MLB rings at the most affordable price Free shipping worldwide.

ZU
zubairkhatri101 · 1 year ago

A helpful article that describes How To Calculate Percentage.For Explore more Please click here and visit us in our website for more details.

ZU
zubairkhatri101 · 1 year ago

A helpful article that describes How To Calculate Percentage.For Explore more Please click here and visit us in our website for more details.

ZU
zubairkhatri101 · 1 year ago

A helpful article that describes How To Calculate Percentage.For Explore more Please click here and visit us in our website for more details.

ZU
zubairkhatri101 · 1 year ago

I simply noticed your blog site in the past and i also have actually been looking through this task on a daily basis. There’s a great number of tips on this site we adore your look with all the web portal in addition. Support the excellent give good results!Tour guide in Riga

SI
siddiquekhirt123 · 1 year ago

That appears to be excellent however i am still not too sure that I like it. At any rate will look far more into it and decide personally!佐敦補習