Category Trend  Published on 20/06/2019

Relative Forces

Description

Follow my cTrader Telegram group at https://t.me/cTraderCommunity; it's a new community but it will grow fast, plus everyone can talk about cTrader indicators and algorithm without restrictions, though it is not allowed to spam commercial indicators to sell them.

This indicator shows a comparison between the chosen symbols.

The comparison can be made only across a certain period of time or across the whole history.


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

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AutoRescale = true, AccessRights = AccessRights.None)]
    public class ForzaRelativa : Indicator
    {
        [Parameter("Periodi", DefaultValue = 48)]
        public int per { get; set; }

        [Parameter("Symbol 1", DefaultValue = "EURUSD")]
        public string sim1 { get; set; }


        [Parameter("Symbol 2", DefaultValue = "USDJPY")]
        public string sim2 { get; set; }


        [Parameter("Symbol 3", DefaultValue = "EURGBP")]
        public string sim3 { get; set; }
        private bool s3v = true;

        [Parameter("Symbol 4", DefaultValue = "GBPUSD")]
        public string sim4 { get; set; }
        private bool s4v = true;

        [Parameter("Symbol 5", DefaultValue = "EURJPY")]
        public string sim5 { get; set; }
        private bool s5v = true;

        [Parameter("Symbol 6", DefaultValue = "AUDUSD")]
        public string sim6 { get; set; }
        private bool s6v = true;

        [Parameter("Whole History", DefaultValue = true)]
        public bool scan { get; set; }

        [Output("Symbol 1", Color = Colors.White)]
        public IndicatorDataSeries Result1 { get; set; }
        [Output("Symbol 2", Color = Colors.Orange)]
        public IndicatorDataSeries Result2 { get; set; }
        [Output("Symbol 3", Color = Colors.Red)]
        public IndicatorDataSeries Result3 { get; set; }
        [Output("Symbol 4", Color = Colors.Purple)]
        public IndicatorDataSeries Result4 { get; set; }
        [Output("Symbol 5", Color = Colors.Blue)]
        public IndicatorDataSeries Result5 { get; set; }
        [Output("Symbol 6", Color = Colors.Green)]
        public IndicatorDataSeries Result6 { get; set; }

        private MarketSeries series1, series2, series3, series4, series5, series6;

        public int index1, index2, index3, index4, index5, index6;

        protected override void Initialize()
        {
            series1 = MarketData.GetSeries(sim1, TimeFrame);
            series2 = MarketData.GetSeries(sim2, TimeFrame);
            series3 = MarketData.GetSeries(sim3, TimeFrame);
            series4 = MarketData.GetSeries(sim4, TimeFrame);
            series5 = MarketData.GetSeries(sim5, TimeFrame);
            series6 = MarketData.GetSeries(sim6, TimeFrame);

            Draw_Legend();
        }

        public override void Calculate(int index)
        {
            Set_Indexes(index);
            if (scan)
            {
                if (series1 != null)
                    Result1[index] = ((series1.Close[index1] / series1.Close[index1 - per]) - 1) * 100;
                if (series2 != null)
                    Result2[index] = ((series2.Close[index2] / series2.Close[index2 - per]) - 1) * 100;
                if (series3 != null)
                    Result3[index] = ((series3.Close[index3] / series3.Close[index3 - per]) - 1) * 100;
                if (series4 != null)
                    Result4[index] = ((series4.Close[index4] / series4.Close[index4 - per]) - 1) * 100;
                if (series5 != null)
                    Result5[index] = ((series5.Close[index5] / series5.Close[index5 - per]) - 1) * 100;
                if (series6 != null)
                    Result6[index] = ((series6.Close[index6] / series6.Close[index6 - per]) - 1) * 100;

            }

            if (!IsLastBar)
                return;
            if (!scan)
            {
                if (series1 != null)
                    for (int i = 0; i < per; i++)
                    {
                        Result1[index - i] = ((series1.Close[index1 - i] / series1.Close[index1 - per]) - 1) * 100;
                    }
                if (series2 != null)
                    for (int i = 0; i < per; i++)
                    {
                        Result2[index - i] = ((series2.Close[index2 - i] / series2.Close[index2 - per]) - 1) * 100;
                    }
                if (series3 != null)
                    for (int i = 0; i < per; i++)
                    {
                        Result3[index - i] = ((series3.Close[index3 - i] / series3.Close[index3 - per]) - 1) * 100;
                    }
                if (series4 != null)
                    for (int i = 0; i < per; i++)
                    {
                        Result4[index - i] = ((series4.Close[index4 - i] / series4.Close[index4 - per]) - 1) * 100;
                    }
                if (series5 != null)
                    for (int i = 0; i < per; i++)
                    {
                        Result5[index - i] = ((series5.Close[index5 - i] / series5.Close[index5 - per]) - 1) * 100;
                    }
                if (series6 != null)
                    for (int i = 0; i < per; i++)
                    {
                        Result6[index - i] = ((series6.Close[index6 - i] / series6.Close[index6 - per]) - 1) * 100;

                    }

                Result1[index - per - 1] = double.NaN;
                Result2[index - per - 1] = double.NaN;
                Result3[index - per - 1] = double.NaN;
                Result4[index - per - 1] = double.NaN;
                Result5[index - per - 1] = double.NaN;
                Result6[index - per - 1] = double.NaN;

            }

            //ChartObjects.DrawText("simbolo1", sim1, index, Result1[index], VerticalAlignment.Top, HorizontalAlignment.Right, Colors.White);
            //ChartObjects.DrawText("simbolo2", sim2, StaticPosition.TopRight, Colors.Orange);
        }

        private void Set_Indexes(int index)
        {
            if (series1 != null)
                index1 = series1.OpenTime.GetIndexByExactTime(MarketSeries.OpenTime[index]);
            if (series2 != null)
                index2 = series2.OpenTime.GetIndexByExactTime(MarketSeries.OpenTime[index]);
            if (series3 != null)
                index3 = series3.OpenTime.GetIndexByExactTime(MarketSeries.OpenTime[index]);
            if (series4 != null)
                index4 = series4.OpenTime.GetIndexByExactTime(MarketSeries.OpenTime[index]);
            if (series5 != null)
                index5 = series5.OpenTime.GetIndexByExactTime(MarketSeries.OpenTime[index]);
            if (series6 != null)
                index6 = series6.OpenTime.GetIndexByExactTime(MarketSeries.OpenTime[index]);
            return;
        }

        private void Draw_Legend()
        {
            ChartObjects.DrawText("sim1", series1 != null ? series1.SymbolCode.ToString() : "Error", StaticPosition.TopLeft, Colors.White);
            ChartObjects.DrawText("sim2", series2 != null ? "\n" + series2.SymbolCode.ToString() : "\nError", StaticPosition.TopLeft, Colors.Orange);
            ChartObjects.DrawText("sim3", series3 != null ? "\n\n" + series3.SymbolCode.ToString() : "\n\nError", StaticPosition.TopLeft, Colors.Red);
            ChartObjects.DrawText("sim4", series4 != null ? "\n\n\n" + series4.SymbolCode.ToString() : "\n\n\nError", StaticPosition.TopLeft, Colors.Purple);
            ChartObjects.DrawText("sim5", series5 != null ? "\n\n\n\n" + series5.SymbolCode.ToString() : "\n\n\n\nError", StaticPosition.TopLeft, Colors.Blue);
            ChartObjects.DrawText("sim6", series6 != null ? "\n\n\n\n\n" + series6.SymbolCode.ToString() : "\n\n\n\n\nError", StaticPosition.TopLeft, Colors.Green);
            return;
        }
    }
}


CY
cysecsbin.01

Joined on 10.11.2018 Blocked

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: Forza Relativa.algo
  • Rating: 0
  • Installs: 1482
  • Modified: 13/10/2021 09:54
Comments
Log in to add a comment.
No comments found.