Profile Picture

BarCountExit after 3 days on close

Posted By steffen 5 Years Ago
Message
Posted Thursday February 09 2012
Hello to all,

i am new here and I am trying Rightedge because i am looking for a new backtesting software. Now I have my fist issue that could not be so dificult I think. I want to close my position after 3 days with an time based exit. I found the solution with BarCountExit but this just works with market on open. Is there any posibility to make this work with market on close? I tried now for hours and i didnt get it.

Thanks a lot for your help.

Posted Friday February 10 2012
The built-in BarCountExit won't work for this. You need to write code to check how many bars the position has been open and close it yourself if necessary. Here's an example of how to do that:


foreach (Position pos in OpenPositions)
{
if (pos.BarsHeld <= 2)
{
OrderSettings settings = new OrderSettings();
settings.OrderType = OrderType.MarketOnClose;
settings.TransactionType = pos.Info.ExitTransType;
settings.Size = pos.CurrentSize;
Order order = pos.SubmitOrder(orderSettings);
if (order.Error != null)
{
OutputWarning(order.Error);
}
}
}


Let us know if you have any issues.

Thanks,
Daniel
Posted Friday February 10 2012
Thanks a lot.
Now it works!

phg
Supreme Being (44,871 reputation)Supreme Being (44,871 reputation)Supreme Being (44,871 reputation)Supreme Being (44,871 reputation)Supreme Being (44,871 reputation)Supreme Being (44,871 reputation)Supreme Being (44,871 reputation)Supreme Being (44,871 reputation)Supreme Being (44,871 reputation)
Posted Saturday February 11 2012
If you wanted to close 3 days later independent of bar size alternatively you could use dates and times:
DateTime barTime = Bars.Current.PriceDateTime;  // Date and time of current bar

foreach(Position pos in OpenPositions)
. . .  pos.OpenDate.Date . . .   // Pseudo code. To illustrate that each position has a time stamp.

So you could base your logic off the difference in these time quantities as well.

-Pete

See also Yahoo group about applying RE.



Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems