Using EOD_Close with Portfolio Trader  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
darob
Posts: 207
Joined: 20 Nov 2014
Has thanked: 57 times
Been thanked: 32 times

Using EOD_Close with Portfolio Trader

Postby darob » 06 Dec 2016

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();
}
}
}

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

Re: Using EOD_Close with Portfolio Trader

Postby Henry MultiСharts » 07 Dec 2016

Hello darob,

It looks like your strategy does not generate the orders when CalcBar is called on bar close.

darob
Posts: 207
Joined: 20 Nov 2014
Has thanked: 57 times
Been thanked: 32 times

Re: Using EOD_Close with Portfolio Trader

Postby darob » 07 Dec 2016

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

User avatar
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]

Postby Henry MultiСharts » 09 Dec 2016

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.

darob
Posts: 207
Joined: 20 Nov 2014
Has thanked: 57 times
Been thanked: 32 times

Re: Using EOD_Close with Portfolio Trader

Postby darob » 09 Dec 2016

Hi Henry, thanks for explaining this.


Return to “MultiCharts .NET”