MC.net: (Multi-Timeframe) EMA @ Weekly Data on Daily Chart  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
rc76
Posts: 51
Joined: 14 Oct 2020
Has thanked: 17 times

MC.net: (Multi-Timeframe) EMA @ Weekly Data on Daily Chart

Postby rc76 » 10 Jun 2021

Capture.JPG
(220.89 KiB) Not downloaded yet
I have two data series on a QQQ daily chart:

QQQ @ daily
QQQ @ weekly (invisible candle)

I have created a default EMA (Mov_Avg_Exponetial) with same period on both QQQ_daily and QQQ_weekly data series

EMA_daily = CYAN
EMA_weekly = RED

I have created the same EMA using ToS. (attached image).
Capture.JPG
(220.89 KiB) Not downloaded yet
As you can see, the EMA_weekly_RED from ToS has a sort of "stepped line" instead of the "smoothed line" in MC. Why is that?

I think other trading platforms also generated this kind of "stepped line" when imposing higher timeframe lines onto lower timeframe chart.

Is there anyway we can make the MC's EMA to generate the same "stepped line" as in ToS?
Last edited by rc76 on 12 Jun 2021, edited 1 time in total.

User avatar
Vlada MultiCharts
Posts: 293
Joined: 22 Apr 2020
Has thanked: 8 times
Been thanked: 76 times

Re: (Multi-Timeframe) EMA @ Weekly Data on Daily Chart

Postby Vlada MultiCharts » 11 Jun 2021

Hello rc76,

You can use the code of a pre-built indicator Mov Avg 1 Line and add Data 2 in its calculation, like this:

Code: Select all

var0 = AverageFC( Price, Length ) data2 ;
Here is the example provided by our Engineering Team:

Code: Select all

inputs: Price( Close ), Length( 9 ), Displace( 0 ) ; variables: var0( 0 ) ; var0 = AverageFC( Price, Length ) data2 ; //<---- Data2 condition1 = Displace >= 0 or CurrentBar > AbsValue( Displace ) ; if condition1 then begin Plot1[Displace]( var0, "Avg" ) ; if Displace <= 0 then begin condition1 = Price crosses over var0 ; if condition1 then Alert( "Price crossing over average" ) else begin condition1 = Price crosses under var0 ; if condition1 then Alert( "Price crossing under average" ) ; end ; end; end ;
You can apply this indicator to Data 1.

rc76
Posts: 51
Joined: 14 Oct 2020
Has thanked: 17 times

Re: (Multi-Timeframe) EMA @ Weekly Data on Daily Chart

Postby rc76 » 11 Jun 2021

Thank you so much Vlada. Apology I didn't indicate it earlier, I am using MC.net. Any chance there is a MC.net sample code can be provided by engineering team? Thank you!

rc76
Posts: 51
Joined: 14 Oct 2020
Has thanked: 17 times

Re: MC.net: (Multi-Timeframe) EMA @ Weekly Data on Daily Chart

Postby rc76 » 16 Jun 2021

The code I used to create Thinkscript is as follow:

Code: Select all

def EMA9_d = ExpAverage(close(period = AggregationPeriod.DAY), 9); def EMA9_w = ExpAverage(close(period = AggregationPeriod.WEEK), 9); plot graph_EMA9_d = EMA9_d; graph_EMA9_d.SetDefaultColor(Color.CYAN); graph_EMA9_d.HideBubble(); plot graph_EMA9_w = EMA9_w; graph_EMA9_w.SetDefaultColor(Color.RED); graph_EMA9_w.HideBubble();

User avatar
Vlada MultiCharts
Posts: 293
Joined: 22 Apr 2020
Has thanked: 8 times
Been thanked: 76 times

Re: MC.net: (Multi-Timeframe) EMA @ Weekly Data on Daily Chart  [SOLVED]

Postby Vlada MultiCharts » 16 Jun 2021

Hello rc76,

You can check the basics in MultiCharts. NET FAQ.
Also I can recommend going through this thread.

Here is a modified Mov_Avg_Exponential code sample for data 2:

Code: Select all

using System; using System.Drawing; using PowerLanguage.Function; namespace PowerLanguage.Indicator { [SameAsSymbol(true)] public class Mov_Avg_Exponential_Data2 : IndicatorObject { private XAverage m_xaverage1; private VariableSeries<Double> m_avgexp; private IPlotObject Plot1; public Mov_Avg_Exponential_Data2(object ctx): base(ctx) { length = 9; } private ISeries<double> price { get; set; } [Input] public int length { get; set; } [Input] public int displace { get; set; } protected override void Create() { m_xaverage1 = new XAverage(this, 2); m_avgexp = new VariableSeries<Double>(this, 0, 2); Plot1 = AddPlot(new PlotAttributes("AvgExp", 0, Color.Blue, Color.Empty, 0, 0, true)); } protected override void StartCalc() { price = BarsOfData(2).Close;// Bars.Close; m_xaverage1.Price = price; m_xaverage1.Length = length; } protected override void CalcBar() { m_avgexp.Value = m_xaverage1[0]; if (((displace >= 0) || Bars.CurrentBar > Math.Abs(displace))) { Plot1.Set(displace, m_avgexp.Value); if ((displace <= 0)) { if (((PublicFunctions.DoubleGreater(price[0], m_avgexp.Value) && PublicFunctions.DoubleGreater(m_avgexp.Value, m_avgexp[1])) && PublicFunctions.DoubleLessEquals(m_avgexp[1], m_avgexp[2]))) { Alerts.Alert("Indicator turning up"); } else{if (((PublicFunctions.DoubleLess(price[0], m_avgexp.Value) && PublicFunctions.DoubleLess(m_avgexp.Value, m_avgexp[1])) && PublicFunctions.DoubleGreaterEquals(m_avgexp[1], m_avgexp[2]))) { Alerts.Alert("Indicator turning down"); } } } } } } }
EMA DATA2.pln
(1.4 KiB) Downloaded 155 times
Attachments
MultiCharts__Mov_Avg_Exponential Sample.png
(68.1 KiB) Not downloaded yet

rc76
Posts: 51
Joined: 14 Oct 2020
Has thanked: 17 times

Re: MC.net: (Multi-Timeframe) EMA @ Weekly Data on Daily Chart

Postby rc76 » 17 Jun 2021

Yes, thank you Vlada. It works now.


Return to “MultiCharts .NET”