Topics
Replies
jwandia2022
09 Nov 2022, 09:24
RE: How to build an indicator in a cbot with DataSeries
Hi,
The two errors I'm getting while building out the indicator in the cbot are:
- Error CS0103: The name 'High' does not exist in the current context
- Error CS0103: The name 'Low' does not exist in the current context
Joyce
@jwandia2022
jwandia2022
05 Oct 2022, 11:44
( Updated at: 21 Dec 2023, 09:22 )
RE: RE: RE: RE: RE:
You forgot to declare the variable for the dailyBars. Above the OnStart() method you just need private Bars dailyBars;
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo.Robots { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class New : Robot { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } private Bars dailyBars; protected override void OnStart() { // Put your initialization logic here dailyBars = MarketData.GetBars("Daily"); } protected override void OnTick() { // Put your core logic here } protected override void OnBar() { // Put your core logic here if (Bars.Last(0).Close > dailyBars.Last(0).Close) { ///Execute Buy Trade } if (Bars.Last(0).Close < dailyBars.Last(0).Close) { ///Execute Sell Trade } } protected override void OnStop() { // Put your deinitialization logic here } } }
I'm still not able to get the sample code above to build on CTrader. Error messages:
Kindly assist.
Joyce.
@jwandia2022
jwandia2022
05 Oct 2022, 10:16
RE: RE: RE: RE: RE:
Thanks. I had not noticed that beforehand.
@jwandia2022
jwandia2022
03 Oct 2022, 14:02
RE: RE: RE:
jwandia2022 said:
ctid3999979 said:
jwandia2022 said:
Hi All,
Is there any way to write a logic that allows a cbot execute a buy/sell trade once the Daily Market Open Price is crossed?
Joyce.
If I'm understanding your query correctly, you could use the MarketData.GetBars() method to get the daily candles, then write some code such as
dailyBars = MarketData.GetBars("Daily"); protected override void OnBar() { if (Bars.Last(0).Close > dailyBars.Last(0).Close) { ExecuteMarketOrder() } }
Hi Again,
Which syntax should I use before "dailyBars = MarketData.GetBars("Daily")" to call the method?
Below is a sample of the code
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class New : Robot
{
[Parameter(DefaultValue = 0.0)]
public double Parameter { get; set; }
protected override void OnStart()
{
// Put your initialization logic here
dailyBars = MarketData.GetBars("Daily");
}
protected override void OnTick()
{
// Put your core logic here
}
protected override void OnBar()
{
// Put your core logic here
if (Bars.Last(0).Close > dailyBars.Last(0).Close)
{
///Execute Buy Trade
}
if (Bars.Last(0).Close < dailyBars.Last(0).Close)
{
///Execute Sell Trade
}
}
protected override void OnStop()
{
// Put your deinitialization logic here
}
}
}
@jwandia2022
jwandia2022
03 Oct 2022, 12:50
RE: RE:
ctid3999979 said:
jwandia2022 said:
Hi All,
Is there any way to write a logic that allows a cbot execute a buy/sell trade once the Daily Market Open Price is crossed?
Joyce.
If I'm understanding your query correctly, you could use the MarketData.GetBars() method to get the daily candles, then write some code such as
dailyBars = MarketData.GetBars("Daily"); protected override void OnBar() { if (Bars.Last(0).Close > dailyBars.Last(0).Close) { ExecuteMarketOrder() } }
Hi Again,
Which syntax should I use before "dailyBars = MarketData.GetBars("Daily")" to call the method?
@jwandia2022
jwandia2022
03 Oct 2022, 10:53
RE: RE:
ctid3999979 said:
jwandia2022 said:
Hi All,
Is there any way to write a logic that allows a cbot execute a buy/sell trade once the Daily Market Open Price is crossed?
Joyce.
If I'm understanding your query correctly, you could use the MarketData.GetBars() method to get the daily candles, then write some code such as
dailyBars = MarketData.GetBars("Daily"); protected override void OnBar() { if (Bars.Last(0).Close > dailyBars.Last(0).Close) { ExecuteMarketOrder() } }
Thanks. Will try working with this solution and see what happens.
@jwandia2022
jwandia2022
11 Nov 2022, 13:30
RE:
Hi
Found a solution already from one of the forums. Thank you.
Joyce.
@jwandia2022