Start trading

To signal the market open

Created at 09 Nov 2022, 21:35
cTrader Reddit
cTrader Discord
AL

Algo_Invest

Joined 19.03.2020

To signal the market open
09 Nov 2022, 21:35


Hello,
 

Since, apparently, it's not possible to identify, from the API, the exact moment when a market opens, I was trying to create a simple method do check this.

When backtesting, I've noticed that this works great for forex but not for indices:

  • Forex: A confirmation on market close/open moment is shown every weekday at the correct time.
  • Indices: This seems to be randomly taken since, it is not returned on every weekday, however, such markets also have a break everyday.


In fact, it is not the first time I've noticed that some code works great for forex but not for indices.

Is there any reason for such inconsistency? It's also possible that I am missing something here.

Below is the code.
Thanks in advance.

using cAlgo.API;

namespace cAlgo.Robots
{
    [Robot(AccessRights = AccessRights.None)]
    public class OnTimertest : Robot
    {
        [Parameter(DefaultValue = "Hello world!")]
        public string Message { get; set; }
        
        private bool _marketJustOpened;

        protected override void OnStart()
        {       
            Timer.Start(1);
        }
        
        protected override void OnTimer()
        {          
            if (Symbol.MarketHours.IsOpened() && _marketJustOpened)
            {
                _marketJustOpened = false;
                Print("MARKET HAS JUST OPENED"); 
            }

            if (!Symbol.MarketHours.IsOpened() && !_marketJustOpened)
            {
                _marketJustOpened = true;
                Print("MARKET IS CLOSED");
            }  
        }
    }
}

 


@Algo_Invest
Replies

PanagiotisChar
10 Nov 2022, 09:26

Hi there,

Any examples so that we can reproduce? Index, broker, backtesting dates?

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 


@PanagiotisChar

Algo_Invest
10 Nov 2022, 10:01

RE:

Hi Panagiotis,

Thanks for your reply!

You can try, for instante: US500, Pepperstone, Jan 2021-Today.

 

PanagiotisChar said:

Hi there,

Any examples so that we can reproduce? Index, broker, backtesting dates?

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 

 


@Algo_Invest

Algo_Invest
15 Nov 2022, 15:51

RE: RE:

Hi Panagiotis,

Is there any update on this?

 

ncel01 said:

Hi Panagiotis,

Thanks for your reply!

You can try, for instante: US500, Pepperstone, Jan 2021-Today.

 

PanagiotisChar said:

Hi there,

Any examples so that we can reproduce? Index, broker, backtesting dates?

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 

 

 


@Algo_Invest

PanagiotisChar
16 Nov 2022, 08:58

Hi there,

I ran the cBot but I cannot see any problem. Open and close times seem in line with what the broker has configured.

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us


@PanagiotisChar

Algo_Invest
16 Nov 2022, 09:55

RE:

Hi Panagiotis,

Could you please share the output?

I'd like to compare your results with mine.

Thanks.

 

PanagiotisChar said:

Hi there,

I ran the cBot but I cannot see any problem. Open and close times seem in line with what the broker has configured.

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 


@Algo_Invest