Is it possible in C bot?
Is it possible in C bot?
18 Mar 2024, 15:58
Is it possible in a C bot?
If the C bot is supposed to open a trade when the candle is green at candle close (if open < close), is it possible for it to open the trade 10 seconds or x seconds before the candle closes?
If open > current price, the current price will be obtained 10 seconds before the close of every candle.
I want to avoid these situations.
Replies
flappiyt
19 Mar 2024, 15:53
( Updated at: 19 Mar 2024, 16:00 )
RE: Is it possible in C bot?
PanagiotisCharalampous said:
Hi there,
Yes it is. You need to calculate your candle's duration and then detect when the upcoming closing time is closer that 10 seconds, then execute your logic.
Best regards,
Panagiotis
Hi Panagiotis
Could you please tell me how to do that? Do I have to start the bot at the exact hour, like 15:35:00, and then calculate it, or is there an easier way? The bot will be opening trades on a 5-minute chart.
I have created a bot like this, but it only prints "Green candle" after the candle closes; it prints it at exact hours not 10 s before.
using System;
using cAlgo.API;
namespace cAlgo
{
[Robot(TimeZone = TimeZones.UTC)]
public class BOT : Robot
{
int PeriodInSeconds = 300;
int Seconds = 10;
protected override void OnBar() // On tick doesn't work either
{
var timeToClose = PeriodInSeconds - (Server.Time - MarketSeries.OpenTime.Last(1)).TotalSeconds;
if (timeToClose <= Seconds)
{
var lastCandle = MarketSeries.Open.Last(1);
if (lastCandle > MarketSeries.Close.Last(1))
{
Print("Green candle");
}
}
}
}
}
@flappiyt
PanagiotisCharalampous
20 Mar 2024, 07:06
RE: RE: Is it possible in C bot?
flappiyt said:
PanagiotisCharalampous said:
Hi there,
Yes it is. You need to calculate your candle's duration and then detect when the upcoming closing time is closer that 10 seconds, then execute your logic.
Best regards,
Panagiotis
Hi Panagiotis
Could you please tell me how to do that? Do I have to start the bot at the exact hour, like 15:35:00, and then calculate it, or is there an easier way? The bot will be opening trades on a 5-minute chart.
I have created a bot like this, but it only prints "Green candle" after the candle closes; it prints it at exact hours not 10 s before.
using System;
using cAlgo.API;
namespace cAlgo
{
[Robot(TimeZone = TimeZones.UTC)]
public class BOT : Robot
{
int PeriodInSeconds = 300;
int Seconds = 10;
protected override void OnBar() // On tick doesn't work either
{
var timeToClose = PeriodInSeconds - (Server.Time - MarketSeries.OpenTime.Last(1)).TotalSeconds;
if (timeToClose <= Seconds)
{
var lastCandle = MarketSeries.Open.Last(1);
if (lastCandle > MarketSeries.Close.Last(1))
{
Print("Green candle");
}
}
}
}
}
Hi there,
Unfortunately I cannot write the code for you. If you need professional assistance, you can contact a consultant
Best regards,
Panagiotis
@PanagiotisCharalampous
flappiyt
21 Mar 2024, 16:01
RE: RE: RE: Is it possible in C bot?
PanagiotisCharalampous said:
flappiyt said:
PanagiotisCharalampous said:
Hi there,
Yes it is. You need to calculate your candle's duration and then detect when the upcoming closing time is closer that 10 seconds, then execute your logic.
Best regards,
Panagiotis
Hi Panagiotis
Could you please tell me how to do that? Do I have to start the bot at the exact hour, like 15:35:00, and then calculate it, or is there an easier way? The bot will be opening trades on a 5-minute chart.
I have created a bot like this, but it only prints "Green candle" after the candle closes; it prints it at exact hours not 10 s before.
using System;
using cAlgo.API;
namespace cAlgo
{
[Robot(TimeZone = TimeZones.UTC)]
public class BOT : Robot
{
int PeriodInSeconds = 300;
int Seconds = 10;
protected override void OnBar() // On tick doesn't work either
{
var timeToClose = PeriodInSeconds - (Server.Time - MarketSeries.OpenTime.Last(1)).TotalSeconds;
if (timeToClose <= Seconds)
{
var lastCandle = MarketSeries.Open.Last(1);
if (lastCandle > MarketSeries.Close.Last(1))
{
Print("Green candle");
}
}
}
}
}
Hi there,
Unfortunately I cannot write the code for you. If you need professional assistance, you can contact a consultant
Best regards,
Panagiotis
Hi Panagiotis
I don't want you to write code for me, I only want to ask what methods are used to implement this in C#.
@flappiyt
PanagiotisCharalampous
22 Mar 2024, 08:15
RE: RE: RE: RE: Is it possible in C bot?
flappiyt said:
PanagiotisCharalampous said:
flappiyt said:
PanagiotisCharalampous said:
Hi there,
Yes it is. You need to calculate your candle's duration and then detect when the upcoming closing time is closer that 10 seconds, then execute your logic.
Best regards,
Panagiotis
Hi Panagiotis
Could you please tell me how to do that? Do I have to start the bot at the exact hour, like 15:35:00, and then calculate it, or is there an easier way? The bot will be opening trades on a 5-minute chart.
I have created a bot like this, but it only prints "Green candle" after the candle closes; it prints it at exact hours not 10 s before.
using System;
using cAlgo.API;
namespace cAlgo
{
[Robot(TimeZone = TimeZones.UTC)]
public class BOT : Robot
{
int PeriodInSeconds = 300;
int Seconds = 10;
protected override void OnBar() // On tick doesn't work either
{
var timeToClose = PeriodInSeconds - (Server.Time - MarketSeries.OpenTime.Last(1)).TotalSeconds;
if (timeToClose <= Seconds)
{
var lastCandle = MarketSeries.Open.Last(1);
if (lastCandle > MarketSeries.Close.Last(1))
{
Print("Green candle");
}
}
}
}
}
Hi there,
Unfortunately I cannot write the code for you. If you need professional assistance, you can contact a consultant
Best regards,
Panagiotis
Hi Panagiotis
I don't want you to write code for me, I only want to ask what methods are used to implement this in C#.
There is no specific method. You need to write the logic yourself. You need to find the candle duration based on bar open times and then keep track of the time elapsed in each candle. When the specified time has elapsed, you need to execute your logic. The only way to help you further is to write the code for you.
@PanagiotisCharalampous
PanagiotisCharalampous
19 Mar 2024, 07:54
Hi there,
Yes it is. You need to calculate your candle's duration and then detect when the upcoming closing time is closer that 10 seconds, then execute your logic.
Best regards,
Panagiotis
@PanagiotisCharalampous