Hi, I've applied this script as a separate strategy in Portfolio Trader to close any remaining open positions ahead of the close. It doesn't work, however. Any idea why? All other signals run on 15 min bars, this one on 3 min. MC.NET64 v.10 release (Build 13630), Win 7
Many thanks
using System;
namespace PowerLanguage.Strategy
{
[IOGMode(IOGMode.Disabled)]
public class EOD_Close : SignalObject
{
private IOrderMarket EOD_LX;
private IOrderMarket EOD_SX;
public EOD_Close(object ctx) :
base(ctx)
{
TimeClosePosition="12:54: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();
}
}
}
Using EOD_Close with Portfolio Trader [SOLVED]
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: Using EOD_Close with Portfolio Trader
Hello darob,
It looks like your strategy does not generate the orders when CalcBar is called on bar close.
It looks like your strategy does not generate the orders when CalcBar is called on bar close.
Re: Using EOD_Close with Portfolio Trader
Hi Henry, I grabbed the script from here: viewtopic.php?f=19&t=27758&p=79950 and have applied it as-is. It looks like CalcBar is checking for the correct time, and if correct, OnRecalcLastBarAfterEvent should generate the order/s. Is there something else that should be done to run the script in Portfolio Trader?
Thanks
Thanks
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: Using EOD_Close with Portfolio Trader [SOLVED]
Hello darob,
You need to modify the code to have the orders generated on bar close. The EOD exit sample code we have provided generates the orders before bar close event occurs.
You need to modify the code to have the orders generated on bar close. The EOD exit sample code we have provided generates the orders before bar close event occurs.