SC to Multicharts.NET

Questions about MultiCharts .NET and user contributed studies.
TicksCollector
Posts: 9
Joined: 22 Jan 2014
Has thanked: 5 times
Been thanked: 1 time

SC to Multicharts.NET

Postby TicksCollector » 02 Feb 2014

Hi,

Coming from SC (SC), lots of things in MC.NET look different.
In SC you develop in their own language (called ACSIL) which is pretty close in style to Easylanguage so things are very clear.
But since it's actually C++ underneath it, if you need/want something that is not encapsulated in ACSIL, you can simply use C++ code in the same study and it will compile just fine.

With that said, I see that MC.NET supports only C#.NET programming.
I'm not a professional programmer and I just learn as I go (after 3 years I've developed a plethora of complex tools in SC).
I tried going over C# codes in MC.NET, but since you don't give any remarks in the code of what you do there... it's even harder to "learn as I go" :-)

Please help me convert this small code snippet from SC to MC.NET which will give me some insight of how things are done in MC.NET.
This code snippet simply gets the system times of when bars were created and stores them in an array:

Code: Select all

int& IndexFollow = sc.PersistVars->i1;

if (IndexFollow < sc.Index)
{
OpenTime[sc.Index] = sc.CurrentSystemDateTime.GetTime();
IndexFollow = sc.Index;
}
Explanations for the code:

sc.Index = an ACSIL member that holds the last (or current) bar's index number.
In SC the first bar that is load into a chart gets Index number 0. the second bar gets Index number 1 etc etc.
Every time a new bar is added, sc.Index grows by 1.
When that happens I simply store the system time (sc.CurrentSystemDateTime.GetTime()) in an array which is indexed by the bars Indexes (OpenTime[sc.Index]).

In order to get just the bar's creation time, I need to "lock" the if statement and I do that with an int variable called IndexFollow.
But since a regular variable will get over written with each new tick in the current bar, SC gives an option to create a persistent var like this:
int& IndexFollow = sc.PersistVars->i1;
(you can declare persistent int, float, double and DateTime)

Looking on code examples in MC.NET and reading your wiki, I couldn't see how can I translate this little code snippet.
How do you index bars?
Where it is stored?
How do you create persistent (static?) vars?


Please help :-)

MidKnight
Posts: 343
Joined: 12 Aug 2012
Has thanked: 123 times
Been thanked: 56 times

Re: SC to Multicharts.NET

Postby MidKnight » 03 Feb 2014

G'day TicksCollector,

I used SC for a time and its a good platform for the price. I personally hated their model for writing customized studies but I have a good friend (Kiwi, you have maybe heard of him) that just loves it.

I'm by no means an expert on MC.net but will help where I can.

The bars time comes from your datafeed so there is no need to track it like in your example. All you need to figure it out is:

Code: Select all

Bars.Time[0].TimeOfDay]
How do you index bars?
Bars are indexed relative from the current bar being processed by CalcBar(). As in the snippet above, the reference to Time[0] is referencing the current bar being processed by CalcBar(). When the chart loads, it will run that for every bar put on the chart and also for subsequent real-time bars created.
Where it is stored?
It is stored within the local database on your C: by default. I think its a silly idea that the MC.net team decided not to put it with the assigned installation directory, but that is what they do. You can move it and there is docs to describe the process but that is a different topic....
How do you create persistent (static?) vars?
Perhaps you should read a little on object oriented programming to answer this properly. Do some simple objects in C# tutorials. Maintaining state and their accompanied sound principles is no different in MC.net.

I hope this helps a bit. I've used about a dozen platforms over my 10 years trading and they all had issues that I didn't like in some way. MC.net isn't a perfect platform but its quite easily extended and pretty good value. It will take you time to become familiar.

With kind regards,
MK

TicksCollector
Posts: 9
Joined: 22 Jan 2014
Has thanked: 5 times
Been thanked: 1 time

Re: SC to Multicharts.NET

Postby TicksCollector » 04 Feb 2014

Hey MK,
Thanks for taking the challenge :-)

Yes I know Kiwi, good man and very knowledgeable about SC's inner workings.
I too like programming in SC, the ability to have ACSIL and C++ in the same study code is a great option, but as you said no platform is perfect which is why I'm looking to MC to complement some SC shortfalls (for starters anyway).
The bars time comes from your datafeed so there is no need to track it like in your example. All you need to figure it out is:

Code: Select all

Bars.Time[0].TimeOfDay]
That's nice!
In SC I can't get the data feed's time stamp that easily...
So this gives me the data feed's "bar open" time stamp down to seconds resolutions.
And to extract milliseconds from that stamp I do this?

Code: Select all

MillisecondsFromDateTime(Bars.Time[0].TimeOfDay)
Bars are indexed relative from the current bar being processed
Ah ok so you don't have a way to know (easily) that a new bar was added or how many bars are loaded...
No Problem.
Where it is stored?
It is stored within the local database on your C: by default.
I wanted to know where MC.NET keeps the bars index... which now I obviously know they don't.
How do you create persistent (static?) vars?
Perhaps you should read a little on object oriented programming to answer this properly. Do some simple objects in C# tutorials. Maintaining state and their accompanied sound principles is no different in MC.net.
I went over few C# videos, don't remember seeing anything that explains this part.
What should I look for? which subject?
I know I'm missing something just not sure what :-)
It will take you time to become familiar.
No kidding lol

My object is to asses the latency of bars by subtracting the feed's time stamp from my local time.
So if above I have the "data feed's" bar's open time stamp, and also extracted its millisecond part, is there a member that gives (that easily) the "computer/local/system" time stamp of when the bar was opened/created?
If not, will that be a correct way to get what I want in MC.NET?

Code: Select all

if (DataFeedDateTimeVariable != Bars.Time[0].TimeOfDay) // meaning a new bar was created
{
ComputerDateTimeVariable = ComputerDateTime;
DataFeedDateTimeVariable = Bars.Time[0].TimeOfDay;
// and latency will be = ComputerDateTimeVariable - DataFeedDateTimeVariable
}

Thanks again.

MidKnight
Posts: 343
Joined: 12 Aug 2012
Has thanked: 123 times
Been thanked: 56 times

Re: SC to Multicharts.NET

Postby MidKnight » 04 Feb 2014

In SC I can't get the data feed's time stamp that easily...
So this gives me the data feed's "bar open" time stamp down to seconds resolutions.
And to extract milliseconds from that stamp I do this?
The bars timestamp in MC.net is the bar close time. This is common amongst most other platforms too. SC was the only platform I have used to date that uses the timestamp as the open.

Code: Select all

Bars.Time[0]
Will give you a datetime object. To extract the milliseconds from that time object you should probably refer to the C# API docs at microsoft. I'm no expert in the language and constantly refer to the C# and MC.net API docs whenever I code anything.

Ah ok so you don't have a way to know (easily) that a new bar was added or how many bars are loaded...
No Problem.
You can tell when a new bar is added because if you set your indicator settings to "update on every tick" unchecked your CalcBar() code will run at the end of every bar. If instead you mean you don't know how to differentiate between chart loading bars and real-time bars - there is a flag you can check within the MC.net API but I cannot recall what it was exactly. It has been posted on the forums somewhere and is in the API somewhere.... With regard to knowing how many bars are loaded, there is a property called CurrentBar that gives you the current bars bar number. Combined with the LastBarOnChart property you could get the number of bars loaded on the chart.

I went over few C# videos, don't remember seeing anything that explains this part.
What should I look for? which subject?
I know I'm missing something just not sure what :-)
Just any tutorials so you can understand what Classes and Objects are. Objects have state and behaviour.

GL on the journey - bring food :)

With kind regards,
MK

TicksCollector
Posts: 9
Joined: 22 Jan 2014
Has thanked: 5 times
Been thanked: 1 time

Re: SC to Multicharts.NET

Postby TicksCollector » 08 Feb 2014

The bars timestamp in MC.net is the bar close time. This is common amongst most other platforms too. SC was the only platform I have used to date that uses the timestamp as the open.
Yea I've seen it now..... this is weird.
With close time as time stamp if ES opens in my local time of 16:30:00 it means I can never know which bar is the open bar. the same bar will have a different time stamp depending on the periodicity:
16:35:00 with 5 min bars
17:00:00 with 30 min bars
20:30:00 with 240 min bars
And with Range/Tick/Volume/Renko bars? ... any guess is true.
Sorry, this is so wrong on so many levels :-)
SC got it right.

Anyway, after trying to figure things thru MC's hlp file (more confusing than helping) and the online wiki, I just sat down, started writing code with what I know so far and simply went thru over members/properties/etc via intellisense.
Common sense always win and I got my code up and running.

I still don't know how to declare a Persistant variable in C# (var that won't get over written by its own deceleration in a loop), but I thought about the logic of what I wanted to achieve and figured I don't really need it at all.

So there IS an Index for bars in MC :-)
You said so yourself, "CurrentBar" is the executing bar (like sc.Index in SC) and there are couple of properties that give the "total loaded bars" (like sc.ArraySize in SC).
Good to know.


Many thanks for helping out.
TC

MidKnight
Posts: 343
Joined: 12 Aug 2012
Has thanked: 123 times
Been thanked: 56 times

Re: SC to Multicharts.NET

Postby MidKnight » 09 Feb 2014

Howdy,

Checking for the first bar of the day is not hard and there are probably several ways to do it either through using the Session or Bars.LastBarInSession.

If you want to save state in your code outside of the CalcBar() loop, you put your variable into the object. If you have many variables saving similar state, you consider making a new class and then referencing it in your indicator object. This is how its done in all object-orientated languages.

Yeah CurrentBar could be thought of as index of the last bar on the chart but you don't really use it often (well at least I don't). Most of the time you are indexing relative to the current bar being processed and your indexes offset from that. You don't have to do stuff like CurrentBar - 1 to get the previous bar, you just use 1.

Glad you got your stuff figured out in the end - nice work!


Return to “MultiCharts .NET”