Backtest: How to enter a trade at the Open of the *next* bar

Created at 07 Nov 2024, 13:09
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!
MA

markmath01

Joined 07.11.2024

Backtest: How to enter a trade at the Open of the *next* bar
07 Nov 2024, 13:09


Hi,

There could someone explain to me how to execute a trade based on the Open Price of the next bar once the Closing Price of the latest bar has been generated and the bar is complete?

Essentially, I am looking for something like an “OnBarOpen” method or similar.

Thanks


@markmath01
Replies

firemyst
09 Nov 2024, 13:50

If you're programming a bot, use the OnBar() method. 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
    public class ThirdBarMarketOrderBot : Robot
    {
        private int barCount;

        protected override void OnStart()
        {
            barCount = 0;
        }

        protected override void OnBar()
        {
            barCount++;
            Print ("Bar count {0}", barCount);

        }
    }
}

You can find more about it by googling “calgo onbar”


@firemyst

markmath01
09 Nov 2024, 18:01 ( Updated at: 10 Nov 2024, 15:35 )

RE: Backtest: How to enter a trade at the Open of the *next* bar

firemyst said: 

If you're programming a bot, use the OnBar() method. 

using System;using System.Collections.Generic;using System.Linq;using System.Text;using cAlgo.API;using cAlgo.API.Collections;using cAlgo.API.Indicators;using cAlgo.API.Internals;namespace cAlgo{    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]    public class ThirdBarMarketOrderBot : Robot    {        private int barCount;        protected override void OnStart()        {            barCount = 0;        }        protected override void OnBar()        {            barCount++;            Print ("Bar count {0}", barCount);        }    }}

You can find more about it by googling “calgo onbar”

Thanks !


@markmath01