Multi-symbol robots and indicators

Created at 13 Sep 2013, 12:26
cAlgo_Development's avatar

cAlgo_Development

Joined 20.02.2013

Multi-symbol robots and indicators
13 Sep 2013, 12:26


We added new functionality to cAlgo - the ability for robots and indicators to work with multiple symbols. Now it's possible to use multiple symbol prices, OHLCV series and trade different symbols.

 

Requesting symbol

Robots and indicators can request a symbol specifying its symbol code. Symbol objects behave like the default Symbol object of a robot or indicator, containing current Ask, Bid, PipSize and other useful properties.

Symbol symbol = MarketData.GetSymbol("USDJPY");

Print("Symbol: {0}, Ask: {1}, Bid: {2}", symbol.Code, symbol.Ask, symbol.Bid);

 

Requesting OHLCV series

Robots and indicators can request OHLCV series for multiple symbols and timeframes and build indicators based on it.

MarketSeries series = MarketData.GetSeries("EURCAD", TimeFrame.Minute15);
MovingAverage ma = Indicators.SimpleMovingAverage(series.Close, 20);

Print("Symbol: {0}, TimeFrame: {1}", series.SymbolCode, series.TimeFrame);
Print("Last Close: {0}, Average Close: {1}", series.Close.LastValue, ma.Result.LastValue);

 

Trading multiple symbols

Robots in cAlgo can execute orders for different symbols. To do this, the robot must request the needed symbol by its code. Then, it will be possible to use it in a trade request:

 Symbol symbol = MarketData.GetSymbol("GBPCHF");
 ExecuteMarketOrder(TradeType.Buy, symbol, 10000);

The new version of our Demo cTrader and cAlgo is released and can be downloaded from www.spotware.com

Backtesting of Multi-symbol robots in not supported at least for now. It can be implemented in future.


@cAlgo_Development
Replies

cAlgo_Development
13 Sep 2013, 12:36

Example: Multi-symbol RSI robot

Robot below trades EURUSD if both EURUSD and EURJPY are overbought or oversold according to RSI indicator:

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

namespace cAlgo.Robots
{
    [Robot()]
    public class MultiSymbolRsiRobot : Robot
    {

        private const string MyLabel = "MultiSymbolRsiRobot";

        [Parameter("Periods", DefaultValue = 14)]
        public int Periods { get; set; }

        [Parameter("Volume", DefaultValue = 10000, MinValue = 1000)]
        public int Volume { get; set; }

        private RelativeStrengthIndex eurJpyRSI;
        private RelativeStrengthIndex eurUsdRSI;

        private Symbol eurUsd;

        protected override void OnStart()
        {
            var eurJpySeries = MarketData.GetSeries("EURJPY", TimeFrame);
            var eurUsdSeries = MarketData.GetSeries("EURUSD", TimeFrame);

            eurJpyRSI = Indicators.RelativeStrengthIndex(eurJpySeries.Close, Periods);
            eurUsdRSI = Indicators.RelativeStrengthIndex(eurUsdSeries.Close, Periods);

            eurUsd = MarketData.GetSymbol("EURUSD");
        }

        protected override void OnTick()
        {
            if (Trade.IsExecuting)
                return;

            if (eurUsdRSI.Result.LastValue > 70 && eurJpyRSI.Result.LastValue > 70)
            {
                ClosePosition(eurUsd, TradeType.Buy);
                OpenPosition(eurUsd, TradeType.Sell);
            }
            if (eurUsdRSI.Result.LastValue < 30 && eurJpyRSI.Result.LastValue < 30)
            {
                ClosePosition(eurUsd, TradeType.Sell);
                OpenPosition(eurUsd, TradeType.Buy);
            }
        }


        private void ClosePosition(Symbol symbol, TradeType tradeType)
        {
            foreach (Position position in Account.Positions)
            {
                if (position.Label == MyLabel && position.SymbolCode == symbol.Code && position.TradeType == tradeType)
                    Trade.Close(position);
            }
        }

        private void OpenPosition(Symbol symbol, TradeType tradeType)
        {
            if (HasPosition(symbol, tradeType))
                return;

            var request = new MarketOrderRequest(tradeType, Volume) 
            {
                Label = MyLabel,
                Symbol = symbol
            };

            Trade.Send(request);
        }

        private bool HasPosition(Symbol symbol, TradeType tradeType)
        {
            foreach (Position position in Account.Positions)
            {
                if (position.SymbolCode == symbol.Code && position.Label == MyLabel && position.TradeType == tradeType)
                    return true;
            }
            return false;
        }

    }
}

 


@cAlgo_Development

pennyfx
19 Sep 2013, 09:01

RE: Example: Multi-symbol RSI robot

Does this mean the following code will now return ALL open positions across all pairs ?  If so, this will probably break a lot of Robots.

foreach (Position position in Account.Positions)


@pennyfx

cAlgo_Development
19 Sep 2013, 09:15

This code was always like this - Account.Positions always contained positions for all symbols.


@cAlgo_Development

cAlgo_Development
19 Sep 2013, 15:13

Indicator Example

Moving averages of several symbols on a single chart.



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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC)]
    public class MultiSymbolMA : Indicator
    {
        private MovingAverage ma1, ma2, ma3;
        private MarketSeries series1, series2, series3;
        private Symbol symbol1, symbol2, symbol3;

        [Parameter(DefaultValue = "EURUSD")]
        public string Symbol1 { get; set; }

        [Parameter(DefaultValue = "EURAUD")]
        public string Symbol2 { get; set; }

        [Parameter(DefaultValue = "EURCAD")]
        public string Symbol3 { get; set; }

        [Parameter(DefaultValue = 14)]
        public int Period { get; set; }

        [Parameter(DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType MaType { get; set; }

        [Output("MA Symbol 1", Color = Colors.Magenta)]
        public IndicatorDataSeries Result1 { get; set; }

        [Output("MA Symbol 2", Color = Colors.Red)]
        public IndicatorDataSeries Result2 { get; set; }

        [Output("MA Symbol 3", Color = Colors.Yellow)]
        public IndicatorDataSeries Result3 { get; set; }

        protected override void Initialize()
        {
            symbol1 = MarketData.GetSymbol(Symbol1);
            symbol2 = MarketData.GetSymbol(Symbol2);
            symbol3 = MarketData.GetSymbol(Symbol3);

            series1 = MarketData.GetSeries(symbol1, TimeFrame);
            series2 = MarketData.GetSeries(symbol2, TimeFrame);
            series3 = MarketData.GetSeries(symbol3, TimeFrame);

            ma1 = Indicators.MovingAverage(series1.Close, Period, MaType);
            ma2 = Indicators.MovingAverage(series2.Close, Period, MaType);
            ma3 = Indicators.MovingAverage(series3.Close, Period, MaType);
        }

        public override void Calculate(int index)
        {
            ShowOutput(symbol1, Result1, ma1, series1, index);
            ShowOutput(symbol2, Result2, ma2, series2, index);
            ShowOutput(symbol3, Result3, ma3, series3, index);
        }

        private void ShowOutput(Symbol symbol, IndicatorDataSeries result, MovingAverage movingAverage, MarketSeries series, int index)
        {
            int index2 = GetIndexByDate(series, MarketSeries.OpenTime[index]);
            result[index] = movingAverage.Result[index2];

            string text = string.Format("{0} {1}", symbol.Code, Math.Round(result[index], symbol.Digits));

            ChartObjects.DrawText(symbol.Code, text, index + 1, result[index], VerticalAlignment.Center, HorizontalAlignment.Right, Colors.Yellow);
        }

        private int GetIndexByDate(MarketSeries series, DateTime time)
        {
            for (int i = series.Close.Count - 1; i >= 0; i--)
                if (time == series.OpenTime[i])
                    return i;
            return -1;
        }
    }
}

 


@cAlgo_Development

cAlgo_Fanatic
19 Sep 2013, 15:29

Indicator Example 2

Multiple symbol information displayed on the chart.

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC)]
    public class MultiSymbolMarketInfo : Indicator
    {
        private Symbol symbol1;
        private Symbol symbol2;
        private Symbol symbol3;

        [Parameter(DefaultValue = "EURGBP")]
        public string Symbol1 { get; set; }

        [Parameter(DefaultValue = "GBPUSD")]
        public string Symbol2 { get; set; }

        [Parameter(DefaultValue = "EURUSD")]
        public string Symbol3 { get; set; }

        protected override void Initialize()
        {
            symbol1 = MarketData.GetSymbol(Symbol1);
            symbol2 = MarketData.GetSymbol(Symbol2);
            symbol3 = MarketData.GetSymbol(Symbol3);
        }

        public override void Calculate(int index)
        {
            if (!IsLastBar)
                return;

            var text = FormatSymbol(symbol1) + "\n" + FormatSymbol(symbol2) + "\n" + FormatSymbol(symbol3);

            ChartObjects.DrawText("symbol1", text, StaticPosition.TopLeft, Colors.Lime);
        }

        private string FormatSymbol(Symbol symbol)
        {
            var spread = Math.Round(symbol.Spread / symbol.PipSize, 1);
            return string.Format("{0}\t Ask: {1}\t Bid: {2}\t Spread: {3}", symbol.Code, symbol.Ask, symbol.Bid, spread);

        }
    }
}

 


@cAlgo_Fanatic

Abhi
23 Sep 2014, 22:16

Multi-symbol robots and indicators

Hi Spotware Team, nice improvements. I still cannot run average true range indicator on multiple symbols.

 

Please could you let us know when the feature will be available or if there is a way to get around the problem.

 

Thanks in advance.

 

Regards,

Abhi


@Abhi

Spotware
24 Sep 2014, 09:56

RE: Multi-symbol robots and indicators

Abhi said:

Hi Spotware Team, nice improvements. I still cannot run average true range indicator on multiple symbols.

 

Please could you let us know when the feature will be available or if there is a way to get around the problem.

 

Thanks in advance.

 

Regards,

Abhi

Please specify what you mean by saying that. You can use multi-symbol data in code of your indicator. You can also add ATR to several charts.


@Spotware

Abhi
24 Sep 2014, 21:37

RE: RE: Multi-symbol robots and indicators

Spotware said:

Abhi said:

Hi Spotware Team, nice improvements. I still cannot run average true range indicator on multiple symbols.

 

Please could you let us know when the feature will be available or if there is a way to get around the problem.

 

Thanks in advance.

 

Regards,

Abhi

Please specify what you mean by saying that. You can use multi-symbol data in code of your indicator. You can also add ATR to several charts.

I want to show ATR for multiple symbols on a single chart. The  method call "Indicators.AverageTrueRange(int period , MovingAverageType.Exponential)" can be only called for a single symbol in a chart. Is there anyway to call ATR on multiple symbols and show up on a chart like you showed for RelativeStrengthIndex in this forum on previous posts.

 

Does it make sense now.


@Abhi

Spotware
25 Sep 2014, 12:32

There is an overload of AverageTrueRange method that accepts MarketSeries object:

/api/reference/internals/iindicatorsaccessor/averagetruerange-9d2b

We can recommend you to contact one of our Partners or post a job in Development Jobs section.


@Spotware

Abhi
25 Sep 2014, 21:58

RE:

Spotware said:

There is an overload of AverageTrueRange method that accepts MarketSeries object:

/api/reference/internals/iindicatorsaccessor/averagetruerange-9d2b

We can recommend you to contact one of our Partners or post a job in Development Jobs section.

Many thanks for the help, greatly appreciated. The overloaded method works for one symbol only at run time although I can call ATR indicator on multiple symbols at compile time. 

The chart symbol (on where I am calling my custom indicator) and the marketseries symbol need  to match for me to display the ATR value.

 

So if I call ATR on multiple symbols, the chart does not display the ATR for all the symbols until I comment out  the rest of the symbols. 

 

Below is the code:

 

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.CentralEuropeanStandardTime, AccessRights = AccessRights.None)]
    public class AbhiRadarscreen : Indicator
    {

        protected MarketSeries series_EURUSD, series_USDJPY;
        protected AverageTrueRange ATR_EURUSD, ATR_USDJPY;
        protected string DisplayText;


        protected override void Initialize()
        {

        }

        public override void Calculate(int index)
        {
            series_EURUSD = MarketData.GetSeries("EURUSD", TimeFrame.Daily);
            ATR_EURUSD = Indicators.AverageTrueRange(series_EURUSD, 22, MovingAverageType.Exponential);

            //series_USDJPY = MarketData.GetSeries("USDJPY", TimeFrame.Daily);
            //ATR_USDJPY = Indicators.AverageTrueRange(series_USDJPY, 22, MovingAverageType.Exponential);



            DisplayText = string.Format("Symbol\t\t\tAverage True Range\n");
            DisplayText = DisplayText + string.Format("EURUSD\t\t{0}\n", ATR_EURUSD.Result.LastValue * 10000);
            //DisplayText = DisplayText + string.Format("USDJPY\t\t{0}\n", ATR_USDJPY.Result.LastValue * 10000);
            ChartObjects.DrawText("DisplayText", DisplayText, StaticPosition.TopLeft, Colors.Lime);

        }
    }
}


@Abhi

Abhi
26 Sep 2014, 00:26

Please ignore my previous comment. Your suggestion works after I restarted Ctrader. Many thanks,


@Abhi

crank
27 Dec 2014, 16:24

RE: Example: Multi-symbol RSI robot

How would I use the Stochastic Oscillator %K with two symbols in indicators or Robots?

cAlgo_Development said:

Robot below trades EURUSD if both EURUSD and EURJPY are overbought or oversold according to RSI indicator:

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

namespace cAlgo.Robots
{
    [Robot()]
    public class MultiSymbolRsiRobot : Robot
    {

        private const string MyLabel = "MultiSymbolRsiRobot";

        [Parameter("Periods", DefaultValue = 14)]
        public int Periods { get; set; }

        [Parameter("Volume", DefaultValue = 10000, MinValue = 1000)]
        public int Volume { get; set; }

        private RelativeStrengthIndex eurJpyRSI;
        private RelativeStrengthIndex eurUsdRSI;

        private Symbol eurUsd;

        protected override void OnStart()
        {
            var eurJpySeries = MarketData.GetSeries("EURJPY", TimeFrame);
            var eurUsdSeries = MarketData.GetSeries("EURUSD", TimeFrame);

            eurJpyRSI = Indicators.RelativeStrengthIndex(eurJpySeries.Close, Periods);
            eurUsdRSI = Indicators.RelativeStrengthIndex(eurUsdSeries.Close, Periods);

            eurUsd = MarketData.GetSymbol("EURUSD");
        }

        protected override void OnTick()
        {
            if (Trade.IsExecuting)
                return;

            if (eurUsdRSI.Result.LastValue > 70 && eurJpyRSI.Result.LastValue > 70)
            {
                ClosePosition(eurUsd, TradeType.Buy);
                OpenPosition(eurUsd, TradeType.Sell);
            }
            if (eurUsdRSI.Result.LastValue < 30 && eurJpyRSI.Result.LastValue < 30)
            {
                ClosePosition(eurUsd, TradeType.Sell);
                OpenPosition(eurUsd, TradeType.Buy);
            }
        }


        private void ClosePosition(Symbol symbol, TradeType tradeType)
        {
            foreach (Position position in Account.Positions)
            {
                if (position.Label == MyLabel && position.SymbolCode == symbol.Code && position.TradeType == tradeType)
                    Trade.Close(position);
            }
        }

        private void OpenPosition(Symbol symbol, TradeType tradeType)
        {
            if (HasPosition(symbol, tradeType))
                return;

            var request = new MarketOrderRequest(tradeType, Volume) 
            {
                Label = MyLabel,
                Symbol = symbol
            };

            Trade.Send(request);
        }

        private bool HasPosition(Symbol symbol, TradeType tradeType)
        {
            foreach (Position position in Account.Positions)
            {
                if (position.SymbolCode == symbol.Code && position.Label == MyLabel && position.TradeType == tradeType)
                    return true;
            }
            return false;
        }

    }
}

 

 


@crank

crank
27 Dec 2014, 16:25

RE: Example: Multi-symbol RSI robot

How would I use the Stochastic Oscillator %K for two different symbols in indicators or robots?

cAlgo_Development said:

Robot below trades EURUSD if both EURUSD and EURJPY are overbought or oversold according to RSI indicator:

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

namespace cAlgo.Robots
{
    [Robot()]
    public class MultiSymbolRsiRobot : Robot
    {

        private const string MyLabel = "MultiSymbolRsiRobot";

        [Parameter("Periods", DefaultValue = 14)]
        public int Periods { get; set; }

        [Parameter("Volume", DefaultValue = 10000, MinValue = 1000)]
        public int Volume { get; set; }

        private RelativeStrengthIndex eurJpyRSI;
        private RelativeStrengthIndex eurUsdRSI;

        private Symbol eurUsd;

        protected override void OnStart()
        {
            var eurJpySeries = MarketData.GetSeries("EURJPY", TimeFrame);
            var eurUsdSeries = MarketData.GetSeries("EURUSD", TimeFrame);

            eurJpyRSI = Indicators.RelativeStrengthIndex(eurJpySeries.Close, Periods);
            eurUsdRSI = Indicators.RelativeStrengthIndex(eurUsdSeries.Close, Periods);

            eurUsd = MarketData.GetSymbol("EURUSD");
        }

        protected override void OnTick()
        {
            if (Trade.IsExecuting)
                return;

            if (eurUsdRSI.Result.LastValue > 70 && eurJpyRSI.Result.LastValue > 70)
            {
                ClosePosition(eurUsd, TradeType.Buy);
                OpenPosition(eurUsd, TradeType.Sell);
            }
            if (eurUsdRSI.Result.LastValue < 30 && eurJpyRSI.Result.LastValue < 30)
            {
                ClosePosition(eurUsd, TradeType.Sell);
                OpenPosition(eurUsd, TradeType.Buy);
            }
        }


        private void ClosePosition(Symbol symbol, TradeType tradeType)
        {
            foreach (Position position in Account.Positions)
            {
                if (position.Label == MyLabel && position.SymbolCode == symbol.Code && position.TradeType == tradeType)
                    Trade.Close(position);
            }
        }

        private void OpenPosition(Symbol symbol, TradeType tradeType)
        {
            if (HasPosition(symbol, tradeType))
                return;

            var request = new MarketOrderRequest(tradeType, Volume) 
            {
                Label = MyLabel,
                Symbol = symbol
            };

            Trade.Send(request);
        }

        private bool HasPosition(Symbol symbol, TradeType tradeType)
        {
            foreach (Position position in Account.Positions)
            {
                if (position.SymbolCode == symbol.Code && position.Label == MyLabel && position.TradeType == tradeType)
                    return true;
            }
            return false;
        }

    }
}

 

 


@crank

crank
27 Dec 2014, 16:26

RE:

How would I use the Stochastic Oscillator %K for two different symbols in indicators or robots?

cAlgo_Development said:

We added new functionality to cAlgo - the ability for robots and indicators to work with multiple symbols. Now it's possible to use multiple symbol prices, OHLCV series and trade different symbols.

 

Requesting symbol

Robots and indicators can request a symbol specifying its symbol code. Symbol objects behave like the default Symbol object of a robot or indicator, containing current Ask, Bid, PipSize and other useful properties.

Symbol symbol = MarketData.GetSymbol("USDJPY");

Print("Symbol: {0}, Ask: {1}, Bid: {2}", symbol.Code, symbol.Ask, symbol.Bid);

 

Requesting OHLCV series

Robots and indicators can request OHLCV series for multiple symbols and timeframes and build indicators based on it.

MarketSeries series = MarketData.GetSeries("EURCAD", TimeFrame.Minute15);
MovingAverage ma = Indicators.SimpleMovingAverage(series.Close, 20);

Print("Symbol: {0}, TimeFrame: {1}", series.SymbolCode, series.TimeFrame);
Print("Last Close: {0}, Average Close: {1}", series.Close.LastValue, ma.Result.LastValue);

 

Trading multiple symbols

Robots in cAlgo can execute orders for different symbols. To do this, the robot must request the needed symbol by its code. Then, it will be possible to use it in a trade request:

 Symbol symbol = MarketData.GetSymbol("GBPCHF");
 ExecuteMarketOrder(TradeType.Buy, symbol, 10000);

The new version of our Demo cTrader and cAlgo is released and can be downloaded from www.spotware.com

Backtesting of Multi-symbol robots in not supported at least for now. It can be implemented in future.

 


@crank

crank
27 Dec 2014, 16:27

RE:

How would I use the Stochastic Oscillator %K for two different symbols in indicators or robots?

We added new functionality to cAlgo - the ability for robots and indicators to work with multiple symbols. Now it's possible to use multiple symbol prices, OHLCV series and trade different symbols.

 

Requesting symbol

Robots and indicators can request a symbol specifying its symbol code. Symbol objects behave like the default Symbol object of a robot or indicator, containing current Ask, Bid, PipSize and other useful properties.

Symbol symbol = MarketData.GetSymbol("USDJPY");

Print("Symbol: {0}, Ask: {1}, Bid: {2}", symbol.Code, symbol.Ask, symbol.Bid);

 

Requesting OHLCV series

Robots and indicators can request OHLCV series for multiple symbols and timeframes and build indicators based on it.

MarketSeries series = MarketData.GetSeries("EURCAD", TimeFrame.Minute15);
MovingAverage ma = Indicators.SimpleMovingAverage(series.Close, 20);

Print("Symbol: {0}, TimeFrame: {1}", series.SymbolCode, series.TimeFrame);
Print("Last Close: {0}, Average Close: {1}", series.Close.LastValue, ma.Result.LastValue);

 

Trading multiple symbols

Robots in cAlgo can execute orders for different symbols. To do this, the robot must request the needed symbol by its code. Then, it will be possible to use it in a trade request:

 Symbol symbol = MarketData.GetSymbol("GBPCHF");
 ExecuteMarketOrder(TradeType.Buy, symbol, 10000);

The new version of our Demo cTrader and cAlgo is released and can be downloaded from www.spotware.com

Backtesting of Multi-symbol robots in not supported at least for now. It can be implemented in future.

 


@crank

crank
01 Jan 2015, 15:34

RE: RE:

1) But the Stochastic Oscillator doesn't have an input for "series" like the RSI or a moving average to distinguish between two different symbols/series in one indicator. 

2) Also, in indicator below, how would I display the difference in the RSI of symbol1 minus the RSI of symbol2, i.e., how do you perform simple arithmetic involving the different symbol RSI outputs instead of just the RSI output? 

Example; The RSI (Or preferably the Stochastic Oscillator %K ) of USDCAD is 70 and the RSI of EURAUD is 60. How do I display USDCAD - EURAUD = 10 using the multi-symbol indicator below, in addition to just the absolute RSI levels for each symbol. Like the  MultiSymbolMarketInfo displays the ask, bid, & spread in the top left of the price chart, but for displaying the result (In the price of simple arithmetic calculations like "USDCAD - EURAUD = 10,"   instead of ask, bid, & spread. 

 

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

namespace cAlgo.Indicators
{
    [Levels(30, 70, 80, 20)]

    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC)]
    public class MultiSymbolMA : Indicator
    {
        private RelativeStrengthIndex ma1, ma2, ma3, ma4;
        private MarketSeries series1, series2, series3, series4;
        private Symbol symbol1, symbol2, symbol3, symbol4;

        [Parameter(DefaultValue = "USDCAD")]
        public string Symbol1 { get; set; }

        [Parameter(DefaultValue = "EURAUD")]
        public string Symbol2 { get; set; }

        [Parameter(DefaultValue = "EURJPY")]
        public string Symbol3 { get; set; }

        [Parameter(DefaultValue = "GBPUSD")]
        public string Symbol4 { get; set; }

        [Parameter(DefaultValue = 5)]
        public int Period { get; set; }

        [Output("MA Symbol 1", Color = Colors.Red, PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries Result1 { get; set; }

        [Output("MA Symbol 2", Color = Colors.Magenta, PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries Result2 { get; set; }

        [Output("MA Symbol 3", Color = Colors.Yellow, PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries Result3 { get; set; }

        [Output("MA Symbol 4", Color = Colors.White, PlotType = PlotType.Line, Thickness = 1, LineStyle = LineStyle.Dots)]
        public IndicatorDataSeries Result4 { get; set; }

        protected override void Initialize()
        {
            symbol1 = MarketData.GetSymbol(Symbol1);
            symbol2 = MarketData.GetSymbol(Symbol2);
            symbol3 = MarketData.GetSymbol(Symbol3);
            symbol4 = MarketData.GetSymbol(Symbol4);

            series1 = MarketData.GetSeries(symbol1, TimeFrame);
            series2 = MarketData.GetSeries(symbol2, TimeFrame);
            series3 = MarketData.GetSeries(symbol3, TimeFrame);
            series4 = MarketData.GetSeries(symbol4, TimeFrame);

            ma1 = Indicators.RelativeStrengthIndex(series1.Close, Period);
            ma2 = Indicators.RelativeStrengthIndex(series2.Close, Period);
            ma3 = Indicators.RelativeStrengthIndex(series3.Close, Period);
            ma4 = Indicators.RelativeStrengthIndex(series4.Close, Period);

        }

        public override void Calculate(int index)
        {
            ShowOutput(symbol1, Result1, ma1, series1, index);
            ShowOutput(symbol2, Result2, ma2, series2, index);
            ShowOutput(symbol3, Result3, ma3, series3, index);
            ShowOutput(symbol4, Result4, ma4, series4, index);
        }

        private void ShowOutput(Symbol symbol, IndicatorDataSeries result, RelativeStrengthIndex RelativeStrengthIndex, MarketSeries series, int index)
        {

            int index2 = GetIndexByDate(series, MarketSeries.OpenTime[index]);

            result[index] = RelativeStrengthIndex.Result[index2];

            string text = string.Format("{0} {1}", symbol.Code, Math.Round(result[index], 0));

            ChartObjects.DrawText(symbol.Code, text, index + 1, result[index], VerticalAlignment.Center, HorizontalAlignment.Right, Colors.Yellow);

        }
        private int GetIndexByDate(MarketSeries series, DateTime time)
        {
            for (int i = series.Close.Count - 1; i >= 0; i--)
                if (time == series.OpenTime[i])
                    return i;
            return -1;
        }
    }
}
 

How would I use the Stochastic Oscillator %K for two different symbols in indicators or robots?

We added new functionality to cAlgo - the ability for robots and indicators to work with multiple symbols. Now it's possible to use multiple symbol prices, OHLCV series and trade different symbols.

 

Requesting symbol

Robots and indicators can request a symbol specifying its symbol code. Symbol objects behave like the default Symbol object of a robot or indicator, containing current Ask, Bid, PipSize and other useful properties.

Symbol symbol = MarketData.GetSymbol("USDJPY");

Print("Symbol: {0}, Ask: {1}, Bid: {2}", symbol.Code, symbol.Ask, symbol.Bid);

 

Requesting OHLCV series

Robots and indicators can request OHLCV series for multiple symbols and timeframes and build indicators based on it.

MarketSeries series = MarketData.GetSeries("EURCAD", TimeFrame.Minute15);
MovingAverage ma = Indicators.SimpleMovingAverage(series.Close, 20);

Print("Symbol: {0}, TimeFrame: {1}", series.SymbolCode, series.TimeFrame);
Print("Last Close: {0}, Average Close: {1}", series.Close.LastValue, ma.Result.LastValue);

 

Trading multiple symbols

Robots in cAlgo can execute orders for different symbols. To do this, the robot must request the needed symbol by its code. Then, it will be possible to use it in a trade request:

 Symbol symbol = MarketData.GetSymbol("GBPCHF");
 ExecuteMarketOrder(TradeType.Buy, symbol, 10000);

The new version of our Demo cTrader and cAlgo is released and can be downloaded from www.spotware.com

Backtesting of Multi-symbol robots in not supported at least for now. It can be implemented in future.

 

 


@crank

crank
01 Jan 2015, 15:35

RE: RE:

1) But the Stochastic Oscillator doesn't have an input for "series" like the RSI or a moving average to distinguish between two different symbols/series in one indicator. 

2) Also, in indicator below, how would I display the difference in the RSI of symbol1 minus the RSI of symbol2, i.e., how do you perform simple arithmetic involving the different symbol RSI outputs instead of just the RSI output? 

Example; The RSI (Or preferably the Stochastic Oscillator %K ) of USDCAD is 70 and the RSI of EURAUD is 60. How do I display USDCAD - EURAUD = 10 using the multi-symbol indicator below, in addition to just the absolute RSI levels for each symbol. Like the  MultiSymbolMarketInfo displays the ask, bid, & spread in the top left of the price chart, but for displaying the result (In the price of simple arithmetic calculations like "USDCAD - EURAUD = 10,"   instead of ask, bid, & spread. 

 

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

namespace cAlgo.Indicators
{
    [Levels(30, 70, 80, 20)]

    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC)]
    public class MultiSymbolMA : Indicator
    {
        private RelativeStrengthIndex ma1, ma2, ma3, ma4;
        private MarketSeries series1, series2, series3, series4;
        private Symbol symbol1, symbol2, symbol3, symbol4;

        [Parameter(DefaultValue = "USDCAD")]
        public string Symbol1 { get; set; }

        [Parameter(DefaultValue = "EURAUD")]
        public string Symbol2 { get; set; }

        [Parameter(DefaultValue = "EURJPY")]
        public string Symbol3 { get; set; }

        [Parameter(DefaultValue = "GBPUSD")]
        public string Symbol4 { get; set; }

        [Parameter(DefaultValue = 5)]
        public int Period { get; set; }

        [Output("MA Symbol 1", Color = Colors.Red, PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries Result1 { get; set; }

        [Output("MA Symbol 2", Color = Colors.Magenta, PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries Result2 { get; set; }

        [Output("MA Symbol 3", Color = Colors.Yellow, PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries Result3 { get; set; }

        [Output("MA Symbol 4", Color = Colors.White, PlotType = PlotType.Line, Thickness = 1, LineStyle = LineStyle.Dots)]
        public IndicatorDataSeries Result4 { get; set; }

        protected override void Initialize()
        {
            symbol1 = MarketData.GetSymbol(Symbol1);
            symbol2 = MarketData.GetSymbol(Symbol2);
            symbol3 = MarketData.GetSymbol(Symbol3);
            symbol4 = MarketData.GetSymbol(Symbol4);

            series1 = MarketData.GetSeries(symbol1, TimeFrame);
            series2 = MarketData.GetSeries(symbol2, TimeFrame);
            series3 = MarketData.GetSeries(symbol3, TimeFrame);
            series4 = MarketData.GetSeries(symbol4, TimeFrame);

            ma1 = Indicators.RelativeStrengthIndex(series1.Close, Period);
            ma2 = Indicators.RelativeStrengthIndex(series2.Close, Period);
            ma3 = Indicators.RelativeStrengthIndex(series3.Close, Period);
            ma4 = Indicators.RelativeStrengthIndex(series4.Close, Period);

        }

        public override void Calculate(int index)
        {
            ShowOutput(symbol1, Result1, ma1, series1, index);
            ShowOutput(symbol2, Result2, ma2, series2, index);
            ShowOutput(symbol3, Result3, ma3, series3, index);
            ShowOutput(symbol4, Result4, ma4, series4, index);
        }

        private void ShowOutput(Symbol symbol, IndicatorDataSeries result, RelativeStrengthIndex RelativeStrengthIndex, MarketSeries series, int index)
        {

            int index2 = GetIndexByDate(series, MarketSeries.OpenTime[index]);

            result[index] = RelativeStrengthIndex.Result[index2];

            string text = string.Format("{0} {1}", symbol.Code, Math.Round(result[index], 0));

            ChartObjects.DrawText(symbol.Code, text, index + 1, result[index], VerticalAlignment.Center, HorizontalAlignment.Right, Colors.Yellow);

        }
        private int GetIndexByDate(MarketSeries series, DateTime time)
        {
            for (int i = series.Close.Count - 1; i >= 0; i--)
                if (time == series.OpenTime[i])
                    return i;
            return -1;
        }
    }
}
 

How would I use the Stochastic Oscillator %K for two different symbols in indicators or robots?

We added new functionality to cAlgo - the ability for robots and indicators to work with multiple symbols. Now it's possible to use multiple symbol prices, OHLCV series and trade different symbols.

 

Requesting symbol

Robots and indicators can request a symbol specifying its symbol code. Symbol objects behave like the default Symbol object of a robot or indicator, containing current Ask, Bid, PipSize and other useful properties.

Symbol symbol = MarketData.GetSymbol("USDJPY");

Print("Symbol: {0}, Ask: {1}, Bid: {2}", symbol.Code, symbol.Ask, symbol.Bid);

 

Requesting OHLCV series

Robots and indicators can request OHLCV series for multiple symbols and timeframes and build indicators based on it.

MarketSeries series = MarketData.GetSeries("EURCAD", TimeFrame.Minute15);
MovingAverage ma = Indicators.SimpleMovingAverage(series.Close, 20);

Print("Symbol: {0}, TimeFrame: {1}", series.SymbolCode, series.TimeFrame);
Print("Last Close: {0}, Average Close: {1}", series.Close.LastValue, ma.Result.LastValue);

 

Trading multiple symbols

Robots in cAlgo can execute orders for different symbols. To do this, the robot must request the needed symbol by its code. Then, it will be possible to use it in a trade request:

 Symbol symbol = MarketData.GetSymbol("GBPCHF");
 ExecuteMarketOrder(TradeType.Buy, symbol, 10000);

The new version of our Demo cTrader and cAlgo is released and can be downloaded from www.spotware.com

Backtesting of Multi-symbol robots in not supported at least for now. It can be implemented in future.

 

 


@crank

crank
17 Jan 2015, 14:15

Why don't these multi-symbol indicators load on the weekend when the market is closed? The only timeframe I can get to load when the market is closed is 2 day timeframe or greater. All my multi-symbol/multi-timframe custom indicators work fine until...

Why don't these multi-symbol indicators load on the weekend when the market is closed? The only timeframe I can get to load when the market is closed is 2 day timeframe or greater. All my multi-symbol/multi-timframe custom indicators work fine until the weekend when I'm not trading and have time to work on them. Even a cut-and-paste of the simple indicator below won't load on the weekend.

Moving averages of several symbols on a single chart.

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC)]
    public class MultiSymbolMA : Indicator
    {
        private MovingAverage ma1, ma2, ma3;
        private MarketSeries series1, series2, series3;
        private Symbol symbol1, symbol2, symbol3;

        [Parameter(DefaultValue = "EURUSD")]
        public string Symbol1 { get; set; }

        [Parameter(DefaultValue = "EURAUD")]
        public string Symbol2 { get; set; }

        [Parameter(DefaultValue = "EURCAD")]
        public string Symbol3 { get; set; }

        [Parameter(DefaultValue = 14)]
        public int Period { get; set; }

        [Parameter(DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType MaType { get; set; }

        [Output("MA Symbol 1", Color = Colors.Magenta)]
        public IndicatorDataSeries Result1 { get; set; }

        [Output("MA Symbol 2", Color = Colors.Red)]
        public IndicatorDataSeries Result2 { get; set; }

        [Output("MA Symbol 3", Color = Colors.Yellow)]
        public IndicatorDataSeries Result3 { get; set; }

        protected override void Initialize()
        {
            symbol1 = MarketData.GetSymbol(Symbol1);
            symbol2 = MarketData.GetSymbol(Symbol2);
            symbol3 = MarketData.GetSymbol(Symbol3);

            series1 = MarketData.GetSeries(symbol1, TimeFrame);
            series2 = MarketData.GetSeries(symbol2, TimeFrame);
            series3 = MarketData.GetSeries(symbol3, TimeFrame);

            ma1 = Indicators.MovingAverage(series1.Close, Period, MaType);
            ma2 = Indicators.MovingAverage(series2.Close, Period, MaType);
            ma3 = Indicators.MovingAverage(series3.Close, Period, MaType);
        }

        public override void Calculate(int index)
        {
            ShowOutput(symbol1, Result1, ma1, series1, index);
            ShowOutput(symbol2, Result2, ma2, series2, index);
            ShowOutput(symbol3, Result3, ma3, series3, index);
        }

        private void ShowOutput(Symbol symbol, IndicatorDataSeries result, MovingAverage movingAverage, MarketSeries series, int index)
        {
            int index2 = GetIndexByDate(series, MarketSeries.OpenTime[index]);
            result[index] = movingAverage.Result[index2];

            string text = string.Format("{0} {1}", symbol.Code, Math.Round(result[index], symbol.Digits));

            ChartObjects.DrawText(symbol.Code, text, index + 1, result[index], VerticalAlignment.Center, HorizontalAlignment.Right, Colors.Yellow);
        }

        private int GetIndexByDate(MarketSeries series, DateTime time)
        {
            for (int i = series.Close.Count - 1; i >= 0; i--)
                if (time == series.OpenTime[i])
                    return i;
            return -1;
        }
    }
}

 

 


@crank

AlexanderRC
22 Jan 2015, 23:19

You may want to look into cAlgo built in function GetIndexByTime() instead of using your own. Testing for exact equality of DateTimes may be a problem, just a wild guess.


@AlexanderRC

AlexanderRC
06 Feb 2015, 15:55

Spotware, are there any short term plans to support multisymbol cBots in backtesting?

There are some support internally as commission for the same volume for pairs like GBPCAD are different on different days in backtesting, so cross rates to the account currency (USD in my case) are properly accounted for, so they should be downloaded and stored from the server already. Thus, implementing multi currency cBots backtesting should be a couple of steps away.

Caching tick/minute bars data on first invocation of GetSymbol() would be ok for the selected period of backtest so that backtesting engine would not cache all possible symbols present in the broker's cTrader after the user clicks the play button. If caching in the middle of the backtest run requires too many internal changes, you may add UI with a list of checkboxes and the user would have to select which pairs would be used in the backtest or optimization. If the data has not been explicitly cached for the symbol requested via GetSymbol() you may throw an exception. Adding UI for currencies would also cater for data in CSV files, they can be loaded individually for the respective symbols or the format of CSV could be enhanced to include the symbol in each line of the file.


@AlexanderRC

Spotware
10 Feb 2015, 10:44

RE:

AlexanderRC said:

Spotware, are there any short term plans to support multisymbol cBots in backtesting?

There are some support internally as commission for the same volume for pairs like GBPCAD are different on different days in backtesting, so cross rates to the account currency (USD in my case) are properly accounted for, so they should be downloaded and stored from the server already. Thus, implementing multi currency cBots backtesting should be a couple of steps away.

Caching tick/minute bars data on first invocation of GetSymbol() would be ok for the selected period of backtest so that backtesting engine would not cache all possible symbols present in the broker's cTrader after the user clicks the play button. If caching in the middle of the backtest run requires too many internal changes, you may add UI with a list of checkboxes and the user would have to select which pairs would be used in the backtest or optimization. If the data has not been explicitly cached for the symbol requested via GetSymbol() you may throw an exception. Adding UI for currencies would also cater for data in CSV files, they can be loaded individually for the respective symbols or the format of CSV could be enhanced to include the symbol in each line of the file.

Dear AlexanderRC,

Thank you for your suggestions. Probably we will implement first version of multisymbol backtesting in very similar way with that you described. However multisymbol backtesting is not in our short term road map.


@Spotware

AlexanderRC
13 Feb 2015, 02:03

If someone else craves for this feature, please vote for Multi-Currency Backtesting on vote.spotware.com


@AlexanderRC

inferno285
24 May 2015, 00:58

A few days ago I had a working indicator showing other pair's averages, now it won't show up. I tried all the examples posted in this thread that use MarketData.GetSeries and every time if I took at that line then it would show up on cTrader. Please help.

 

Stephen


@inferno285

Spotware
12 Jun 2015, 17:59

RE:

inferno285 said:

A few days ago I had a working indicator showing other pair's averages, now it won't show up. I tried all the examples posted in this thread that use MarketData.GetSeries and every time if I took at that line then it would show up on cTrader. Please help.

 

Stephen

Dear Trader,

Could you please press Ctrl+Alt+Shift+T when you observe this issue?

It will submit troubleshooting information to our support team.


@Spotware

aharonzbaida
06 Sep 2015, 02:16

RE:

cAlgo_Development said:

We added new functionality to cAlgo - the ability for robots and indicators to work with multiple symbols. Now it's possible to use multiple symbol prices, OHLCV series and trade different symbols.

 

Requesting symbol

Robots and indicators can request a symbol specifying its symbol code. Symbol objects behave like the default Symbol object of a robot or indicator, containing current Ask, Bid, PipSize and other useful properties.

Symbol symbol = MarketData.GetSymbol("USDJPY");

Print("Symbol: {0}, Ask: {1}, Bid: {2}", symbol.Code, symbol.Ask, symbol.Bid);

 

Requesting OHLCV series

Robots and indicators can request OHLCV series for multiple symbols and timeframes and build indicators based on it.

MarketSeries series = MarketData.GetSeries("EURCAD", TimeFrame.Minute15);
MovingAverage ma = Indicators.SimpleMovingAverage(series.Close, 20);

Print("Symbol: {0}, TimeFrame: {1}", series.SymbolCode, series.TimeFrame);
Print("Last Close: {0}, Average Close: {1}", series.Close.LastValue, ma.Result.LastValue);

 

Trading multiple symbols

Robots in cAlgo can execute orders for different symbols. To do this, the robot must request the needed symbol by its code. Then, it will be possible to use it in a trade request:

 Symbol symbol = MarketData.GetSymbol("GBPCHF");
 ExecuteMarketOrder(TradeType.Buy, symbol, 10000);

The new version of our Demo cTrader and cAlgo is released and can be downloaded from www.spotware.com

Backtesting of Multi-symbol robots in not supported at least for now. It can be implemented in future.

Is it possible to access bid/ask as time series? i.e. bid[index]. I don't see t1 as option timeframe  MarketData.GetSeries("EURUSD", TimeFrame.t1), or is that something I would have to build myself?

Thanks


@aharonzbaida

aharonzbaida
06 Sep 2015, 02:16

RE:

cAlgo_Development said:

We added new functionality to cAlgo - the ability for robots and indicators to work with multiple symbols. Now it's possible to use multiple symbol prices, OHLCV series and trade different symbols.

 

Requesting symbol

Robots and indicators can request a symbol specifying its symbol code. Symbol objects behave like the default Symbol object of a robot or indicator, containing current Ask, Bid, PipSize and other useful properties.

Symbol symbol = MarketData.GetSymbol("USDJPY");

Print("Symbol: {0}, Ask: {1}, Bid: {2}", symbol.Code, symbol.Ask, symbol.Bid);

 

Requesting OHLCV series

Robots and indicators can request OHLCV series for multiple symbols and timeframes and build indicators based on it.

MarketSeries series = MarketData.GetSeries("EURCAD", TimeFrame.Minute15);
MovingAverage ma = Indicators.SimpleMovingAverage(series.Close, 20);

Print("Symbol: {0}, TimeFrame: {1}", series.SymbolCode, series.TimeFrame);
Print("Last Close: {0}, Average Close: {1}", series.Close.LastValue, ma.Result.LastValue);

 

Trading multiple symbols

Robots in cAlgo can execute orders for different symbols. To do this, the robot must request the needed symbol by its code. Then, it will be possible to use it in a trade request:

 Symbol symbol = MarketData.GetSymbol("GBPCHF");
 ExecuteMarketOrder(TradeType.Buy, symbol, 10000);

The new version of our Demo cTrader and cAlgo is released and can be downloaded from www.spotware.com

Backtesting of Multi-symbol robots in not supported at least for now. It can be implemented in future.

Is it possible to access bid/ask as time series? i.e. bid[index]. I don't see t1 as option timeframe  MarketData.GetSeries("EURUSD", TimeFrame.t1), or is that something I would have to build myself?

Thanks


@aharonzbaida

Spotware
09 Sep 2015, 17:22

Dear Trader,

It's not possible. You could collect bid and ask prices in RunTime and then access them. 


@Spotware

aharonzbaida
28 Nov 2015, 19:11

RE: Multi-Symbol cBot OnTick() events

In a multi-symbol cBot, will the OnTick() method trigger for each incoming tick on every symbol used, or just on incoming ticks of the associated chart? Do I need to write code to check if Bid/Ask price changed on each symbol, and trigger an event for such occurrence?


@aharonzbaida

aharonzbaida
28 Nov 2015, 19:11

RE: Multi-Symbol cBot OnTick() events

In a multi-symbol cBot, will the OnTick() method trigger for each incoming tick on every symbol used, or just on incoming ticks of the associated chart? Do I need to write code to check if Bid/Ask price changed on each symbol, and trigger an event for such occurrence?


@aharonzbaida

aharonzbaida
28 Nov 2015, 19:12

RE: OnTick() in multi-symbol cBots

Spotware said:

Dear Trader,

It's not possible. You could collect bid and ask prices in RunTime and then access them. 

In a multi-symbol cBot, will the OnTick() method trigger for each incoming tick on every symbol used, or just on incoming ticks of the associated chart? Do I need to write code to check if Bid/Ask price changed on each symbol, and trigger an event for such occurrence?


@aharonzbaida

aharonzbaida
28 Nov 2015, 19:16

OnTick() in multi-symbol cBots

In a multi-symbol cBot, will the OnTick() method trigger for each incoming tick on every symbol used, or just on incoming ticks of the associated chart? Do I need to write code to check if Bid/Ask price changed on each symbol, and trigger an event for such occurrence?


@aharonzbaida

Spotware
30 Nov 2015, 20:26

Dear Trader,

OnTick() method is triggered on each incoming tick of the Symbol your cBot is set to run. 


@Spotware

oneplusoc
22 Apr 2016, 06:12

Dear all

how i can  draw the value only  of the rsi on the chart for multi time frame

for this indicator ?

 

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

namespace cAlgo.Indicators
{
    [Levels(30, 70, 80, 20)]

    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC)]
    public class MultiSymbolMA : Indicator
    {
        private RelativeStrengthIndex ma1, ma2, ma3, ma4;
        private MarketSeries series1, series2, series3, series4;
        private Symbol symbol1, symbol2, symbol3, symbol4;

        [Parameter(DefaultValue = "USDCAD")]
        public string Symbol1 { get; set; }

        [Parameter(DefaultValue = "EURAUD")]
        public string Symbol2 { get; set; }

        [Parameter(DefaultValue = "EURJPY")]
        public string Symbol3 { get; set; }

        [Parameter(DefaultValue = "GBPUSD")]
        public string Symbol4 { get; set; }

        [Parameter(DefaultValue = 5)]
        public int Period { get; set; }

        [Output("MA Symbol 1", Color = Colors.Red, PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries Result1 { get; set; }

        [Output("MA Symbol 2", Color = Colors.Magenta, PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries Result2 { get; set; }

        [Output("MA Symbol 3", Color = Colors.Yellow, PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries Result3 { get; set; }

        [Output("MA Symbol 4", Color = Colors.White, PlotType = PlotType.Line, Thickness = 1, LineStyle = LineStyle.Dots)]
        public IndicatorDataSeries Result4 { get; set; }

        protected override void Initialize()
        {
            symbol1 = MarketData.GetSymbol(Symbol1);
            symbol2 = MarketData.GetSymbol(Symbol2);
            symbol3 = MarketData.GetSymbol(Symbol3);
            symbol4 = MarketData.GetSymbol(Symbol4);

            series1 = MarketData.GetSeries(symbol1, TimeFrame);
            series2 = MarketData.GetSeries(symbol2, TimeFrame);
            series3 = MarketData.GetSeries(symbol3, TimeFrame);
            series4 = MarketData.GetSeries(symbol4, TimeFrame);

            ma1 = Indicators.RelativeStrengthIndex(series1.Close, Period);
            ma2 = Indicators.RelativeStrengthIndex(series2.Close, Period);
            ma3 = Indicators.RelativeStrengthIndex(series3.Close, Period);
            ma4 = Indicators.RelativeStrengthIndex(series4.Close, Period);

        }

        public override void Calculate(int index)
        {
            ShowOutput(symbol1, Result1, ma1, series1, index);
            ShowOutput(symbol2, Result2, ma2, series2, index);
            ShowOutput(symbol3, Result3, ma3, series3, index);
            ShowOutput(symbol4, Result4, ma4, series4, index);
        }

        private void ShowOutput(Symbol symbol, IndicatorDataSeries result, RelativeStrengthIndex RelativeStrengthIndex, MarketSeries series, int index)
        {

            int index2 = GetIndexByDate(series, MarketSeries.OpenTime[index]);

            result[index] = RelativeStrengthIndex.Result[index2];

            string text = string.Format("{0} {1}", symbol.Code, Math.Round(result[index], 0));

            ChartObjects.DrawText(symbol.Code, text, index + 1, result[index], VerticalAlignment.Center, HorizontalAlignment.Right, Colors.Yellow);

        }
        private int GetIndexByDate(MarketSeries series, DateTime time)
        {
            for (int i = series.Close.Count - 1; i >= 0; i--)
                if (time == series.OpenTime[i])
                    return i;
            return -1;
        }
    }
}


@oneplusoc

Spotware
22 Apr 2016, 11:02

Dear Trader,

We do not provide coding assistance services. We more than glad to assist you with specific questions about cAlgo.API. You can contact one of our Partners or post a job in Development Jobs section for further coding assistance.


@Spotware

brianchan661
21 Mar 2017, 03:24

Dear team,

Is it still not avaiable for backtesting yet?

Thanks


@brianchan661

brianchan661
21 Mar 2017, 03:24

Dear team,

Is multi symbol still not avaiable for back testing yet?

Thanks


@brianchan661

... Deleted by UFO ...

... Deleted by UFO ...

gunning.ernie
18 Dec 2017, 20:06

RE:

Spotware said:

Dear Trader,

OnTick() method is triggered on each incoming tick of the Symbol your cBot is set to run. 

Hi Guys,

This is a problem, a trading strategy should not be limited to one symbol ontick feed. We have a 1 to many relationship here as I have 1strategy being applied accrosss many symbols AND timeframes. I would siggests a Pubish subscribe pattern were so my bot can register to all the symbol ontick data feeds it wants to receive. Otherwise my other symbols which is not related to the bot's chart is only getting their updated data bassed on the chart's symbol so i will definitaly be delayed on my other symbols for data.

Hope im making sense,

This is a HUGEt issue for me...

A timer is not an option as I'm trading fundamentals (calendar news) and with a huge news events every micro second count. 

Any suggestions?


@gunning.ernie

gunning.ernie
18 Dec 2017, 20:17

RE:

Spotware said:

Dear Trader,

OnTick() method is triggered on each incoming tick of the Symbol your cBot is set to run. 

Hi Guys,

This is a big one for me. You cant have a trading strategy tied to 1 chart (one symbol and time frame). a trading strategy can be applied to many symbols and many timeframes. So you have a 1 to many relationship here apose to 1 to 1.

If my cbot trades 5 pairs and I register the bot to 1 chart of the 4 AND with what you telling me is that I will only receive ontick events for the 1 symbol on the chart, right? 

 

AND what you suggesting is to get the other symbols data on the Chats OnTick event... then the 4 symbols would only be processed when symbol 1 has a OnTick event. THIS IS A HUGE RISK TO ME

I would like to trade the calendar fundamentals and a micro split second is very important. Thus a timer based approach is also not feasable..

Is there no pub & sub (publish and subscribe pattern) were I can subscribe to for Ontick feeds for multiple symbols?


@gunning.ernie

PanagiotisCharalampous
19 Dec 2017, 14:54

Hi gunning.ernie,

The information in this post is a bit outdated. OnTick() method is called for all symbols retrieved using MarketData.GetSymbol(). See the following example

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 NewcBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        protected override void OnStart()
        {
            var EURUSD = MarketData.GetSymbol("EURUSD");
            var GBPUSD = MarketData.GetSymbol("GBPUSD");
            var EURJPY = MarketData.GetSymbol("EURJPY");
            var USDJPY = MarketData.GetSymbol("USDJPY");
        }

        protected override void OnTick()
        {
            Print("tick");
        }

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

In this case, OnTick() will be invoked for all four symbols.

Let me know if this helps you.

Best Regards,

Panagiotis


@PanagiotisCharalampous

gunning.ernie
21 Dec 2017, 06:46

RE:

Panagiotis Charalampous said:

Hi gunning.ernie,

The information in this post is a bit outdated. OnTick() method is called for all symbols retrieved using MarketData.GetSymbol(). See the following example

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 NewcBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        protected override void OnStart()
        {
            var EURUSD = MarketData.GetSymbol("EURUSD");
            var GBPUSD = MarketData.GetSymbol("GBPUSD");
            var EURJPY = MarketData.GetSymbol("EURJPY");
            var USDJPY = MarketData.GetSymbol("USDJPY");
        }

        protected override void OnTick()
        {
            Print("tick");
        }

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

In this case, OnTick() will be invoked for all four symbols.

Let me know if this helps you.

Best Regards,

Panagiotis

Thanks Panagiotis, This helps allot. This is my first stab at cALGO and i have noted on other post the same...they are old. You think certain functionality is not there then it is...

 

Thanks again for the effort.

Ernie


@gunning.ernie

irmscher9
16 Mar 2018, 18:49

Backtesting of Multiple Symbols in on bot still not supported?


@irmscher9

GammaQuant
17 May 2018, 23:43

Multi-symbol robots and indicators - Which Symbol Invoked OnTick?????

Hi Panagiotis or anyone else who knows

on testing this code above the cAlgo Symbol Interface only returns symbol data for the symbol that is selected with calgo to run the robot with but will invoke on ticks from the four symbols entered in the OnStart method.

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 NewcBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }
 
        protected override void OnStart()
        {
            var EURUSD = MarketData.GetSymbol("EURUSD");
            var GBPUSD = MarketData.GetSymbol("GBPUSD");
            var EURJPY = MarketData.GetSymbol("EURJPY");
            var USDJPY = MarketData.GetSymbol("USDJPY");
        }
 
        protected override void OnTick()
        {
            Print("Symbol -" + Symbol.Code + " |  Bid = " + Symbol.Bid );
        }
 
        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

How do i tell OnTick Method or Symbol Interface which Symbol Invoked it?


@GammaQuant

PanagiotisCharalampous
18 May 2018, 11:56

Hi GammaQuant,

Unfortunately you cannot tell for which Symbol was the OnTick() called.

Best Regards,

Panagiotis


@PanagiotisCharalampous

GammaQuant
21 May 2018, 17:16

RE:

Panagiotis Charalampous said:

Hi GammaQuant,

Unfortunately you cannot tell for which Symbol was the OnTick() called.

Best Regards,

Panagiotis

Hi Panagiotis

thank you for the last reply

Ok so i was trying to make some kind of work around property that invoke my own tick method on change but cAlgo wont build and gives me an error:

Unable to load assembly: "EurUsd" parameter must be an auto-property

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 MultiSymbolTest : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        public SymbolEvent EurUsd
        {
            get { return EurUsd; }
            set
            {
                var eurUsd = MarketData.GetSymbol("EURUSD");
                EurUsd = new SymbolEvent 
                {
                    Bid = eurUsd.Bid,
                    Ask = eurUsd.Ask
                };
                MyOnTick(eurUsd);
            }
        }

        protected override void OnStart()
        {
            // Put your initialization logic here
            var EURUSD = MarketData.GetSymbol("EURUSD");
            //var GBPUSD = MarketData.GetSymbol("GBPUSD");
            //var EURJPY = MarketData.GetSymbol("EURJPY");
            //var USDJPY = MarketData.GetSymbol("USDJPY");
        }

        /*protected override void OnTick()
        {
            // Put your core logic here
            Print("Symbol -" + Symbol.Code + " |  Bid = " + Symbol.Bid);
        }*/

        private void MyOnTick(Symbol symbol)
        {
            Print("Symbol -" + Symbol.Code + " |  Bid = " + Symbol.Bid);
        }

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

    public struct SymbolEvent
    {
        public double Ask;
        public double Bid;
    }
}

Wht is the situation with preset properties and calgo?


@GammaQuant

GammaQuant
21 May 2018, 18:26

RE: RE:

Sorry forget the above.........


@GammaQuant

ctid491211
10 Jun 2018, 23:23

RE:

Panagiotis Charalampous said:

Hi gunning.ernie,

The information in this post is a bit outdated. OnTick() method is called for all symbols retrieved using MarketData.GetSymbol(). See the following example

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 NewcBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        protected override void OnStart()
        {
            var EURUSD = MarketData.GetSymbol("EURUSD");
            var GBPUSD = MarketData.GetSymbol("GBPUSD");
            var EURJPY = MarketData.GetSymbol("EURJPY");
            var USDJPY = MarketData.GetSymbol("USDJPY");
        }

        protected override void OnTick()
        {
            Print("tick");
        }

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

In this case, OnTick() will be invoked for all four symbols.

Let me know if this helps you.

Best Regards,

Panagiotis

Hi!

Nice Trading Software! I came to the point, that I need to "subscribe" to multiple Symbols in one of my strategies. Now I just found your comment on this behaviour. Sadly there is nothing about this subject in the reference documentation (the documentation is really very minimalistic!). Would be nice to have more information about the exact behaviour of GetSymbol()! Clearly it would be nice to referece the Symbol which is updated in the OnTick() Callback Attributes. But I have one more request. Is it possible to Unsubscribe from a specific Symbol while the Bot / Indicator is running.

Best regards


@ctid491211

ctid491211
10 Jun 2018, 23:25

RE:

Panagiotis Charalampous said:

Hi gunning.ernie,

The information in this post is a bit outdated. OnTick() method is called for all symbols retrieved using MarketData.GetSymbol(). See the following example

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 NewcBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        protected override void OnStart()
        {
            var EURUSD = MarketData.GetSymbol("EURUSD");
            var GBPUSD = MarketData.GetSymbol("GBPUSD");
            var EURJPY = MarketData.GetSymbol("EURJPY");
            var USDJPY = MarketData.GetSymbol("USDJPY");
        }

        protected override void OnTick()
        {
            Print("tick");
        }

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

In this case, OnTick() will be invoked for all four symbols.

Let me know if this helps you.

Best Regards,

Panagiotis

Hi!

Nice Trading Software! I came to the point, that I need to "subscribe" to multiple Symbols in one of my strategies. Now I just found your comment on this behaviour. Sadly there is nothing about this subject in the reference documentation (the documentation is really very minimalistic!). Would be nice to have more information about the exact behaviour of GetSymbol()! Clearly it would be nice to referece the Symbol which is updated in the OnTick() callback attributes. But I have one more request. Is it possible to Unsubscribe from a specific Symbol while the Bot / Indicator is running.

Best regards


@ctid491211

bendyarm
16 Jun 2018, 16:53

RE:

Panagiotis Charalampous said:

Hi GammaQuant,

Unfortunately you cannot tell for which Symbol was the OnTick() called.

Best Regards,

Panagiotis

Disappointing to see there is no multi-instrument support for back tests.  Can you advise whether this functionality is likely to be available in future?

Thanks,

 

Finn


@bendyarm

bendyarm
16 Jun 2018, 16:59

RE: RE:

Disappointing to see there is no multi-instrument support for back tests.  Can you advise whether this functionality is likely to be available in future?

Thanks,

 

Bendyarm


@bendyarm

bediharry
02 Nov 2018, 21:55

GetSymbol Not supported for backtesting

Guys,
Will this functionality work for back testing and optimisation?

Thanks,

H


@bediharry

oliveira.phc
06 Dec 2018, 16:46

Adding an instance without a symbol

Hello there.

I want to have a robot with a single instance for listenning to some events, like `Positions.Closed` and `PendingOrders.Filled`, for example. This robot's responsibility is to create a new record on a database for each kind of event.

Is it possible to have a "symbol-less" instance?


@oliveira.phc

oliveira.phc
06 Dec 2018, 16:49

RE: Adding an instance without a symbol

oliveira.phc said:

Hello there.

I want to have a robot with a single instance for listenning to some events, like `Positions.Closed` and `PendingOrders.Filled`, for example. This robot's responsibility is to create a new record on a database for each kind of event.

Is it possible to have a "symbol-less" instance?

For that matter, also a "timeframe-less" instance?


@oliveira.phc

PanagiotisCharalampous
06 Dec 2018, 17:23

Hi oliveira.phc,

There is no such possibility at the moment.

Best Regards,

Panagiotis


@PanagiotisCharalampous

DelFonseca
02 Jul 2019, 21:05

Custom indicator multi timeframe

Hello,

Im using Renko indicator (https://ctrader.com/algos/indicators/show/1086) on a cBot for multi timeframe but i cant get the if brick is up or down in multi timeframe, only in single pair.
Where am i going wrong?
 

            AUDCADseries = MarketData.GetSeries("AUDCAD", TimeFrame.Hour);
            AUDCADrenko = Indicators.GetIndicator<Renko>(AUDCADseries, AUDCADrenko.Close, RenkoPips, BricksToShow, 3, "SeaGreen", "Tomato");

Thank you 


@DelFonseca

DelFonseca
02 Jul 2019, 21:09

Hello,

How can i call custom indicator for multi-timeframe? im trying calling Renko (https://ctrader.com/algos/indicators/show/1086) with the code below but it doesn't work:
 

            AUDCADseries = MarketData.GetSeries("AUDCAD", TimeFrame.Hour);
            AUDCADrenko = Indicators.GetIndicator<Renko>(AUDCADseries, RenkoPips, BricksToShow, 3, "SeaGreen", "Tomato");

Thank you!!


@DelFonseca

DelFonseca
02 Jul 2019, 21:09

Hello,

How can i call custom indicator for multi-timeframe? im trying calling Renko (https://ctrader.com/algos/indicators/show/1086) with the code below but it doesn't work:
 

            AUDCADseries = MarketData.GetSeries("AUDCAD", TimeFrame.Hour);
            AUDCADrenko = Indicators.GetIndicator<Renko>(AUDCADseries, RenkoPips, BricksToShow, 3, "SeaGreen", "Tomato");

Thank you!!


@DelFonseca

DelFonseca
02 Jul 2019, 21:10

RE:

Hello,

How can i call custom indicator for multi-timeframe? im trying calling Renko (https://ctrader.com/algos/indicators/show/1086) with the code below but it doesn't work:
 

            AUDCADseries = MarketData.GetSeries("AUDCAD", TimeFrame.Hour);
            AUDCADrenko = Indicators.GetIndicator<Renko>(AUDCADseries, RenkoPips, BricksToShow, 3, "SeaGreen", "Tomato");

Thank you!!


@DelFonseca

PanagiotisCharalampous
03 Jul 2019, 09:32

Hi DelTrader,

This indicator does not support custom timeframes.

Best Regards,

Panagiotis


@PanagiotisCharalampous

constantromeo1987
13 Sep 2019, 18:28

Hi Spotware Team, nice improvements. I still cannot run average true range indicator on multiple symbols.

 

Please could you let us know when the feature will be available or if there is a way to get around the problem.

 

Thanks in advance.

 

Regards,

Abhi


@constantromeo1987

constantromeo1987
13 Sep 2019, 18:29

RE: RE: RE: Multi-symbol robots and indicators

Abhi said:

Spotware said:

Abhi said:

Hi Spotware Team, nice improvements. I still cannot run average true range indicator on multiple symbols.

 

Please could you let us know when the feature will be available or if there is a way to get around the problem.

 

Thanks in advance.

 

Regards,

Abhi

Please specify what you mean by saying that. You can use multi-symbol data in code of your indicator. You can also add ATR to several charts.

I want to show ATR for multiple symbols on a single chart. The  method call "Indicators.AverageTrueRange(int period , MovingAverageType.Exponential)" can be only called for a single symbol in a chart. Is there anyway to call ATR on multiple symbols and show up on a chart like you showed for RelativeStrengthIndex in this forum on previous posts.

 

Does it make sense now.

 


@constantromeo1987

danblackadder
11 Nov 2019, 14:03

BUMP. Multi-symbol support in back testing when? I have been waiting over 2 years for this... 


@danblackadder

PanagiotisCharalampous
11 Nov 2019, 16:42

RE:

danblackadder said:

BUMP. Multi-symbol support in back testing when? I have been waiting over 2 years for this... 

Hi danblackadder,

It will be included in 3.7

Best Regards,

Panagiotis


@PanagiotisCharalampous

taha.benbrahim.ic
21 Nov 2019, 10:01

Multiple Renko charts

Hi,

Can i access a multiple  Renko charts with 

MarketSeries series = MarketData.GetSeries("EURCAD", TimeFrame.Minute15);

Thanks.

 


@taha.benbrahim.ic

ctid1574514
23 Nov 2019, 03:15

RE: RE:

Panagiotis Charalampous said:

danblackadder said:

BUMP. Multi-symbol support in back testing when? I have been waiting over 2 years for this... 

Hi danblackadder,

It will be included in 3.7

Best Regards,

Panagiotis

https://ctrader.com/forum/suggestions/21283?page=6#post-56

 

3.7 will be before Xmas


@ctid1574514

ctid1574514
23 Nov 2019, 03:16

RE: RE:

Panagiotis Charalampous said:

danblackadder said:

BUMP. Multi-symbol support in back testing when? I have been waiting over 2 years for this... 

Hi danblackadder,

It will be included in 3.7

Best Regards,

Panagiotis

https://ctrader.com/forum/suggestions/21283?page=6#post-56

3.7 will be before xmas 


@ctid1574514

DelFonseca
02 Jan 2020, 23:59

RE: Correlation Coefficient

cAlgo_Fanatic said:

The correlation coefficient compares how currency pairs have moved in relation to each other.

The correlation coefficient formula is:

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

namespace cAlgo.Indicators
{
    [Levels(-1, -0.5, 0, 0.5, 1)]
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, ScalePrecision = 2)]
    public class CorrelationCoefficient : Indicator
    {
        private MarketSeries series2;
        private Symbol symbol2;

        [Parameter(DefaultValue = "EURUSD")]
        public string Symbol2 { get; set; }

        [Parameter(DefaultValue = 22)]
        public int Period { get; set; }

        [Output("Correlation Coefficient", Color = Colors.Yellow)]
        public IndicatorDataSeries Result { get; set; }

        protected override void Initialize()
        {
            symbol2 = MarketData.GetSymbol(Symbol2);
            series2 = MarketData.GetSeries(symbol2, TimeFrame);
        }

        public override void Calculate(int index)
        {
            if (index < Period)
                return;

            double sumX = 0, sumY = 0, sumXY = 0, sumX2 = 0, sumY2 = 0;
            double x, y, x2, y2;

            int index2 = GetIndexByDate(series2, MarketSeries.OpenTime[index]);

            if (index2 == -1)
                return;

            for (int i = 0; i < Period; i++)
            {
                x = MarketSeries.Close[index - i];
                y = series2.Close[index2 - i];

                x2 = x * x;
                y2 = y * y;
                sumX += x;
                sumY += y;
                sumXY += x * y;
                sumX2 += x2;
                sumY2 += y2;
            }

            Result[index] = (Period * (sumXY) - sumX * sumY) / 
                               Math.Sqrt((Period * sumX2 - sumX * sumX) * (Period * sumY2 - sumY * sumY));
        }

        private int GetIndexByDate(MarketSeries series, DateTime time)
        {
            for (int i = series.Close.Count - 1; i >= 0; i--)
            {
                if (time == series.OpenTime[i])
                    return i;
            }
            return -1;
        }
    }
}

 

Good night,

 

I want to get the correlation of 2 symbols, for example EURGBP with GBPCHF but showing on EURUSD chart.

Can someone help me? 

Thank you so much

@DelFonseca

kerrifox19
13 Jan 2020, 16:39

RE: RE: Correlation Coefficient

Thanks for sharing this useful information with us.

 


@kerrifox19

... Deleted by UFO ...

... Deleted by UFO ...

cAlgo_Fanatic
19 Sep 2013, 15:46

Correlation Coefficient

The correlation coefficient compares how currency pairs have moved in relation to each other.

The correlation coefficient formula is:

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

namespace cAlgo.Indicators
{
    [Levels(-1, -0.5, 0, 0.5, 1)]
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, ScalePrecision = 2)]
    public class CorrelationCoefficient : Indicator
    {
        private MarketSeries series2;
        private Symbol symbol2;

        [Parameter(DefaultValue = "EURUSD")]
        public string Symbol2 { get; set; }

        [Parameter(DefaultValue = 22)]
        public int Period { get; set; }

        [Output("Correlation Coefficient", Color = Colors.Yellow)]
        public IndicatorDataSeries Result { get; set; }

        protected override void Initialize()
        {
            symbol2 = MarketData.GetSymbol(Symbol2);
            series2 = MarketData.GetSeries(symbol2, TimeFrame);
        }

        public override void Calculate(int index)
        {
            if (index < Period)
                return;

            double sumX = 0, sumY = 0, sumXY = 0, sumX2 = 0, sumY2 = 0;
            double x, y, x2, y2;

            int index2 = GetIndexByDate(series2, MarketSeries.OpenTime[index]);

            if (index2 == -1)
                return;

            for (int i = 0; i < Period; i++)
            {
                x = MarketSeries.Close[index - i];
                y = series2.Close[index2 - i];

                x2 = x * x;
                y2 = y * y;
                sumX += x;
                sumY += y;
                sumXY += x * y;
                sumX2 += x2;
                sumY2 += y2;
            }

            Result[index] = (Period * (sumXY) - sumX * sumY) / 
                               Math.Sqrt((Period * sumX2 - sumX * sumX) * (Period * sumY2 - sumY * sumY));
        }

        private int GetIndexByDate(MarketSeries series, DateTime time)
        {
            for (int i = series.Close.Count - 1; i >= 0; i--)
            {
                if (time == series.OpenTime[i])
                    return i;
            }
            return -1;
        }
    }
}

 


@cAlgo_Fanatic