Situation
You only want to trade on certain days, for example by opening a long position on Friday and closing it on Monday.

Programming example

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

namespace PowerLanguage.Strategy
{
    [IOGMode(IOGMode.Enabled)]
    public class Example_TradeCertainDays : SignalObject
    {
        private IOrderMarket buyOrder, sellOrder;

        [Input]
        public DayOfWeek EnterDay { get; set; }

        [Input]
        public DayOfWeek ExitDay { get; set; }

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

        protected override void Create()
        {
            buyOrder  = OrderCreator.MarketNextBar(new SOrderParameters(Contracts.Default, EOrderAction.Buy));
            sellOrder = OrderCreator.MarketNextBar(new SOrderParameters(Contracts.Default, EOrderAction.Sell));

            // Assign default values
            EnterDay = DayOfWeek.Friday;
            ExitDay  = DayOfWeek.Monday;
        }

        protected override void CalcBar()
        {
            // When flat, enter long on the 'EnterDay'
            if ((StrategyInfo.MarketPosition == 0) && (Bars.Time[0].DayOfWeek == EnterDay))
            {
                buyOrder.Send();
            }

            // When long, exit position on the 'ExitDay'
            if ((StrategyInfo.MarketPosition > 0) && (Bars.Time[0].DayOfWeek == ExitDay))
            {
                sellOrder.Send();
            }
        }
    }
}

MultiCharts .NET programming example

To generate orders during a bar, instead of on bar close, we set the Intra-Bar Order Generation to enabled in line 9. Note that this also requires that the Bar Magnifier in the Strategy Properties is enabled.

To easily enter the days into the strategy, two inputs are added:

[Input]
public DayOfWeek EnterDay { get; set; }

[Input]
public DayOfWeek ExitDay { get; set; }

Creating orders in MultiCharts .NET’s Create() method

Then in the Create() override method the orders are created and the default values assigned to the inputs:

protected override void Create() 
{
    buyOrder  = OrderCreator.MarketNextBar(new SOrderParameters(Contracts.Default, EOrderAction.Buy));
    sellOrder = OrderCreator.MarketNextBar(new SOrderParameters(Contracts.Default, EOrderAction.Sell));

    // Assign default values
    EnterDay = DayOfWeek.Friday;
    ExitDay  = DayOfWeek.Monday;
}

Generate day-specific trading orders in MultiCharts .NET

In the CalcBar() method, we generate the orders based on the comparisons between Bars.Time[0].DayOfWeek (which returns the day of the week for the current bar) with the two inputted values:

protected override void CalcBar()
{
    // When flat, enter long on the 'EnterDay'
    if ((StrategyInfo.MarketPosition == 0) && (Bars.Time[0].DayOfWeek == EnterDay))
    {
        buyOrder.Send();
    }

    // When long, exit position on the 'ExitDay'
    if ((StrategyInfo.MarketPosition > 0) && (Bars.Time[0].DayOfWeek == ExitDay))
    {
        sellOrder.Send();
    }
}

Before entering a long position we check if there is no open position (in which case the StrategyInfo.MarketPosition property returns 0), and whether the day of the current bar is equal to the EnterDay input. When both conditions are true, a long order is submitted.

For closing the position there needs to be a long position (meaning, StrategyInfo.MarketPosition returns a value greater than zero) and the bar’s current day needs to be equal to the ExitDay input. With both conditions satisfied, the exit long order is submitted and the position closed.

Each constant in an enumeration corresponds to a numerical value (see Liberty & MacDonald, 2009). In the case of the DayOfWeek enumeration, the numeric values are:

public enum DayOfWeek
{
    Sunday = 0,
    Monday = 1,
    Tuesday = 2,
    Wednesday = 3,
    Thursday = 4,
    Friday = 5,
    Saturday = 6,
}

With this you can also evaluate expressions like if ((int)Bars.Time[0].DayOfWeek > 3), which will evaluate to true if the day of the current bar is a Thursday, Friday, or Saturday.

See the articles 'How to trade only during certain times with a trading strategy?' and 'How to exit a strategy position prior to the close?' for ideas how to work with times in a MultiCharts .NET trading strategy.

References

Liberty, J. & MacDonald, B. (2009). Learning C# 3.0: Master the Fundamentals of C# 3.0. Sebastopol, CA: O’Reilly Media.