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
close at end of day
-
- Posts: 196
- Joined: 08 Aug 2012
- Has thanked: 41 times
- Been thanked: 41 times
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: close at end of day
Hello shane,
Did you put the checkbox into Session End box next to 9am in your custom session template setting?
Did you put the checkbox into Session End box next to 9am in your custom session template setting?
-
- Posts: 196
- Joined: 08 Aug 2012
- Has thanked: 41 times
- Been thanked: 41 times
Re: close at end of day
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
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
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: close at end of day
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.
As an input you need to specify the local time when you need to close the position, for example 16:37:25.
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();
}
}
}
- Attachments
-
- EOD_Close.pln
- (1.99 KiB) Downloaded 1308 times
-
- Posts: 196
- Joined: 08 Aug 2012
- Has thanked: 41 times
- Been thanked: 41 times
Re: close at end of day
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
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
-
- Posts: 5
- Joined: 16 Feb 2015
- Has thanked: 2 times
Re: close at end of day
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.
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: close at end of day
Hello FrancescoDelta88,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.
You can find the PowerLanguage code here.