Detecting if Bar Magnifier is Enabled

Questions about MultiCharts .NET and user contributed studies.
User avatar
orad
Posts: 119
Joined: 14 Nov 2012
Has thanked: 50 times
Been thanked: 18 times

Detecting if Bar Magnifier is Enabled

Postby orad » 06 Jun 2019

Hi, is there a property in the Study API that tells if Bar Magnifier is enabled?

Currently, I have to check how many times it hits inside bar status to know if Bar Magnifier is enabled (see the code below). I need this so I can alert myself if Bar Magnifier is disabled in Strategy Properties.

The following Study is also useful for understanding How Signals are Calculated based on Intra-Bar Order Generation (IOG) and Bar Magnifier settings.

Code: Select all

using System; namespace PowerLanguage.Strategy { [IOGMode(IOGMode.Enabled)] public class CheckBarMagnifier : SignalObject { public CheckBarMagnifier(object ctx) : base(ctx) { } private int _insideBarHitCount; protected override void StartCalc() { _insideBarHitCount = 0; Output.Clear(); } protected override void CalcBar() { CheckBarMagnifierIsEnabled(); } private void CheckBarMagnifierIsEnabled() { if (Bars.CurrentBar == 1) { Output.WriteLine("Bar: {0}\t Time: {1}\t\t Update Time: {2}\t\t Status: {3}\t Price: {4}", Bars.CurrentBar, Bars.TimeValue, Bars.BarUpdateTime, Bars.Status, Bars.CloseValue); if (Bars.Status == EBarState.Inside) { _insideBarHitCount++; } else if (Bars.Status == EBarState.Close) { Output.WriteLine("IOGMode is {0}", Environment.IOGEnabled ? "ENABLED" : "DISABLED"); if (_insideBarHitCount > 2) { Output.WriteLine("Bar Magnifier is ENABLED."); } else { Output.WriteLine("Bar Magnifier is DISABLED."); } } } } } }

User avatar
Svetlana MultiCharts
Posts: 220
Joined: 19 Oct 2017
Has thanked: 1 time
Been thanked: 55 times

Re: Detecting if Bar Magnifier is Enabled

Postby Svetlana MultiCharts » 07 Jun 2019

Hello, orad,

Currently there is no such pre-built keyword, unfortunately. We are planning to introduce it in one of the future MultiCharts versions.

User avatar
orad
Posts: 119
Joined: 14 Nov 2012
Has thanked: 50 times
Been thanked: 18 times

Re: Detecting if Bar Magnifier is Enabled

Postby orad » 07 Jun 2019

Here is a more complete code that detects and sets these properties:
  • IsBarMagnifierEnabled
  • IsBarMagnifierIntraBarTimeEnabled
Note that it uses bar 1 for detection, and the above properties are valid from bar 2.

Code: Select all

using System; namespace PowerLanguage.Strategy { [IOGMode(IOGMode.Enabled)] public class CheckBarMagnifier : SignalObject { public CheckBarMagnifier(object ctx) : base(ctx) { } private int _insideBarHitCount; /// <summary> /// Determines if Bar Magnifier in IOG Mode is enabled. /// Value will be valid after bar 1. /// </summary> protected bool IsBarMagnifierEnabled { get; private set; } /// <summary> /// Determines if Bar Magnifier access to Intra-Bar-Time in IOG Mode is enabled. /// Value will be valid after bar 1. /// </summary> protected bool IsBarMagnifierIntraBarTimeEnabled { get; private set; } protected override void StartCalc() { _insideBarHitCount = 0; Output.Clear(); } protected override void CalcBar() { CheckBarMagnifierIsEnabled(); } private void CheckBarMagnifierIsEnabled() { if (Bars.CurrentBar == 1) { Output.WriteLine("Bar: {0}\t Time: {1}\t\t Update Time: {2}\t\t Status: {3}\t Price: {4}", Bars.CurrentBar, Bars.TimeValue, Bars.BarUpdateTime, Bars.Status, Bars.CloseValue, Bars.TimeValue.Ticks - Bars.BarUpdateTime.Ticks); if (Bars.Status == EBarState.Open) { IsBarMagnifierIntraBarTimeEnabled = Bars.TimeValue.Ticks == Bars.BarUpdateTime.Ticks; } else if (Bars.Status == EBarState.Inside) { _insideBarHitCount++; } else if (Bars.Status == EBarState.Close) { Output.WriteLine("IOGMode is {0}", Environment.IOGEnabled ? "ENABLED" : "DISABLED"); IsBarMagnifierEnabled = _insideBarHitCount > 2; IsBarMagnifierIntraBarTimeEnabled &= IsBarMagnifierEnabled; Output.WriteLine("Bar Magnifier is {0}", IsBarMagnifierEnabled ? "ENABLED" : "DISABLED"); Output.WriteLine("Bar Magnifier access to intra-bar-time is {0}", IsBarMagnifierIntraBarTimeEnabled ? "ENABLED" : "DISABLED"); } } } } }
It would be great to have these settings exposed through the API.

Also when you do that please also add a parameter in [IOGMode] attribute so we can enable access to intra-bar-time in the code.


Return to “MultiCharts .NET”