Indicators - reset on every session - how to?  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
User avatar
Al3cs
Posts: 34
Joined: 22 Jun 2017
Location: Italy
Has thanked: 31 times
Been thanked: 1 time

Indicators - reset on every session - how to?

Postby Al3cs » 12 May 2020

Hi all,
when I use custom session template with ETH and RTH sessions I have Floor Trade Pivots which ignores session start/end and reset on new day only.
How can I fix it?
Thanks
2020-05-12 17_30_54-Window.png
(48.95 KiB) Not downloaded yet

User avatar
Al3cs
Posts: 34
Joined: 22 Jun 2017
Location: Italy
Has thanked: 31 times
Been thanked: 1 time

Re: Indicators - reset on every session - how to?

Postby Al3cs » 14 May 2020

Well, still struggling with this problem.
I found two threads all about this problem:
viewtopic.php?f=19&t=10767&hilit=sessionobject#p52928
viewtopic.php?f=19&t=46121&p=102389&hil ... ct#p102231

So what I understood is I have to change the piece of code "Bars.Time[0].Date != Bars.Time[1].Date"

Code: Select all

protected override void CalcBar() { EResolution resolution = Bars.Info.Resolution.Type; if (resolution == EResolution.Quarter || EResolution.Week <= resolution && resolution <= EResolution.Year) return; if (Bars.Time[0].Date != Bars.Time[1].Date) { m_counter.Value = (m_counter.Value + 1); --------- --------- -----
and I have to set condition similar to (pseudocode): "Bars.Session[1] != Bars.Session[0]" but I still can'f figure out how.
This problem is 7 years old and still every indicator (ie high/low of day) doesn't have twin indicator for sessions (i.e. high/low of session)
Is this really so rare for traders to trade OverNight sessions too?

Do I have to edit one by one every single indicator to let it work for session breaks too?

Another example for VWAP (still an old problem):
- if I set vwap_reset I can manually set session's start/end time but it reset on midnight....WHY break in two the overnight session??
Really really annoying

User avatar
Al3cs
Posts: 34
Joined: 22 Jun 2017
Location: Italy
Has thanked: 31 times
Been thanked: 1 time

Re: Indicators - reset on every session - how to?  [SOLVED]

Postby Al3cs » 14 May 2020

Well, I think I found the solution in this post from AMP Futures forum:
https://forum.ampfutures.com/forum/futu ... 2#post4352

using same way used in OHLCPeriodsAgo function (even if I fully don't understand what I did and why this is the correct way to do it...)

I still have to verify if it gives back correct values. After this check I will upload the new indicator in "User Contributed Studies" thread

Code: Select all

using System; using System.Drawing; using PowerLanguage.Function; namespace PowerLanguage.Indicator { [SameAsSymbol(true)] public class Session_F_T_Pivots : IndicatorObject { private VariableObject<Double> m_s1; private VariableObject<Double> m_s2; private VariableObject<Double> m_s3; private VariableObject<Double> m_r1; private VariableObject<Double> m_r2; private VariableObject<Double> m_r3; private VariableObject<Double> m_pp; private VariableObject<Double> m_todayshigh; private VariableObject<Double> m_todayslow; private VariableObject<Int32> m_counter; private IPlotObject Plot1; private IPlotObject Plot2; private IPlotObject Plot3; private IPlotObject Plot4; private IPlotObject Plot5; private IPlotObject Plot6; private IPlotObject Plot7; // private VariableSeries<bool> m_lastBarInSession; // public Session_F_T_Pivots(object ctx) : base(ctx){ plot_5or7 = 5; } [Input] public int plot_5or7 { get; set; } protected override void Create(){ m_s1 = new VariableObject<Double>(this); m_s2 = new VariableObject<Double>(this); m_s3 = new VariableObject<Double>(this); m_r1 = new VariableObject<Double>(this); m_r2 = new VariableObject<Double>(this); m_r3 = new VariableObject<Double>(this); m_pp = new VariableObject<Double>(this); m_todayshigh = new VariableObject<Double>(this); m_todayslow = new VariableObject<Double>(this); m_counter = new VariableObject<Int32>(this); Plot1 = AddPlot(new PlotAttributes("R3", EPlotShapes.LeftTick, Color.Magenta, Color.Empty, 2, 0, true)); Plot2 = AddPlot(new PlotAttributes("R2", EPlotShapes.LeftTick, Color.Blue, Color.Empty, 2, 0, true)); Plot3 = AddPlot(new PlotAttributes("R1", EPlotShapes.LeftTick, Color.Yellow, Color.Empty, 2, 0, true)); Plot4 = AddPlot(new PlotAttributes("PP", EPlotShapes.LeftTick, Color.Cyan, Color.Empty, 2, 0, true)); Plot5 = AddPlot(new PlotAttributes("S1", EPlotShapes.LeftTick, Color.Yellow, Color.Empty, 2, 0, true)); Plot6 = AddPlot(new PlotAttributes("S2", EPlotShapes.LeftTick, Color.Blue, Color.Empty, 2, 0, true)); Plot7 = AddPlot(new PlotAttributes("S3", EPlotShapes.LeftTick, Color.Magenta, Color.Empty, 2, 0, true)); // m_lastBarInSession = new VariableSeries<bool>(this); // } protected override void CalcBar() { m_lastBarInSession.Value = Bars.LastBarInSession; EResolution resolution = Bars.Info.Resolution.Type; if (resolution == EResolution.Quarter || EResolution.Week <= resolution && resolution <= EResolution.Year) return; if (m_lastBarInSession[1]) { m_counter.Value = (m_counter.Value + 1); var m_yesthigh = m_todayshigh.Value; var m_yestlow = m_todayslow.Value; var m_yestclose = Bars.Close[1]; m_todayshigh.Value = Bars.High[0]; m_todayslow.Value = Bars.Low[0]; m_pp.Value = (((m_yesthigh + m_yestlow) + m_yestclose) /((3))); m_r1.Value = ((m_pp.Value*2) - m_yestlow); m_r2.Value = ((m_pp.Value + m_yesthigh) - m_yestlow); m_r3.Value = ((m_r2.Value + m_yesthigh) - m_yestlow); m_s1.Value = ((m_pp.Value*2) - m_yesthigh); m_s2.Value = ((m_pp.Value - m_yesthigh) + m_yestlow); m_s3.Value = ((m_s2.Value - m_yesthigh) + m_yestlow); } else{ if (PublicFunctions.DoubleGreater(Bars.High[0], m_todayshigh.Value)){ m_todayshigh.Value = Bars.High[0]; } if (PublicFunctions.DoubleLess(Bars.Low[0], m_todayslow.Value)){ m_todayslow.Value = Bars.Low[0]; } } if (m_counter.Value >= 2) { if ((plot_5or7 == 7)) { Plot1.Set(0, m_r3.Value); } Plot2.Set(0, m_r2.Value); Plot3.Set(0, m_r1.Value); Plot4.Set(0, m_pp.Value); Plot5.Set(0, m_s1.Value); Plot6.Set(0, m_s2.Value); if ((plot_5or7 == 7)) { Plot7.Set(0, m_s3.Value); } } } } }


Return to “MultiCharts .NET”