Newbie question about AverageFC  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
bobrovartiom
Posts: 8
Joined: 12 Mar 2016
Has thanked: 1 time

Newbie question about AverageFC

Postby bobrovartiom » 12 Mar 2016

Sorry for the newbie question but I am just starting to learn Multicharts and can not figure out next thing:
I am watching the code Mov_Avg_1_Line study. I see the instance of the class AverageFC

Code: Select all

private AverageFC m_averagefc1;
I understand what it is doing. But when I enter the AverageFC class here is the code:

Code: Select all

public class AverageFC : FunctionSimple<double>
{
public AverageFC(CStudyControl ctx);
public AverageFC(CStudyControl ctx, int data_stream);

public int length { get; set; }
public ISeries<double> price { get; set; }

protected override double CalcBar();
protected override void Create();
protected override void StartCalc();
}
So I completely do not understand where it calculates the moving Average. I see no method for this here. Where does it happen at all?

Thanks!

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

Re: Newbie question about AverageFC  [SOLVED]

Postby JoshM » 14 Mar 2016

So I completely do not understand where it calculates the moving Average. I see no method for this here. Where does it happen at all?
I suppose you use an external IDE like Visual Studio? I also don't see that function's code in Visual Studio. But in the PowerLanguage .NET Editor, the `AverageFC` function shows the following code:

Code: Select all

using System;

namespace PowerLanguage.Function
{
public class AverageFC : FunctionSimple<Double>
{
private SummationFC m_summationfc1;

public AverageFC(CStudyControl ctx) :
base(ctx) {}

public AverageFC(CStudyControl ctx, int data_stream) :
base(ctx, data_stream) {}

public ISeries<Double> price { get; set; }

public Int32 length { get; set; }

protected override void Create(){
m_summationfc1 = new SummationFC(this);
}

protected override void StartCalc(){
m_summationfc1.price = price;
m_summationfc1.length = length;
}


protected override double CalcBar(){
return m_summationfc1[0] / length;
}
}
}
The `SummationFC` function that it references has the following code:

Code: Select all

using System;

namespace PowerLanguage.Function
{
public class SummationFC : FunctionSeries<Double>
{

private VariableSeries<Double> m_sum;

public SummationFC(CStudyControl ctx) :
base(ctx) {}

public SummationFC(CStudyControl ctx, int data_stream) :
base(ctx, data_stream) {}

public ISeries<Double> price { get; set; }

public Int32 length { get; set; }

protected override void Create(){
m_sum = new VariableSeries<Double>(this);
}

protected override void StartCalc(){
}

private void on_first_bar(){
m_sum.Value = 0;
for (var i = 0; i < length; ++i)
m_sum.Value += price[i];
}


protected override double CalcBar(){
if (Bars.CurrentBar == 1)
on_first_bar();
else
m_sum.Value = m_sum[1] + price.Value- price[length];
return m_sum.Value;
}
}
}

bobrovartiom
Posts: 8
Joined: 12 Mar 2016
Has thanked: 1 time

Re: Newbie question about AverageFC

Postby bobrovartiom » 14 Mar 2016

JoshM,

Thanks a lot, you are right. Under some reason in VS I see no implementation in these functions, but in PL.NET Editor everything is clear.

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

Re: Newbie question about AverageFC

Postby Henry MultiСharts » 06 Apr 2016

From MultiCharts .NET FAQ post #9:
Everything you need to know about MultiCharts .Net functions:
  • The source code of the functions has been opened in MultiCharts 8.5.
  • Functions are not in VS solution, they are built-in in PLEditor.
  • That means prebuilt functions cannot be seen in Visual Studio.
  • Prebuilt functions are read-only and cannot be exported.
  • You can create new functions from PowerLanguage .Net editor only.
  • User created functions are present in VS solution and can be exported/imported in PLEditor.
  • After each change in a function you need to remove and re-add the strategy to the chart.
  • MC.NET does not analyze the script to know if any functions are used and if they were modified.


Return to “MultiCharts .NET”