Topics
07 Jan 2024, 20:24
 432
 11
Replies

danerius
21 Feb 2024, 20:16

RE: Indicator lines update

firemyst said: 

What time frame are you using?

Thanks. That makes sense. Havent decided on a Timeframe yet, still in the works /danerius


@danerius

danerius
05 Feb 2024, 09:56

Bumping…


@danerius

danerius
17 Jan 2024, 20:13 ( Updated at: 18 Jan 2024, 14:11 )

RE: RE: RE: RE: RE: RE: RE: ChatGPT cBot Issues

 

Hi danerius,

Thanks. It works fine on my side

 Could you please send us some troubleshooting information the next time this happens? Please paste a link to this discussion inside the text box before you submit it.

 

Hello. I sent a report via the form on cTrader this saturday. No response yet. 

Regards /danerius


@danerius

danerius
11 Jan 2024, 19:28

RE: RE: RE: RE: RE: ChatGPT cBot Issues

PanagiotisCharalampous said: 

It seems you missed my response.

Can you please advise what DoubleRenko is?

public DoubleRenko doubleRenko;

 

Apparently I did :)

DoubleRenko is a modified version of mRenkoLineBreak. Heres the code for DoubleRenko

using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{    
   [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
   public class DoubleRenko : Indicator
   {
       [Parameter("ATR Periods (default 12)", DefaultValue = 12, MinValue = 2)]
       public int AtrPeriods { get; set; }

       [Parameter("ATR Exponent (default 1.0)", DefaultValue = 1.0, MinValue = 1.0, MaxValue = 2.0)]
       public double AtrExponent { get; set; }

       [Parameter("ATR Multiplier (default 1.0)", DefaultValue = 1.0)]
       public double AtrMultiplier { get; set; }

       [Parameter("Lookback Period (default 1000)", DefaultValue = 1000, MinValue = 1)]
       public int LookbackPeriod { get; set; }

       [Parameter("ATR Smoothing Type", DefaultValue = MovingAverageType.Exponential)]
       public MovingAverageType AtrSmoothingType { get; set; }

       [Output("Renko Top", LineColor = "Gray")]
       public IndicatorDataSeries RenkoTop { get; set; }

       [Output("Renko Bottom", LineColor = "Gray")]
       public IndicatorDataSeries RenkoBottom { get; set; }

       [Output("Current Brick", LineColor = "White", Thickness = 1)]
       public IndicatorDataSeries CurrentBrick { get; set; }

       public double _brickSize;
       public AverageTrueRange _atr;
       public bool _isAscending = true;
 

       protected override void Initialize()
       {
           _atr = Indicators.AverageTrueRange(AtrPeriods, AtrSmoothingType);
       }

       public override void Calculate(int index)
{
   if (index < LookbackPeriod)
   {
       RenkoTop[index] = double.NaN;
       RenkoBottom[index] = double.NaN;
       CurrentBrick[index] = double.NaN;
       return;
   }
   
   double atrValue = _atr.Result[index];
   _brickSize = AtrMultiplier * Math.Pow(atrValue, AtrExponent);

   if (index == LookbackPeriod)
   {
       RenkoTop[index] = Bars.ClosePrices[index];
       RenkoBottom[index] = Bars.ClosePrices[index] - _brickSize;
       _isAscending = Bars.ClosePrices[index] > Bars.ClosePrices[index - 1];
   }
   else
   {
       RenkoTop[index] = RenkoTop[index - 1];
       RenkoBottom[index] = RenkoBottom[index - 1];

       if (Bars.ClosePrices[index] >= RenkoTop[index] + _brickSize)
       {
           _isAscending = true;
           RenkoTop[index] = RenkoTop[index - 1] + _brickSize;
           RenkoBottom[index] = RenkoTop[index] - _brickSize;
       }
       else if (Bars.ClosePrices[index] <= RenkoBottom[index] - _brickSize)
       {
           _isAscending = false;
           RenkoBottom[index] = RenkoBottom[index - 1] - _brickSize;
           RenkoTop[index] = RenkoBottom[index] + _brickSize;
       }
   }

   CurrentBrick[index] = _isAscending ? RenkoTop[index] : RenkoBottom[index];
   }
}
}


@danerius

danerius
10 Jan 2024, 18:18

RE: RE: RE: ChatGPT cBot Issues

Hi danerius,

I still do not have the code in a readable format. Can you please fix the format so that we can copy/paste and build it?

Best regards,

Panagiotis

Hi. I posted the code earlier but hree it is again. Thanks /Bo


using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
using System;

namespace cAlgo.Robots
{
   [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
   public class DanRobot : Robot
   {
       [Parameter("Quantity (Lots)", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]
       public double Quantity { get; set; }

       // Additional parameters for DoubleRenko

       public DoubleRenko doubleRenko;
       public const string label = "DoubleRenko Trend cBot";
       
       // Log method here
       private void Log(string message)
       {
           Print($"[{Time}] {message}");
       }

       protected override void OnStart()
        {
           // Initialize DoubleRenko
           Log($"Initializing DoubleRenko with parameters: 12, 1.0, 1.0, 1000, MovingAverageType.Exponential");
           doubleRenko = Indicators.GetIndicator<DoubleRenko>(12, 1.0, 1.0, 1000, MovingAverageType.Exponential);
           Log("DoubleRenko initialized.");
       }


protected override void OnBar()
{
   try
   {
       Log("OnBar started");

       if (doubleRenko.CurrentBrick.Count < 2)
       {
           Log("Not enough data for CurrentBrick");
           return;
       }

       double currentBrick = doubleRenko.CurrentBrick.Last(0);
       double previousBrick = doubleRenko.CurrentBrick.Last(1);

       Log($"CurrentBrick: {currentBrick}, PreviousBrick: {previousBrick}");

       if (double.IsNaN(currentBrick) || double.IsNaN(previousBrick))
       {
           Log("NaN value encountered in CurrentBrick");
           return;
       }

       // Check for existing positions
       var longPosition = Positions.Find(label, SymbolName, TradeType.Buy);
       var shortPosition = Positions.Find(label, SymbolName, TradeType.Sell);

       // Trend detection and trading logic
       if (currentBrick > previousBrick && longPosition == null)
       {
           if (shortPosition != null)
               ClosePosition(shortPosition);

           ExecuteMarketOrder(TradeType.Buy, SymbolName, VolumeInUnits, label);
       }
       else if (currentBrick < previousBrick && shortPosition == null)
       {
           if (longPosition != null)
               ClosePosition(longPosition);

           ExecuteMarketOrder(TradeType.Sell, SymbolName, VolumeInUnits, label);
       }

       Log("OnBar completed without errors");
   }
   catch (Exception ex)
   {
       Log($"Error in OnBar: {ex.Message}");
   }
}


       public double VolumeInUnits
       {
           get { return Symbol.QuantityToVolumeInUnits(Quantity); }
       }
   }
}
 


@danerius

danerius
09 Jan 2024, 14:06

RE: RE: RE: ChatGPT cBot Issues

PanagiotisCharalampous said: 

danerius said: 

PanagiotisCharalampous said: 

Dear darenius,

If you need assistance with your cBot, you would need to provide at least the following information

  • What is the cBot supposed to do?
  • What does it do instead?
  • What is the exact problem you are trying to solve?

Best regards,

Panagiotis

Hello Panagiotis and thanks for getting back to me

Ive been working too long on trying to fix the cBot, my brain was fried and I completely missed providing more information. Sorry about that. And pardon the messy look of the code. I used the “code” function, hope you can read it anyways.

- The major issue is that its not performing any Buys or Sells. Im not even sure if its the code or my settings for the demo account. The Log messages reads:

04/01/2024 02:00:00.000 | CBot instance [DanRobot, BTCUSD, Re40] started. 
04/01/2024 02:00:00.000 | Indicator instance [DoubleRenko, BTCUSD, Re40] loaded. 
04/01/2024 02:00:00.000 | Indicator instance [Average True Range, BTCUSD, Re40] loaded. 
04/01/2024 02:00:00.000 | CBot instance [DanRobot, BTCUSD, Re40] crashed with error #F00E2180.

Lets start there and see if we can find a way to make the cBot work. Thanks /Bo

Hi danerius,

I still do not have the code in a readable format. Can you please fix the format so that we can copy/paste and build it?

Best regards,

Panagiotis

Hi. Sure. Here it is….


using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
using System;

namespace cAlgo.Robots
{
   [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
   public class DanRobot : Robot
   {
       [Parameter("Quantity (Lots)", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]
       public double Quantity { get; set; }

       // Additional parameters for DoubleRenko

       public DoubleRenko doubleRenko;
       public const string label = "DoubleRenko Trend cBot";
       
       // Log method here
       private void Log(string message)
       {
           Print($"[{Time}] {message}");
       }

       protected override void OnStart()
        {
           // Initialize DoubleRenko
           Log($"Initializing DoubleRenko with parameters: 12, 1.0, 1.0, 1000, MovingAverageType.Exponential");
           doubleRenko = Indicators.GetIndicator<DoubleRenko>(12, 1.0, 1.0, 1000, MovingAverageType.Exponential);
           Log("DoubleRenko initialized.");
       }


protected override void OnBar()
{
   try
   {
       Log("OnBar started");

       if (doubleRenko.CurrentBrick.Count < 2)
       {
           Log("Not enough data for CurrentBrick");
           return;
       }

       double currentBrick = doubleRenko.CurrentBrick.Last(0);
       double previousBrick = doubleRenko.CurrentBrick.Last(1);

       Log($"CurrentBrick: {currentBrick}, PreviousBrick: {previousBrick}");

       if (double.IsNaN(currentBrick) || double.IsNaN(previousBrick))
       {
           Log("NaN value encountered in CurrentBrick");
           return;
       }

       // Check for existing positions
       var longPosition = Positions.Find(label, SymbolName, TradeType.Buy);
       var shortPosition = Positions.Find(label, SymbolName, TradeType.Sell);

       // Trend detection and trading logic
       if (currentBrick > previousBrick && longPosition == null)
       {
           if (shortPosition != null)
               ClosePosition(shortPosition);

           ExecuteMarketOrder(TradeType.Buy, SymbolName, VolumeInUnits, label);
       }
       else if (currentBrick < previousBrick && shortPosition == null)
       {
           if (longPosition != null)
               ClosePosition(longPosition);

           ExecuteMarketOrder(TradeType.Sell, SymbolName, VolumeInUnits, label);
       }

       Log("OnBar completed without errors");
   }
   catch (Exception ex)
   {
       Log($"Error in OnBar: {ex.Message}");
   }
}


       public double VolumeInUnits
       {
           get { return Symbol.QuantityToVolumeInUnits(Quantity); }
       }
   }
}
 


@danerius

danerius
08 Jan 2024, 17:44 ( Updated at: 09 Jan 2024, 06:34 )

RE: ChatGPT cBot Issues

PanagiotisCharalampous said: 

Dear darenius,

If you need assistance with your cBot, you would need to provide at least the following information

  • What is the cBot supposed to do?
  • What does it do instead?
  • What is the exact problem you are trying to solve?

Best regards,

Panagiotis

Hello Panagiotis and thanks for getting back to me

Ive been working too long on trying to fix the cBot, my brain was fried and I completely missed providing more information. Sorry about that. And pardon the messy look of the code. I used the “code” function, hope you can read it anyways.

- The major issue is that its not performing any Buys or Sells. Im not even sure if its the code or my settings for the demo account. The Log messages reads:

04/01/2024 02:00:00.000 | CBot instance [DanRobot, BTCUSD, Re40] started. 
04/01/2024 02:00:00.000 | Indicator instance [DoubleRenko, BTCUSD, Re40] loaded. 
04/01/2024 02:00:00.000 | Indicator instance [Average True Range, BTCUSD, Re40] loaded. 
04/01/2024 02:00:00.000 | CBot instance [DanRobot, BTCUSD, Re40] crashed with error #F00E2180.

Lets start there and see if we can find a way to make the cBot work. Thanks /Bo


@danerius