Open a postition at a specific day and time each week

Created at 06 Nov 2013, 18:35
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
jhtrader's avatar

jhtrader

Joined 15.10.2013 Blocked

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

jhtrader
06 Nov 2013, 18:37

Can you suggest a method to get the second last bar of the week?

jhtrader said:

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.

 

 

 

 


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

9718853
12 Nov 2014, 11:49

Timer

Can you please provide an example of using the timer to start on sundays market open and close on Fridays market close? Every reference to the Timer Object seems to use it to trade quicker than on Tick....


@9718853