Startegy computing with BarsOfData(2) - debuging problem  [SOLVED]

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

Startegy computing with BarsOfData(2) - debuging problem

Postby Drogo » 17 Apr 2015

Hello,

On basis your ExampleIndicator I made ExampleStrategy to see how strategy is built with more than one data stream.
code:
------
using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;
using ATCenterProxy.interop;

namespace PowerLanguage.Strategy {
public class ExampleStrategy : SignalObject {
public ExampleStrategy(object _ctx):base(_ctx){
Output.Clear();
Output.WriteLine("Class constructor method");
}
private IOrderMarket buy_order;
protected override void Create() {
// create variable objects, function objects, order objects etc.
buy_order = OrderCreator.MarketNextBar(new SOrderParameters(Contracts.Default, EOrderAction.Buy));
Output.WriteLine("Create() method");
}
protected override void StartCalc() {
// assign inputs
Output.WriteLine("StartCalc() method");
}
protected override void CalcBar(){
// strategy logic
//buy_order.Send();
if (Bars.CurrentBar <= 10)
{
Output.WriteLine(" CalcBar() method: Bar number: {0}", Bars.CurrentBar);
}
if (BarsOfData(2).CurrentBar <= 5)
{
Output.WriteLine(" CalcBar() method: BarsOfData number: {0}", BarsOfData(2).CurrentBar);
}
}

}}
------
So for the strategy I use two instruments(data) (1min and 5 min.)
And there is result:
Class constructor method
Create() method
StartCalc() method
CalcBar() method: Bar number: 1
StartCalc() method
CalcBar() method: Bar number: 1
CalcBar() method: BarsOfData number: 1
CalcBar() method: Bar number: 2
CalcBar() method: BarsOfData number: 1
CalcBar() method: Bar number: 3
CalcBar() method: BarsOfData number: 1
CalcBar() method: Bar number: 3
CalcBar() method: BarsOfData number: 2
CalcBar() method: Bar number: 4
CalcBar() method: BarsOfData number: 2
CalcBar() method: Bar number: 5
CalcBar() method: BarsOfData number: 2
CalcBar() method: Bar number: 5
CalcBar() method: BarsOfData number: 3
CalcBar() method: Bar number: 6
CalcBar() method: BarsOfData number: 3
CalcBar() method: Bar number: 7
CalcBar() method: BarsOfData number: 3
CalcBar() method: Bar number: 7
CalcBar() method: BarsOfData number: 4
CalcBar() method: Bar number: 8
CalcBar() method: BarsOfData number: 4
CalcBar() method: Bar number: 9
CalcBar() method: BarsOfData number: 4
CalcBar() method: Bar number: 10
CalcBar() method: BarsOfData number: 4
CalcBar() method: BarsOfData number: 4
CalcBar() method: BarsOfData number: 5
CalcBar() method: BarsOfData number: 5
CalcBar() method: BarsOfData number: 5


So why StartCalc() method and all code above row where is used BarsOfData (for first time) is called twice?
It cause problem while debugging in Visual studio as well:
'BarsOfData(2)' threw an exception of type 'ManagedStudies.details._ELAPI_exception_Wrap_' int

Is the any way how to handle the code to have process strategy correct with more then one data?
Thank you in advance.
Attachments
error.png
Visual Studio Error
(30.92 KiB) Downloaded 798 times
Capture.PNG
Setting Chart
(86.94 KiB) Downloaded 787 times

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

Re: Startegy computing with BarsOfData(2) - debuging problem  [SOLVED]

Postby Henry MultiСharts » 22 Apr 2015

So why StartCalc() method and all code above row where is used BarsOfData (for first time) is called twice?
Hello Drogo,

Please see the following post.
It cause problem while debugging in Visual studio as well:
'BarsOfData(2)' threw an exception of type 'ManagedStudies.details._ELAPI_exception_Wrap_' int
You need to configure the VIsualStudio to catch only the exceptions you need, not all of them.


Return to “MultiCharts .NET”