With the CalcAtOpenNextBar attribute a strategy can be set to submit its orders on bar close or the open of the bar. But what if we want to generate and fill orders at any price within a bar?

IOGMode attribute: disable or enable a strategy’s intra-bar order generation

Attributes in C# are, in a nutshell, code annotations that can be applied to certain types (Troelsen, 2012). In MultiCharts .NET attributes can be added to classes to change certain settings.

One attribute is IOGMode, which enables intra-bar order generation (abbreviated to IOG) so that a strategy can react to price changes within a bar (MultiCharts, 2014). This means the following when IOG is enabled (MultiCharts, 2014; MultiCharts Wiki, 2015):

  • On real-time data the strategy’s CalcBar() method is executed on every tick, allowing the programming code in this method to react to each tick.
  • With historical data the CalcBar() method is executed at the open, high, low, and close of each bar. With the Bar Magnifier (discussed below) a more precise historical calculation is possible.

When the IOGMode attribute isn’t added to a strategy, the default behaviour of executing CalcBar() only on bar close and submitting orders for the next bar applies (MultiCharts, 2014).

Tip: Existing, pending orders that aren’t resubmitted when the strategy calculates again are cancelled (see MultiCharts, 2014). So with IOG, active orders need to be resubmitted on every tick as long as you want to keep them active. And with IOG disabled, they need to be resubmitted on every bar.

Intra-bar order generation and the Bar Magnifier: more precise backtesting

The Bar Magnifier is an option for emulating the price movement within a bar more precisely, which helps to backtest IOG-strategies more accurately (MultiCharts, 2014).

To enable the Bar Magnifier, right-click on the chart, select ‘Format Signals’ and click on ‘Properties’. In the ‘Strategy Properties’ window go to the ‘Backtesting’ tab to enable the Bar Magnifier with your preferred precision. The Bar Magnifier’s precision is a trade-off: the lower, the more accurate the results, but also the more data needs to be (down)loaded and processed (MultiCharts Wiki, 2013).

MultiCharts .NET IOGMode - enable Bar Magnifier

Setting the IOGMode attribute in MultiCharts .NET

The IOGMode attribute needs to be set to IOGMode.Enabled to enable intra-bar order generation (MultiCharts, 2014), like this:

public class Example_IOGMode : SignalObject
    // Strategy code

And set the attribute to IOGMode.Disabled to disable intra-bar order generation:

public class Example_IOGMode : SignalObject
    // Strategy code

Example: IOGMode’s effect on the orders of a trading strategy

To examine intra-bar orders more closely, let’s consider the following example:

public class Example_IOGMode : SignalObject
    public Example_IOGMode(object _ctx) : base(_ctx) { }

    private IOrderMarket shortOrder, coverOrder;

    protected override void Create()
        shortOrder = OrderCreator.MarketNextBar(new 
            SOrderParameters(Contracts.UserSpecified, EOrderAction.SellShort));
        coverOrder = OrderCreator.MarketNextBar(new 
            SOrderParameters(Contracts.UserSpecified, EOrderAction.BuyToCover));

    int counter = 0;

    protected override void CalcBar()
        if (counter < 3)

        else if (StrategyInfo.MarketPosition < 0 &&
            Bars.Status == EBarState.Close)

            counter = 0;

We start with setting IOGMode to enabled. Then two IOrderMarket orders are created (shortOrder and coverOrder), which are subsequently created in the Create() method with OrderCreator.MarketNextBar().

Note that when IOG is enabled, MarketNextBar orders are actually send on the next tick, not next bar (see Henry MultiCharts, 2013). The orders are set here as a SellShort and BuyToCover order, and both have their order size set to UserSpecified. This latter means we can programmatically set the order size for these orders.

Submitting intra-bar orders in MultiCharts .NET

The next part declares the counter integer variable and assigns it a value of 0. Then in the CalcBar() method an if/else statement begins with evaluating whether this variable is less than 3. When it is, the short order’s Send() method is called with an argument of 1 so that one contract (or share) is sold short. The postfix increment operator (++) then increases this variable with one so that eventually the short order isn’t send more than three times.

The if/else statement’s else portion require two conditions to be true. First, the current position needs to be short. This is tested with the StrategyInfo.MarketPosition property which returns the current position size as a positive number (when long) or a negative one (when short) (MultiCharts, 2014). The other condition is whether the bar’s current script calculation (Bars.Status) happens on the bar’s closing tick (EBarState.Close). This way we submit the exit order (coverOrder) on bar close, ready to be executed at the next bar’s open.

These exit orders are submitted with it’s Send() method. In it, we pass CurrentPosition.OpenLots, a property that returns the amount of open contracts in the current position (MultiCharts, 2014). This way the exit order has its size set so that it closes all open positions. Finally, counter is reset back to zero so that on the next bar the strategy starts with opening a short position anew.

A MultiCharts .NET trading strategy with IOGMode on or off

When IOGMode is enabled, the above strategy generates three intra-bar short orders and one exit order that’s executed at the bar’s open:

MultiCharts .NET IOGMode - enabled

With IOGMode is disabled orders are generated on bar close and submitted for the next. So the above example then only generates a trade per bar:

MultiCharts .NET IOGMode - disabled

When you change an attribute with the strategy already added to the chart, the script needs to be removed and re-added to see the adjusted code’s effect (see Henry MultiCharts, 2014).

Setting a strategy’s intra-bar order generation manually in MultiCharts .NET

Intra-bar order generation can also be set manually for a specific instance of a strategy as long as the IOGMode attribute hasn’t been added to the code (see MultiCharts Wiki, 2012).

To set IOG manually, right-click on the chart and select ‘Format Signals’. Then select the strategy and click ‘Format’ and move to the strategy’s ‘Properties’ tab to enable IOG (see yellow arrow):

MultiCharts .NET IOGMode - enable manually

If you want the strategy to have potentially multiple entries and exits per bar, select the two options highlighted with a green arrow in the image above. These entries and exits options cannot be set programmatically (Alex MultiCharts, 2014), and so the exact IOG settings need to be manually specified.

When the strategy should be able to enter multiple times per bar, another option also need to be manually changed. To do that, right-click on the chart, select ‘Format Signals’, and click on ‘Properties’. Then in the ‘Strategy Properties’ screen change the setting ‘Allow up to x entry orders in the same direction as the currently held position’. And, when desired, select ‘regardless of the entry that generated the order’:

MultiCharts .NET IOGMode - multiple entries

Besides IOGMode, other attributes that change a trading strategy’s behaviour are ExitFromOneEntryOnce and AllowSendOrdersAlways.


With intra-bar order generation (IOG) a strategy’s orders can be generated and filled inside a bar. This setting can be enabled or disabled programmatically with IOGMode. When entries and exits need to be able to execute multiple times, some settings needs to be changed manually.

For more information about coding and the C# programming language, see Kodify.net.


Alex MultiCharts (2014, May 8). IOGMode option from code – forum discussion. Retrieved on January 31, 2015, from http://www.multicharts.com/discussion/viewtopic.php?f=19&t=46544#p104638

Henry MultiCharts (2013, November 20). Logic of MarketNextBar with IOGMode.Enabled – forum discussion. Retrieved on January 30, 2015, from http://www.multicharts.com/discussion/viewtopic.php?f=19&t=45699#p100008

Henry MultiCharts (2014, December 11). MultiCharts .NET FAQ – forum discussion. Retrieved on January 25, 2015, from http://www.multicharts.com/discussion/viewtopic.php?f=19&t=45848#p111375

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, August 31). IntraBarOrderGeneration. Retrieved on January 31, 2015, from http://www.multicharts.com/trading-software/index.php/IntraBarOrderGeneration

MultiCharts Wiki (2013, May 21). Bar Magnifier. Retrieved on January 31, 2015, from http://www.multicharts.com/trading-software/index.php/Bar_Magnifier

MultiCharts Wiki (2015, January 8). How Signals are Calculated. Retrieved on February 1, 2015, from http://www.multicharts.com/trading-software/index.php/How_Signals_are_Calculated

Troelsen, A. (2012). Pro C# 5.0 and the .NET 4.5 Framework (6th edition). Apress.

Visit Kodify.net for more helpful coding articles.