MC.NET previous day close

Questions about MultiCharts .NET and user contributed studies.
mirek
Posts: 24
Joined: 08 Jan 2013
Has thanked: 3 times
Been thanked: 3 times

MC.NET previous day close

Postby mirek » 08 Jan 2013

Hi all,

I apologies for newbie question. I would like to get "Close of the previous day" (EL CloseD()) in MC.NET. Can you direct me to the correct code sample?

thank you
mirek

PS: Is this a proper way?

Code: Select all

double CloseD=0;

if (Bars.Time[0].Date != Bars.Time[1].Date) CloseD = Bars.Close[1];

User avatar
Henry MultiСharts
Posts: 9121
Joined: 25 Aug 2011
Has thanked: 1258 times
Been thanked: 2927 times

Re: MC.NET previous day close

Postby Henry MultiСharts » 09 Jan 2013

Hello mirek,

The code you have provided will not do the same thing as EL CloseD function.
OpenD, HighD, LowD and CloseD functions would be added in one of the next versions of MultiCharts .Net.

mirek
Posts: 24
Joined: 08 Jan 2013
Has thanked: 3 times
Been thanked: 3 times

Re: MC.NET previous day close

Postby mirek » 09 Jan 2013

Hi Henry,

thank you for the comment. I am using it only for CloseD of previous day and it seems the output is fine. I am aware that it does not fully replace the function CloseD with all possible history.

It would be nice to have full function in MC.NET.

mirek

DPTrade
Posts: 3
Joined: 12 Feb 2014
Been thanked: 1 time

Re: MC.NET previous day close

Postby DPTrade » 12 Feb 2014

So HighD and LowD do not reset at midnight in MultiCharts? If so, is there a way to track the high and low of the current session on 1 min charts since the start of the session, even if the session crosses over into a different calendar day?

User avatar
Henry MultiСharts
Posts: 9121
Joined: 25 Aug 2011
Has thanked: 1258 times
Been thanked: 2927 times

Re: MC.NET previous day close

Postby Henry MultiСharts » 13 Feb 2014

So HighD and LowD do not reset at midnight in MultiCharts? If so, is there a way to track the high and low of the current session on 1 min charts since the start of the session, even if the session crosses over into a different calendar day?
Hello DPTrade,

HighD and LowD reset at midnight in MultiCharts. That is possible to create your own function that will do the calculations you need.

User avatar
JoshM
Posts: 2099
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1526 times
Been thanked: 1502 times
Contact:

Re: MC.NET previous day close

Postby JoshM » 14 Feb 2014

(...) is there a way to track the high and low of the current session on 1 min charts since the start of the session, even if the session crosses over into a different calendar day?
See attached example/indicator:

Code: Select all

using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;

namespace PowerLanguage.Indicator
{
[SameAsSymbol(true)]
public class Example_HighLowCurrentDay : IndicatorObject
{
private IPlotObject dailyHigh, dailyLow;
private double highOfDay = 0, lowOfDay = 99999;

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

protected override void Create()
{
dailyHigh = AddPlot(new PlotAttributes("Daily High", EPlotShapes.Line, Color.ForestGreen));
dailyLow = AddPlot(new PlotAttributes("Daily Low", EPlotShapes.Line, Color.Firebrick));
}

protected override void CalcBar()
{
// At the start of a new session, reset variables
if (Bars.Status == EBarState.Close)
{
// To calculate the open time, subtract the bar resolution from the current
// bar closing time ** NOTE: only works on minute based charts **
TimeSpan openTime = Bars.TimeValue.TimeOfDay - TimeSpan.FromMinutes(Bars.Info.Resolution.Size);


if (openTime == Bars.Sessions[0].StartTime)
{
highOfDay = 0;
lowOfDay = 99999;
}
}

// Keep track of high/low of day
highOfDay = Math.Max(Bars.HighValue, highOfDay);
lowOfDay = Math.Min(Bars.LowValue, lowOfDay);

// Plot
dailyHigh.Set(highOfDay);
dailyLow.Set(lowOfDay);
}
}
}
Image
Attachments
exampleHighLowCurrentDay.pln
(1.41 KiB) Downloaded 421 times
scr.14-02-2014 18.06.06.png
scr.14-02-2014 18.06.06.png (9.89 KiB) Viewed 1217 times

DPTrade
Posts: 3
Joined: 12 Feb 2014
Been thanked: 1 time

Re: MC.NET previous day close

Postby DPTrade » 14 Feb 2014

Thank you for posting this - this works really well.

Abhi
Posts: 28
Joined: 28 Nov 2015
Has thanked: 5 times
Been thanked: 2 times

Re: MC.NET previous day close

Postby Abhi » 20 Jan 2019

(...) is there a way to track the high and low of the current session on 1 min charts since the start of the session, even if the session crosses over into a different calendar day?
See attached example/indicator:

Code: Select all

using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;

namespace PowerLanguage.Indicator
{
[SameAsSymbol(true)]
public class Example_HighLowCurrentDay : IndicatorObject
{
private IPlotObject dailyHigh, dailyLow;
private double highOfDay = 0, lowOfDay = 99999;

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

protected override void Create()
{
dailyHigh = AddPlot(new PlotAttributes("Daily High", EPlotShapes.Line, Color.ForestGreen));
dailyLow = AddPlot(new PlotAttributes("Daily Low", EPlotShapes.Line, Color.Firebrick));
}

protected override void CalcBar()
{
// At the start of a new session, reset variables
if (Bars.Status == EBarState.Close)
{
// To calculate the open time, subtract the bar resolution from the current
// bar closing time ** NOTE: only works on minute based charts **
TimeSpan openTime = Bars.TimeValue.TimeOfDay - TimeSpan.FromMinutes(Bars.Info.Resolution.Size);


if (openTime == Bars.Sessions[0].StartTime)
{
highOfDay = 0;
lowOfDay = 99999;
}
}

// Keep track of high/low of day
highOfDay = Math.Max(Bars.HighValue, highOfDay);
lowOfDay = Math.Min(Bars.LowValue, lowOfDay);

// Plot
dailyHigh.Set(highOfDay);
dailyLow.Set(lowOfDay);
}
}
}
Image
Thank you Josh, I am a big fan your website and looking at your examples to build my indicators. Would you be able to suggest if I want to show the previous day high/Low close on scanner irrespective of the resolution whether it is a day or a minute chart. Easylanguage functions HighD and LowD does the same thing on any scanner or chart resolution.

Abhi
Posts: 28
Joined: 28 Nov 2015
Has thanked: 5 times
Been thanked: 2 times

Re: MC.NET previous day close

Postby Abhi » 22 Jan 2019

(...) is there a way to track the high and low of the current session on 1 min charts since the start of the session, even if the session crosses over into a different calendar day?
See attached example/indicator:

Code: Select all

using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;

namespace PowerLanguage.Indicator
{
[SameAsSymbol(true)]
public class Example_HighLowCurrentDay : IndicatorObject
{
private IPlotObject dailyHigh, dailyLow;
private double highOfDay = 0, lowOfDay = 99999;

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

protected override void Create()
{
dailyHigh = AddPlot(new PlotAttributes("Daily High", EPlotShapes.Line, Color.ForestGreen));
dailyLow = AddPlot(new PlotAttributes("Daily Low", EPlotShapes.Line, Color.Firebrick));
}

protected override void CalcBar()
{
// At the start of a new session, reset variables
if (Bars.Status == EBarState.Close)
{
// To calculate the open time, subtract the bar resolution from the current
// bar closing time ** NOTE: only works on minute based charts **
TimeSpan openTime = Bars.TimeValue.TimeOfDay - TimeSpan.FromMinutes(Bars.Info.Resolution.Size);


if (openTime == Bars.Sessions[0].StartTime)
{
highOfDay = 0;
lowOfDay = 99999;
}
}

// Keep track of high/low of day
highOfDay = Math.Max(Bars.HighValue, highOfDay);
lowOfDay = Math.Min(Bars.LowValue, lowOfDay);

// Plot
dailyHigh.Set(highOfDay);
dailyLow.Set(lowOfDay);
}
}
}
Image
Thank you Josh, I am a big fan your website and looking at your examples to build my indicators. Would you be able to suggest if I want to show the previous day high/Low close on scanner irrespective of the resolution whether it is a day or a minute chart. Easylanguage functions HighD and LowD does the same thing on any scanner or chart resolution.
sorted thanks :)

Abhi
Posts: 28
Joined: 28 Nov 2015
Has thanked: 5 times
Been thanked: 2 times

Re: MC.NET previous day close

Postby Abhi » 22 Jan 2019

If anybody wondering how to get range for previous day on a scanner.

using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;

namespace PowerLanguage.Indicator
{
[SameAsSymbol(true)]
[UpdateOnEveryTick(true)]
[SkipIdenticalTicks(false)]
public class AG_Volume_Profile : IndicatorObject
{
public AG_Volume_Profile(object _ctx):base(_ctx)
{
}
private IPlotObject PreviousRange;

protected override void Create()
{
PreviousRange = AddPlot(new PlotAttributes("PrevRange", EPlotShapes.Point,Color.Yellow, Color.Empty, 4,0,true));

}
protected override void StartCalc()
{
ExecInfo.MaxBarsBack = 3;
}
protected override void CalcBar()
{
PreviousRange.Set(Bars.High[1] - Bars.Low[1]);

}

}
}


Return to “MultiCharts .NET”