close at end of day

Questions about MultiCharts .NET and user contributed studies.
shanemcdonald
Posts: 196
Joined: 08 Aug 2012
Has thanked: 41 times
Been thanked: 41 times

close at end of day

Postby shanemcdonald » 28 Jun 2013

hi

I was testing the " Close at end of day " exit signal on a custom session of 7am to 9am.
After the session closed, the position remained open. It did not send any more signals, but it did not close the position.

Any thoughts ?

shane

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: close at end of day

Postby Henry MultiСharts » 28 Jun 2013

Hello shane,

Did you put the checkbox into Session End box next to 9am in your custom session template setting?

shanemcdonald
Posts: 196
Joined: 08 Aug 2012
Has thanked: 41 times
Been thanked: 41 times

Re: close at end of day

Postby shanemcdonald » 29 Jun 2013

hi

yes , session end is checked
when the SA is off, the historical trade history shows that the signal is working.
With SA on during live trading, it does not close position. It leaves position open.

thanks
shane

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: close at end of day

Postby Henry MultiСharts » 02 Jul 2013

Hello Shane,

In real time action the "GenerateExitOnClose" conditions are not always met.
There are two conditions that should be met:
Session end and a simultaneous with session end tick.
The second condition is not always met, this can happen if the market is slow and then the position won’t close.
You can achieve your goal by using this script. You need to apply it as a separate strategy.

Code: Select all

using System;
namespace PowerLanguage.Strategy
{
[IOGMode(IOGMode.Enabled)]
public class EOD_Close : SignalObject
{
private IOrderMarket EOD_LX;
private IOrderMarket EOD_SX;

public EOD_Close(object ctx) :
base(ctx)
{
TimeClosePosition="23:59:00";
}
[Input]
public string TimeClosePosition { get; set; }

protected override void Create()
{
EOD_LX = OrderCreator.MarketNextBar(new SOrderParameters(Contracts.Default, "EOD_LX", EOrderAction.BuyToCover));
EOD_SX = OrderCreator.MarketNextBar(new SOrderParameters(Contracts.Default, "EOD_SX", EOrderAction.Sell));
}
protected override void CalcBar()
{
DateTime CloseTime = Convert.ToDateTime(TimeClosePosition);
if (DateTime.Now.TimeOfDay >= CloseTime.TimeOfDay)
{
ExecControl.RecalcLastBarAfter(new TimeSpan(0, 0, 1));
}
}

protected override void OnRecalcLastBarAfterEvent() {
if (StrategyInfo.MarketPosition != 0)
{
ExecControl.RecalcLastBarAfter(new TimeSpan(0, 0, 1));
}
EOD_LX.Send();
EOD_SX.Send();
}
}
}
As an input you need to specify the local time when you need to close the position, for example 16:37:25.
Attachments
EOD_Close.pln
(1.99 KiB) Downloaded 1298 times

shanemcdonald
Posts: 196
Joined: 08 Aug 2012
Has thanked: 41 times
Been thanked: 41 times

Re: close at end of day

Postby shanemcdonald » 02 Jul 2013

Hi

Thank you very much for your info Henry.
You have always been very helpful

As a workaround, I used the other signal called Stops and Targets. That one works ok.
But your code is very helpful, thanks.

sincerely,

shane

FrancescoDelta88
Posts: 5
Joined: 16 Feb 2015
Has thanked: 2 times

Re: close at end of day

Postby FrancescoDelta88 » 16 Feb 2015

Is there a way to replicate such code also in Multicharts (not .NET)? I need to close position EOD if opened and cancel orders othetrwise, in a custom session of trading in a market.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: close at end of day

Postby Henry MultiСharts » 17 Feb 2015

Is there a way to replicate such code also in Multicharts (not .NET)? I need to close position EOD if opened and cancel orders othetrwise, in a custom session of trading in a market.
Hello FrancescoDelta88,

You can find the PowerLanguage code here.


Return to “MultiCharts .NET”