I followed your instructions, but my bot is still not working. And I reconstructed it so it looks like this
//#reference: ..\Indicators\John.algo 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)] public class HAK : Robot { [Parameter("Initial Volume", DefaultValue = 1, MinValue = 1)] public int InitialVolume { get; set; }
[Parameter("Initial Stop Loss", DefaultValue = 40)] public int SL { get; set; }
[Parameter("Initial Take Profit", DefaultValue = 40)] public int TP { get; set; }
public bool isAlreadyInTrade; public IndicatorDataSeries haClose { get; set; } public IndicatorDataSeries haOpen { get; set; } public John HAJ; string label = "HAK";
telefonowelolo
02 Mar 2024, 09:59 ( Updated at: 03 Mar 2024, 07:09 )
RE: The cBot is not entering trades.
PanagiotisCharalampous said:
Hi PanagiotisCharalampous
I followed your instructions, but my bot is still not working. And I reconstructed it so it looks like this
//#reference: ..\Indicators\John.algo
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)]
public class HAK : Robot
{
[Parameter("Initial Volume", DefaultValue = 1, MinValue = 1)]
public int InitialVolume { get; set; }
[Parameter("Initial Stop Loss", DefaultValue = 40)]
public int SL { get; set; }
[Parameter("Initial Take Profit", DefaultValue = 40)]
public int TP { get; set; }
public bool isAlreadyInTrade;
public IndicatorDataSeries haClose { get; set; }
public IndicatorDataSeries haOpen { get; set; }
public John HAJ;
string label = "HAK";
protected override void OnStart()
{
Positions.Closed += OnPositionClosed;
HAJ = Indicators.GetIndicator<John>(10, MovingAverageType.Simple);
isAlreadyInTrade = false;
}
private void OnPositionClosed(PositionClosedEventArgs args)
{
isAlreadyInTrade = false;
}
protected override void OnBar()-----------------tried OnBarClosed()
{
int index = MarketSeries.Close.Count - 2;
if (!isAlreadyInTrade)
{
Print("Current value of Kolor: " + HAJ.Kolor);
if (HAJ.Kolor)
{
ExecuteMarketOrder(TradeType.Buy, Symbol, InitialVolume, label, SL, TP);
isAlreadyInTrade = true;
}
//else
//{
//ExecuteMarketOrder(TradeType.Sell, Symbol, InitialVolume, label, SL, TP);
//isAlreadyInTrade = true;
//}
}
}
}
}
I found out that the bot somehow thinks the kolor is always false
Indicator:
public Colors Color;
public bool Kolor { get; set; }
Color = (haOpen[index] > haClose[index]) ? Colors.Red : Colors.LimeGreen;
Kolor = (haClose[index] > haOpen[index]);
@telefonowelolo