Bars are not time based but tick based. Therefore the OnBar() method will be triggered when the new tick for that time range arrives. So if the tick comes 10 seconds after the previous bar was supposed to be closed, the OnBar method will be triggered with 10 seconds delay. If no tick arrives within that timeframe, then no bar will be formed.
We have received the exception and the issue will be solved in an upcoming release.
Regarding the SL issue, we would need the cBot code and backtesting parameters in order to reproduce this and explain what happens.
Best regards,
Panagiotis
Hi Panagiotis,
Here is the test code that produce the SL issue, I'm using Nikkei225, Hm1 for testing
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.Robots { [Robot(AccessRights = AccessRights.FullAccess, TimeZone = TimeZones.EasternStandardTime)] public class Test2 : Robot { [Parameter(DefaultValue = 10, MinValue = 0, MaxValue = 500, Step = 10)] public int lossCut { get; set; } [Parameter(DefaultValue = 10, MinValue = 0, MaxValue = 500, Step = 10)] public int takeProfit { get; set; } double volume = 0.0; protected override void OnStart() { // To learn more about cTrader Automate visit our Help Center: // https://help.ctrader.com/ctrader-automate }
Can you also tell me the broker? This usually happens when your SL falls within the symbol's spread. Please check if this is the case
Hi there,
You can use Positions.Opened event and check if the stop loss was set. If the stop loss is null you can act accordingly i.e. place it at a valid distance.
Best regards,
Panagiotis
I want not to submit an order if the StopLoss price is invalid.
so, I wrote a if check statement like below but my order is still without SL (empty SL). Why?
if (stopLossPrice < Symbol.Ask - Symbol.Spread) // Check if stop loss is valid ExecuteMarketOrder(TradeType.Buy, Symbol.Name, volume, "Test", StopLossPips, TakeProfitPips, stopLossPrice.ToString());
We have received the exception and the issue will be solved in an upcoming release.
Regarding the SL issue, we would need the cBot code and backtesting parameters in order to reproduce this and explain what happens.
Best regards,
Panagiotis
Hi Panagiotis,
Here is the test code that produce the SL issue, I'm using Nikkei225, Hm1 for testing
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.Robots { [Robot(AccessRights = AccessRights.FullAccess, TimeZone = TimeZones.EasternStandardTime)] public class Test2 : Robot { [Parameter(DefaultValue = 10, MinValue = 0, MaxValue = 500, Step = 10)] public int lossCut { get; set; } [Parameter(DefaultValue = 10, MinValue = 0, MaxValue = 500, Step = 10)] public int takeProfit { get; set; } double volume = 0.0; protected override void OnStart() { // To learn more about cTrader Automate visit our Help Center: // https://help.ctrader.com/ctrader-automate }
We have received the exception and the issue will be solved in an upcoming release.
Regarding the SL issue, we would need the cBot code and backtesting parameters in order to reproduce this and explain what happens.
Best regards,
Panagiotis
Hi Panagiotis,
Here is the test code that produce the SL issue, I'm using Nikkei225, Hm1 for testing
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.Robots { [Robot(AccessRights = AccessRights.FullAccess, TimeZone = TimeZones.EasternStandardTime)] public class Test2 : Robot { [Parameter(DefaultValue = 10, MinValue = 0, MaxValue = 500, Step = 10)] public int lossCut { get; set; } [Parameter(DefaultValue = 10, MinValue = 0, MaxValue = 500, Step = 10)] public int takeProfit { get; set; } double volume = 0.0; protected override void OnStart() { // To learn more about cTrader Automate visit our Help Center: // https://help.ctrader.com/ctrader-automate }
This happens because you only assign values to indicator data series, when the index of each higher timeframe changes. Hence for the rest of the array elements the value stays NaN. The solution to this depends on what you want to achieve. For example, why do you
Thank you for your reply. I want to test my GMMA strategy with multi-timeframe.
My cBot staretegy is 1hour resolution and should be able to access to the above custom indicator(multi-timeframe GMMA)'s TimeFrame.Hour4 Last(n) values.
Can you me an example on how to code this correctly?
Hi there,
I am sorry but I cannot write the code for you. If you have specific questions, I am happy to answer them. At the moment I do not see a reason to leave the data series values to NaN.
Best regards,
Panagiotis
Hello Panagiotis,
What do you mean by “At the moment I do not see a reason to leave the data series values to NaN.” ?
I made some mistakes in my code?
Can you share the cBot code as well so that I can tell you exactly where the problem is?
Hi Panagiotis,
Yes, I can share the cBot code to you.
here it is.
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;using cAlgo.Indicators;namespace cAlgo.Robots{ [Robot(AccessRights = AccessRights.FullAccess, TimeZone = TimeZones.TokyoStandardTime)] public class GMMASingle : Robot { private GMMA _gmma; protected override void OnStart() { // To learn more about cTrader Automate visit our Help Center: // https://help.ctrader.com/ctrader-automate _gmma = Indicators.GetIndicator<GMMA>(); } protected override void OnBar() { Print(_gmma.LongEma1.Last(1)," ",_gmma.LongEma4.Last(1)); // <--- prints NaN NaN if (_gmma.LongEma1.IsRising() && _gmma.LongEma4.IsRising()) { ExecuteMarketOrder(TradeType.Buy, Symbol.Name, 100, "GMMA", null, null); } if (_gmma.LongEma1.IsFalling() && _gmma.LongEma4.IsFalling()) { ExecuteMarketOrder(TradeType.Sell, Symbol.Name, 100, "GMMA", null, null); } } protected override void OnStop() { // Handle cBot stop here } }}
Hi there,
Here is a visualization of your problem using the debugger
Your Indicator data series have NaN values because you do not assign anything to them when the time does not match the higher timeframe time. Hence the problems in your logic.
I do not understand why you have created a separate indicator for this and have to manage all this complexity. You could just initialize the moving averages inside your cBot and use them.
Best regards,
Panagiotis
Hi Panagiotis,
Thank you for the screenshot. I see the problem now.
I changed my cBot code as following and it seems to print higher time frame values correctly.
However, how can I display, for example, this _longEma2 onto my bachtest chart?
This happens because you only assign values to indicator data series, when the index of each higher timeframe changes. Hence for the rest of the array elements the value stays NaN. The solution to this depends on what you want to achieve. For example, why do you
Thank you for your reply. I want to test my GMMA strategy with multi-timeframe.
My cBot staretegy is 1hour resolution and should be able to access to the above custom indicator(multi-timeframe GMMA)'s TimeFrame.Hour4 Last(n) values.
Can you me an example on how to code this correctly?
Hi there,
I am sorry but I cannot write the code for you. If you have specific questions, I am happy to answer them. At the moment I do not see a reason to leave the data series values to NaN.
Best regards,
Panagiotis
Hello Panagiotis,
What do you mean by “At the moment I do not see a reason to leave the data series values to NaN.” ?
I made some mistakes in my code?
Can you share the cBot code as well so that I can tell you exactly where the problem is?
Hi Panagiotis,
Yes, I can share the cBot code to you.
here it is.
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;using cAlgo.Indicators;namespace cAlgo.Robots{ [Robot(AccessRights = AccessRights.FullAccess, TimeZone = TimeZones.TokyoStandardTime)] public class GMMASingle : Robot { private GMMA _gmma; protected override void OnStart() { // To learn more about cTrader Automate visit our Help Center: // https://help.ctrader.com/ctrader-automate _gmma = Indicators.GetIndicator<GMMA>(); } protected override void OnBar() { Print(_gmma.LongEma1.Last(1)," ",_gmma.LongEma4.Last(1)); // <--- prints NaN NaN if (_gmma.LongEma1.IsRising() && _gmma.LongEma4.IsRising()) { ExecuteMarketOrder(TradeType.Buy, Symbol.Name, 100, "GMMA", null, null); } if (_gmma.LongEma1.IsFalling() && _gmma.LongEma4.IsFalling()) { ExecuteMarketOrder(TradeType.Sell, Symbol.Name, 100, "GMMA", null, null); } } protected override void OnStop() { // Handle cBot stop here } }}
Hi there,
Here is a visualization of your problem using the debugger
Your Indicator data series have NaN values because you do not assign anything to them when the time does not match the higher timeframe time. Hence the problems in your logic.
I do not understand why you have created a separate indicator for this and have to manage all this complexity. You could just initialize the moving averages inside your cBot and use them.
Best regards,
Panagiotis
Hi Panagiotis,
Thank you for the screenshot. I see the problem now.
I changed my cBot code as following and it seems to print higher time frame values correctly.
However, how can I display, for example, this _longEma2 onto my bachtest chart?
This happens because you only assign values to indicator data series, when the index of each higher timeframe changes. Hence for the rest of the array elements the value stays NaN. The solution to this depends on what you want to achieve. For example, why do you
Thank you for your reply. I want to test my GMMA strategy with multi-timeframe.
My cBot staretegy is 1hour resolution and should be able to access to the above custom indicator(multi-timeframe GMMA)'s TimeFrame.Hour4 Last(n) values.
Can you me an example on how to code this correctly?
Hi there,
I am sorry but I cannot write the code for you. If you have specific questions, I am happy to answer them. At the moment I do not see a reason to leave the data series values to NaN.
Best regards,
Panagiotis
Hello Panagiotis,
What do you mean by “At the moment I do not see a reason to leave the data series values to NaN.” ?
I made some mistakes in my code?
Can you share the cBot code as well so that I can tell you exactly where the problem is?
Hi Panagiotis,
Yes, I can share the cBot code to you.
here it is.
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;
using cAlgo.Indicators;
namespace cAlgo.Robots
{
[Robot(AccessRights = AccessRights.FullAccess, TimeZone = TimeZones.TokyoStandardTime)]
public class GMMASingle : Robot
{
private GMMA _gmma;
protected override void OnStart()
{
// To learn more about cTrader Automate visit our Help Center:
// https://help.ctrader.com/ctrader-automate
_gmma = Indicators.GetIndicator<GMMA>();
}
protected override void OnBar()
{
Print(_gmma.LongEma1.Last(1)," ",_gmma.LongEma4.Last(1)); // <--- prints NaN NaN
if (_gmma.LongEma1.IsRising() && _gmma.LongEma4.IsRising()) {
ExecuteMarketOrder(TradeType.Buy, Symbol.Name, 100, "GMMA", null, null);
}
if (_gmma.LongEma1.IsFalling() && _gmma.LongEma4.IsFalling()) {
ExecuteMarketOrder(TradeType.Sell, Symbol.Name, 100, "GMMA", null, null);
}
}
protected override void OnStop()
{
// Handle cBot stop here
}
}
}
This happens because you only assign values to indicator data series, when the index of each higher timeframe changes. Hence for the rest of the array elements the value stays NaN. The solution to this depends on what you want to achieve. For example, why do you
Thank you for your reply. I want to test my GMMA strategy with multi-timeframe.
My cBot staretegy is 1hour resolution and should be able to access to the above custom indicator(multi-timeframe GMMA)'s TimeFrame.Hour4 Last(n) values.
Can you me an example on how to code this correctly?
Hi there,
I am sorry but I cannot write the code for you. If you have specific questions, I am happy to answer them. At the moment I do not see a reason to leave the data series values to NaN.
Best regards,
Panagiotis
Hello Panagiotis,
What do you mean by “At the moment I do not see a reason to leave the data series values to NaN.” ?
This happens because you only assign values to indicator data series, when the index of each higher timeframe changes. Hence for the rest of the array elements the value stays NaN. The solution to this depends on what you want to achieve. For example, why do you
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.Robots
{
[Robot(AccessRights = AccessRights.None)]
public class NewcBot15 : Robot
{
[Parameter(DefaultValue = "Hello world!")]
public string Message { get; set; }
protected override void OnStart()
{
// To learn more about cTrader Automate visit our Help Center:
// https://help.ctrader.com/ctrader-automate
Print(Message);
}
protected override void OnTick()
{
// Handle price updates here
Print((MarketData.GetBars(TimeFrame.Minute, "HONG KONG 50").MedianPrices.LastValue));
}
ys2310
14 Mar 2023, 14:47
( Updated at: 14 Mar 2023, 14:51 )
RE:
I could include Microsoft.ML.OnnxRuntime by compiling it from source code and made it a .Net6.0 dll.
But I get a run-time error "13/02/2023 09:00:00.000 | CBot instance [test, XAUUSD, h1] crashed with error "Crashed in OnStart with OnnxRuntimeException: [ErrorCode:Fail] Load model from C:/cTrader/svm_test.onnx failed:D:\a\_work\1\s\engine\lotus\onnxruntime\core/graph/model_load_utils.h:57 onnxruntime::model_load_utils::ValidateOpsetForDomain ONNX Runtime only *guarantees* support for models stamped with official released onnx opset versions. Opset 16 is under development and support for this is limited. The operator schemas and or other functionality may change before next ONNX release and in this case ONNX Runtime will not guarantee backward compatibility. Current official support for domain ai.onnx is till opset 15.
"".
ys2310
02 Oct 2024, 05:33
RE: OnBar() not fired at specified interval
PanagiotisCharalampous said:
Hello Panagiotis,
Thank you for your reply. I'm clear now.
What if I want to every 5 minutes event?
@ys2310