Open a postition at a specific day and time each week
06 Nov 2013, 18:35
Hi,
I want to open a bunch of positions one hour after the market opens. I also want to close all positions on the market close.
I am using UTC- 5
DateTime currentTime = MarketSeries.OpenTime[MarketSeries.OpenTime.Count - 1]
DateTime previousTime = MarketSeries.OpenTime[MarketSeries.OpenTime.Count - 2]
if (currentTime.DayOfWeek == DayOfWeek.Sunday && previousTime.DayOfWeek != DayOfWeek.Sunday && TokyoMarketOpen)
{
//first bar of the week
}
** "TokyoMarketOpen" is calculated elsewhere and is true when the Tokyo session is active.
Replies
fzlogic
13 Nov 2013, 14:40
private int _firstBarIndex = -1;
private int _secondBar;
protected override void OnStart()
{
// Put your initialization logic here
}
protected override void OnBar()
{
// Put your core logic here
DateTime currentTime = MarketSeries.OpenTime[MarketSeries.OpenTime.Count - 1];
DateTime previousTime = MarketSeries.OpenTime[MarketSeries.OpenTime.Count - 2];
int index = MarketSeries.OpenTime.Count - 1;
if (currentTime.DayOfWeek == DayOfWeek.Sunday && previousTime.DayOfWeek != DayOfWeek.Sunday)
{
//first bar of the week
_firstBarIndex = index;
}
if (index == _firstBarIndex + 1)
{
// second bar of the week
_secondBar = index;
Print(MarketSeries.OpenTime[_secondBar]);
}
}
@fzlogic
Spotware
03 Jul 2014, 11:46
Now you can implement by using the Timer object:
http://www.spotware.com/about/news-updates/ctrader-and-calgo-updates---july-2014/637
@Spotware

jhtrader
06 Nov 2013, 18:37
Can you suggest a method to get the second last bar of the week?
jhtrader said: