Category Other  Published on 27/07/2024

Arbitrage (EDUCATIONAL EXEMPLE)

Description

Warning: This indicator shows the possibilities of arbitrage but does not take exact values into account.

Try it on a 5/10 tick chart Maximum, to get an idea of what can be done in one days with this method.

 

What is Triangular Arbitrage?

Triangular arbitrage is a technique primarily used in the foreign exchange (Forex) markets, where an investor exploits the differences in exchange rates between three different currencies to make a profit. Here’s a simple explanation:

Three Currencies:

  • Triangular arbitrage involves three different currencies, for example, the euro (EUR), the US dollar (USD), and the Japanese yen (JPY).

Difference in Exchange Rates:

  • The investor identifies a difference in exchange rates between these three currencies. For example, the direct exchange rate between the euro and the yen might differ from the rate obtained by going through the US dollar.

Sequence of Trades:

  • The investor performs a series of trades to profit from this difference. Suppose they start with euros:
    1. Exchange EUR to USD: They convert euros to US dollars.
    2. Exchange USD to JPY: They convert the US dollars obtained into Japanese yen.
    3. Exchange JPY to EUR: Finally, they convert the Japanese yen back into euros.

Profit:

  • If the exchange rates are favorable, the investor ends up with more euros than they started with, thus making a risk-free profit.

Example:

Imagine the following exchange rates:

  • 1 EUR = 1.20 USD
  • 1 USD = 110 JPY
  • 1 EUR = 130 JPY

The investor starts with 1000 EUR:

Exchange EUR to USD:

  • 1000 EUR * 1.20 = 1200 USD

Exchange USD to JPY:

  • 1200 USD * 110 = 132,000 JPY

Exchange JPY to EUR:

  • 132,000 JPY / 130 = 1015.38 EUR

The investor now has 1015.38 EUR, making a profit of 15.38 EUR.

Summary:

Triangular arbitrage involves taking advantage of differences in exchange rates between three currencies by performing a series of trades. Starting with one currency, converting it successively into two others, and returning to the initial currency, the investor can make a risk-free profit if the exchange rates are favorable. This technique also contributes to the efficiency of foreign exchange markets by correcting exchange rate imbalances.

Enjoy for Free =) 
Previous account here : https://ctrader.com/users/profile/70920
Contact telegram :  https://t.me/nimi012 


/*

//////////////////////  ATTENTION \\\\\\\\\\\\\\\\\\\\\\\\\

Note that this indicator does not display the exact profit values but gives an idea of the possibility of triangular arbitrage.
For this indicator to be perfect, it should take into account the Ask and Bid prices, commissions, and maximum latency time.

*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Levels(0, 10, 25, 50)]
    [Indicator(AccessRights = AccessRights.None)]
    public class Arbitrage : Indicator
    {
        [Parameter("Symbol List", DefaultValue = "EURUSD", Group = "Symbol Management")]
        public string Symbol1 { get; set; }
        [Parameter("Symbol List", DefaultValue = "USDJPY", Group = "Symbol Management")]
        public string Symbol2 { get; set; }
        [Parameter("Symbol List", DefaultValue = "EURJPY", Group = "Symbol Management")]
        public string Symbol3 { get; set; }

        [Parameter("Symbol List", DefaultValue = EnumCalculation.See_Profit, Group = "Symbol Management")]
        public EnumCalculation Calculation { get; set; }

        public enum EnumCalculation
        {
            Is_It_Arbitrable,
            See_Profit,
        }

        [Parameter("Inital Amount", DefaultValue = 100000, Group = "See Profit")]
        public int InitalAmount { get; set; }

        [Output("Result")]
        public IndicatorDataSeries Result { get; set; }

        private Bars symb1, symb2, symb3;

        protected override void Initialize()
        {
            symb1 = MarketData.GetBars(TimeFrame, Symbol1);
            symb2 = MarketData.GetBars(TimeFrame, Symbol2);
            symb3 = MarketData.GetBars(TimeFrame, Symbol3);
            if (!IsBacktesting)
            {
                while (symb1.OpenTimes[0] > Bars.OpenTimes[0])
                    symb1.LoadMoreHistory();
                while (symb2.OpenTimes[0] > Bars.OpenTimes[0])
                    symb2.LoadMoreHistory();
                while (symb3.OpenTimes[0] > Bars.OpenTimes[0])
                    symb3.LoadMoreHistory();
            }
        }
        public override void Calculate(int index)
        {
            var indexSymbol1 = symb1.OpenTimes.GetIndexByTime(Bars.OpenTimes.Last(0));
            var indexSymbol2 = symb2.OpenTimes.GetIndexByTime(Bars.OpenTimes.Last(0));
            var indexSymbol3 = symb3.OpenTimes.GetIndexByTime(Bars.OpenTimes.Last(0));

            double rateSymbol1 = symb1.ClosePrices[indexSymbol1];
            double rateSymbol2 = symb2.ClosePrices[indexSymbol2];
            double rateSymbol3 = symb3.ClosePrices[indexSymbol3];

            double impliedRateSymbol3 = rateSymbol1 * rateSymbol2;
            double isItArbitrable = impliedRateSymbol3 - rateSymbol3;

            double amountSymbol1 = InitalAmount * symb1.ClosePrices[indexSymbol1];
            double amountSymbol2 = amountSymbol1 * symb2.ClosePrices[indexSymbol2];
            double finalAmount = amountSymbol2 / symb3.ClosePrices[indexSymbol3];

            double profit = finalAmount - InitalAmount;

            Result[index] = Calculation == EnumCalculation.Is_It_Arbitrable ? isItArbitrable : profit;

            IndicatorArea.DrawStaticText("Attention", "------->   ATTENTION   <-------  \nNote that this indicator does not display the exact profit values but gives an idea of the possibility of triangular arbitrage.\nFor this indicator to be perfect, it should take into account the Ask and Bid prices, commissions, and maximum latency time.", VerticalAlignment.Bottom, HorizontalAlignment.Center, Color.Red);

        }
    }
}

YE
YesOrNot2

Joined on 17.05.2024

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: Arbitrage.algo
  • Rating: 5
  • Installs: 271
  • Modified: 27/07/2024 09:23
Comments
Log in to add a comment.
No comments found.