This article summarises the most important points of the previous MultiCharts .NET class attributes articles. Follow the article links for examples and more information.

Class attributes in MultiCharts .NET

C# attributes add metadata to code elements like classes (Dorman, 2010) and, by doing so, influence the way these operate (see Stephens, 2014). MultiCharts .NET attributes are used to set certain script options programmatically.

Attributes are added immediately above the class to which they apply (Dorman, 2010), like this:

MultiCharts .NET - placement of class attributes

MultiCharts .NET attributes can be divided into three groups:

  • Indicator attributes: SameAsSymbol, SkipIdenticalTicks, and UpdateOnEveryTick.
  • Attributes for both indicators and strategies: MouseEvents and RecoverDrawings.
  • Trading strategy attributes: CalcAtOpenNextBar, IOGMode, ExitFromOneEntryOnce, and AllowSendOrdersAlways.

SameAsSymbol: plotting an indicator on a data series

The SameAsSymbol attribute set to true plots an indicator on a data series (MultiCharts, 2014).

[SameAsSymbol(true)]
public class Example_SameAsSymbol : IndicatorObject
{
    // Indicator code
}

And when set to false, an indicator is displayed in its own separate subchart:

[SameAsSymbol(false)]
public class Example_SameAsSymbol : IndicatorObject
{
    // Indicator code
}

The default behaviour without SameAsSymbol is to plot an indicator in an individual subchart.

SkipIdenticalTicks: only process ticks that differ from the previous

When SkipIdenticalTicks is set to true, intra-bar real-time identical ticks are skipped (see MultiCharts Wiki, 2015):

[SkipIdenticalTicks(true)]
public class Example_SkipIdenticalTicks : IndicatorObject
{
    // Indicator code
}

When this attribute is set to false, ticks with the same price as the previous are not skipped:

[SkipIdenticalTicks(false)]
public class Example_SkipIdenticalTicks : IndicatorObject
{
    // Indicator code
}

If the attribute isn’t defined, identical ticks are skipped by default. Indicators that rely on volume or tick count might better not skip identical ticks (MultiCharts Wiki, 2015).

UpdateOnEveryTick: only calculating an indicator on bar close

The UpdateOnEveryTick attribute set to true calculates an indicator on each incoming tick.

[UpdateOnEveryTick(true)]
public class Example_UpdateOnEveryTick : IndicatorObject
{
    // Indicator code
}

When set to false, an indicator is only calculated on bar close:

[UpdateOnEveryTick(false)]
public class Example_UpdateOnEveryTick : IndicatorObject
{
    // Indicator code
}

The default behaviour is to update on each real-time tick (MultiCharts Wiki, 2012), which also applies when UpdateOnEveryTick is omitted from the code.

MouseEvents: enable a script’s processing of mouse clicks

The MouseEvents attribute set to true enables mouse clicks processing in an indicator or trading strategy.

[MouseEvents(true)]
public class Example_MouseEvents : IndicatorObject
{
    // Script code
}

Note that MouseEvents only enables the mouse click processing; dealing with the actual mouse clicks needs to be done in the OnMouseEvent() method. For example:

protected override void OnMouseEvent(MouseClickArgs arg)
{
    Output.WriteLine("A {0} click with the {1} key",
        arg.buttons,
        arg.keys);

    Output.WriteLine("  Bar #{0}, price: {1}, time: {2}",
        arg.bar_number,
        arg.point.Price,
        arg.point.Time);
}

When MouseEvents is set to false, mouse clicks on a chart’s data series aren’t processed.

[MouseEvents(false)]
public class Example_MouseEvents : IndicatorObject
{
    // Script code
}

Without the MouseEvents attribute the default behaviour of no mouse click processing applies.

RecoverDrawings: don’t remove intra-bar generated drawings

The RecoverDrawings attribute set to false preserves all intra-bar generated drawings after the next script calculation (MultiCharts, 2014; MultiCharts Wiki, 2014a).

[RecoverDrawings(false)]
public class Example_RecoverDrawings : IndicatorObject
{
    // Script code
}

To only keep drawings (arrows, trend lines, or text boxes) that were made on bar close, and throw away the intra-bar generated ones, set the attribute to true.

[RecoverDrawings(true)]
public class Example_RecoverDrawings : IndicatorObject
{
    // Script code
}

When the attribute isn’t added to the code, it defaults to true (MultiCharts Wiki, 2014a), meaning that intra-bar generated drawings are removed by default.

CalcAtOpenNextBar: generating orders on the bar open

The CalcAtOpenNextBar attribute set to true enables a strategy to generate orders on bar open which are then submitted for the current bar (MultiCharts, 2014).

[CalcAtOpenNextBar(true)]
public class Example_CalcAtOpenNextBar : SignalObject
{
    // Strategy code
}

With the attribute enabled, the next bar’s open can be accessed with Bars.Open[-1] or the equivalent Bars.OpenNextBar() while the next bar’s time is retrievable with Bars.Time[-1] or Bars.TimeNextBar() (MultiCharts, 2014).

When this attribute is set to false or not added to the script, the default behaviour of generating orders on bar close and submitting them for the next bar applies.

[CalcAtOpenNextBar(false)]
public class Example_CalcAtOpenNextBar : SignalObject
{
    // Strategy code
}

IOGMode: generating orders intra-bar by calculating on every tick

The IOGMode attribute set to enabled turns on intra-bar order generation (IOG) so that a strategy can react to price changes within a bar (MultiCharts, 2014).

[IOGMode(IOGMode.Enabled)]
public class Example_IOGMode : SignalObject
{
    // Strategy code
}

Note that, when IOG is active, orders need to be resubmitted on every tick in order to keep them active (see MultiCharts, 2014).

When the attribute isn’t added to the code or when set to disabled, the default behaviour of generating orders on bar close applies (MultiCharts, 2014).

[IOGMode(IOGMode.Disabled)]
public class Example_IOGMode : SignalObject
{
    // Strategy code
}

ExitFromOneEntryOnce: scaling out with a reusable order

With ExitFromOneEntryOnce we can repeatedly use the same exit order to exit from the same entry (MultiCharts, 2014). When this attribute is set to FillAndKillExitOrder a filled exit order can be generated again by the script to be executed against the same entry order (Henry MultiCharts, 2014).

[ExitFromOneEntryOnce(ExitFromOneEntryOnce.FillAndKillExitOrder)]
public class Example_ExitFromOneEntryOnce : SignalObject
{
    // Strategy code
}

When set to StandardCalculation a filled exit order cannot be applied again to the same entry (Henry MultiCharts, 2014). That means we need an exit order for each exit, and so scaling out in three steps requires three individual exit orders.

[ExitFromOneEntryOnce(ExitFromOneEntryOnce.StandardCalculation)]
public class Example_ExitFromOneEntryOnce : SignalObject
{
    // Strategy code
}

When the attribute isn’t defined the StandardCalculation behaviour applies.

AllowSendOrdersAlways: send a trading strategy’s orders at any time

The AllowSendOrdersAlways attribute, when set to true, allows orders to be generated always regardless of the calculation’s bar status (MultiCharts Wiki, 2014b). This allows for sending orders on periodic script recalculations or when bars from multiple data series don’t align.

[AllowSendOrdersAlways(true)]
public class Example_AllowSendOrdersAlways : SignalObject
{
    // Strategy code
}

Set the attribute to false to only send orders when the script is calculated with a bar status that indicates an opening, inside, or closing tick.

[AllowSendOrdersAlways(false)]
public class Example_AllowSendOrdersAlways : SignalObject
{
    // Strategy code
}

With the attribute missing from the code, the default behaviour of no order generation when the bar’s status is EBarState.None applies (see MultiCharts Wiki, 2014b).

Summary

This concludes the ‘chapter’ on the MultiCharts .NET class attributes. See all MultiCharts .NET programming articles to explore other topics.


References

Dorman, S. (2010). Sams Teach Yourself Visual C# 2010 in 24 Hours. Indianapolis, IN: Sams/Pearson Education.

Henry MultiCharts (2014, December 24). Close partial postions – forum discussion. Retrieved on February 3, 2015, from http://www.multicharts.com/discussion/viewtopic.php?f=19&t=47785&view=unread#p111812

MultiCharts (2014). MultiCharts .NET Programming Guide (version 1.1). Retrieved from http://www.multicharts.com/downloads/MultiCharts.NET-ProgrammingGuide-v1.1.pdf

MultiCharts Wiki (2012, February 23). How Scripts Work. Retrieved on January 26, 2015, from http://www.multicharts.com/trading-software/index.php/How_Scripts_Work

MultiCharts Wiki (2014a, January 23). RecoverDrawings. Retrieved on January 27, 2015, from http://www.multicharts.com/trading-software/index.php/RecoverDrawings

MultiCharts Wiki (2014b, December 26). AllowSendOrdersAlways. Retrieved on February 5, 2015, from http://www.multicharts.com/trading-software/index.php/AllowSendOrdersAlways

MultiCharts Wiki (2015, January 29). Skip Identical Ticks. Retrieved on January 30, 2015, from http://www.multicharts.com/trading-software/index.php/Skip_Identical_Ticks

Stephens, R. (2014). C# 5.0 Programmer Reference. Indianapolis, IN: John Wiley & Sons.