Input's location

Questions about MultiCharts .NET and user contributed studies.
GTrader
Posts: 83
Joined: 30 Oct 2012
Has thanked: 24 times
Been thanked: 8 times

Input's location

Postby GTrader » 21 Oct 2015

Question: Why do the inputs for a study have to be at a particular place within the class?

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Input's location

Postby JoshM » 22 Oct 2015

Question: Why do the inputs for a study have to be at a particular place within the class?
Because they are C# properties (so methods), and therefore need to be placed inside the indicator's or strategy's class (because all methods need to be placed inside a class). They can also not be placed inside another method (or property), because methods can't be nested (but they can call each other, though).

However, besides those limitations the properties can be placed everywhere. For instance:

Code: Select all

namespace PowerLanguage.Indicator
{
public class Snippet_Indicator : IndicatorObject
{
[Input]
public int FirstInput { get; set; }

public Snippet_Indicator(object _ctx) : base(_ctx) { }

protected override void StartCalc()
{
}

[Input]
public int SecondInput { get; set; }

protected override void CalcBar()
{
}

[Input]
public int ThirdInput { get; set; }
}
}
So they do have a particular place (they need to be placed inside the class), but as long as they are in the class they can be placed at several locations. It's just convention and a matter of personal preference to place them at the top.

More about properties can be found here: MSDN and MSDN properties.

GTrader
Posts: 83
Joined: 30 Oct 2012
Has thanked: 24 times
Been thanked: 8 times

Re: Input's location

Postby GTrader » 22 Oct 2015

Hi Josh,
I should have been clearer on my question. The problem I am running into is that if I move my properties to the bottom of the class definition the strategy compiles fine but when I add it to a chart I receive an error. If I move my properties right after the class constructor everything works fine when I add it to a chart.

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Input's location

Postby JoshM » 22 Oct 2015

I should have been clearer on my question. The problem I am running into is that if I move my properties to the bottom of the class definition the strategy compiles fine but when I add it to a chart I receive an error. If I move my properties right after the class constructor everything works fine when I add it to a chart.
Not sure if I follow you. Do you mean the properties themselves (like the ones I showed in the code example in my post), or giving the properties a default value?

If I add the snippet example from my previous post to the chart, it works fine (on MultiCharts .NET64 Version 9.0 Release (Build 10362)):

Image

I don't have the issue that the last property (`ThirdInput` which is at the bottom of the class) doesn't work or gives an error.
Attachments
scr.22-10-2015 17.31.14.png
(1.5 KiB) Downloaded 986 times

GTrader
Posts: 83
Joined: 30 Oct 2012
Has thanked: 24 times
Been thanked: 8 times

Re: Input's location

Postby GTrader » 28 Oct 2015

That's exactly the issue I'm having. No big deal as I can just put them up further in the class definition for the strategy I'm working on, but I assumed that it was a requirement or something.


Return to “MultiCharts .NET”