Using standard C# array in strategy

Questions about MultiCharts .NET and user contributed studies.
Drogo
Posts: 14
Joined: 11 Oct 2012
Has thanked: 2 times

Using standard C# array in strategy

Postby Drogo » 27 Apr 2015

Hello,

I have question about using standard C# multidimensional arrays.
Can I use it in strategy? Is there any limitation? Could be there problem with back testing and optimizing?

There is simple example of "Signals" array:
using System;
using System.Drawing;
using PowerLanguage.Function;
using ATCenterProxy.interop;

namespace PowerLanguage.Strategy
{
public class ExampleStrategyArray : SignalObject
{
public ExampleStrategyArray(object _ctx) : base(_ctx) { }
private double[,] Signals = new double[100, 3];
private int CurrentArrIndex = 0;
private IOrderPriced buy_order;
private double BuyLimitPrice = 0;
private int arrSize = 0;
private VariableSeries<Double> m_fastavg;

private VariableSeries<Double> m_slowavg;
private AverageFC m_averagefc1;

private AverageFC m_averagefc2;
protected override void Create()
{
// create variable objects, function objects, order objects etc.
buy_order = OrderCreator.Limit(new SOrderParameters(Contracts.Default, EOrderAction.Buy));
m_averagefc1 = new AverageFC(this);
m_averagefc2 = new AverageFC(this);
m_fastavg = new VariableSeries<Double>(this);
m_slowavg = new VariableSeries<Double>(this);
}
protected override void StartCalc()
{
arrSize = Signals.GetLength(0);

m_averagefc1.price = Bars.Close;
m_averagefc1.length = 5;
m_averagefc2.price = Bars.Close;
m_averagefc2.length = 50;
}
protected override void CalcBar()
{
if (Bars.Status == EBarState.Open && this.CrossesOver(m_fastavg, m_slowavg))
{

for (int i = 0; i < arrSize; i++)
{
if (Signals[i, 0] == 0)
{
CurrentArrIndex = i;
break;
}
}
Signals[CurrentArrIndex, 0] = Bars.LowValue;
Signals[CurrentArrIndex, 1] = Bars.CloseValue;
Signals[CurrentArrIndex, 2] = Bars.OpenValue;

}

if (Bars.Status == EBarState.Close && StrategyInfo.MarketPosition == 0)
{
BuyLimitPrice = 0;
for (int i = 0; i < arrSize; i++)
{
if (Signals[i, 0] > 0 && Bars.LowValue - Signals[i, 0] > BuyLimitPrice)
{
BuyLimitPrice = Signals[i, 0];

}
}
}



if (BuyLimitPrice > 0 && StrategyInfo.MarketPosition == 0)
{
buy_order.Send(BuyLimitPrice);
}

}
}
}

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Using standard C# array in strategy

Postby Henry MultiСharts » 29 Apr 2015

Hello,

I have question about using standard C# multidimensional arrays.
Can I use it in strategy? Is there any limitation? Could be there problem with back testing and optimizing?
Hello Drogo,

You should be able to use C# multidimensional arrays in a strategy without any limitations/issues.

novaleaf
Posts: 49
Joined: 17 Apr 2014
Has thanked: 9 times
Been thanked: 4 times

Re: Using standard C# array in strategy

Postby novaleaf » 05 May 2015

@Henry, I assumed arrays would cause problems with backtesting / historical data: either scrolling back or jumping to and replaying timesteps. Is this not the case?

Drogo
Posts: 14
Joined: 11 Oct 2012
Has thanked: 2 times

Re: Using standard C# array in strategy

Postby Drogo » 05 May 2015

Hello Henry,

I have problems with backtesting and optimization. When I use standard arrays in strategy. It causes that sometimes stop calculating. There is not any error. It calculates for example 2 years of five. In two years there are 200 trades and then nothing. If I recompile the strategy or I remove it and add it , results are calculated correctly.

I use two two dimension arrays [500,5]. In chart with two regular instruments. One instrument is 1 minute and second 30 minute with normal candlesticks.

I use the newest version .net. MultiCharts .NET64 Version 9.0 Release (Build 10761).

Drogo
Attachments
stop.PNG
(31.27 KiB) Downloaded 1433 times

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Using standard C# array in strategy

Postby Henry MultiСharts » 06 May 2015

Hello Henry,

I have problems with backtesting and optimization. When I use standard arrays in strategy. It causes that sometimes stop calculating. There is not any error. It calculates for example 2 years of five. In two years there are 200 trades and then nothing. If I recompile the strategy or I remove it and add it , results are calculated correctly.

I use two two dimension arrays [500,5]. In chart with two regular instruments. One instrument is 1 minute and second 30 minute with normal candlesticks.

I use the newest version .net. MultiCharts .NET64 Version 9.0 Release (Build 10761).

Drogo
Hello Drogo,

In order to analyze this case please send the following information to support@multicharts.com:
- workspace you are using;
- in QuoteManager select the symbol you are using, make a right click on it->Export data->Export instrument (with data). Attach the Qmd export file for analysis;
- in PowerLanguage .NET editor->File->Export->export the studies you are using for replicating this behavior; send us the pln file;
- instructions for replicating this behavior.

novaleaf
Posts: 49
Joined: 17 Apr 2014
Has thanked: 9 times
Been thanked: 4 times

Re: Using standard C# array in strategy

Postby novaleaf » 06 May 2015

@Henry, I assumed arrays would cause problems with backtesting / historical data: either scrolling back or jumping to and replaying timesteps. Is this not the case?
Indeed, I just ran into this problem when "jumping" back to replay timesteps.

If you use your own array or list, you need to clear or recreate it in the StartCalc() method. Such as:

Code: Select all

protected override void StartCalc()
{
this.sessionData = new List<SessionData>();
}


Return to “MultiCharts .NET”