BUG IN POSITION.PIPS OF CTRADER AUTOMATE!!!!!!!!!!!!!
BUG IN POSITION.PIPS OF CTRADER AUTOMATE!!!!!!!!!!!!!
19 Jul 2019, 10:48
I would like to report a bug and request for immediate resolution. I have this code for my cbot:
if ((Positions.Find("wave 0", SymbolName, TradeType.Buy) == null) && (Symbol.Spread / Symbol.PipSize < LimitRange)) { foreach (var position in Positions) { if ((position.Pips * -1 <= LimitRange * 2) && (position.SymbolName == Symbol.Name) && (position.TradeType == TradeType.Sell)) { ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "wave 0", StopLossInPips, TakeProfitInPips, LimitRange); Notifications.SendEmail(senderemailaddress, "recipientemailaddress, SymbolName, " Buy Side Refresh One Side " + " Negative Pips Converted to Positive = " + position.Pips * -1 + " Limit Range * 2 = " + LimitRange * 2) } } }
The logic of it is, if there is a sell position and there are no buy positions, and the sell position is at -6 pips or higher (-5, -4, etc.), the cbot will open a buy position. I activate this bot when the sell position is at -20 pips or lower.
In backtesting there are no issues, it works as coded and intended. However, when I forward tested this, things started to go crazy. It opened buy positions even when the sell position was lower than -6 pips e.g. at -30 pips, -40, -80, -100!
To debug, as you can see in the code, I instructed the bot to send me an e-mail, which is linked to my telegram account, informing me of the value of the variables such as the position.pips, etc. I have now found out the cause of the problem. It appears to me that the cbot is reading the position.pips as 0 even though in reality, it should be -30 pips or some other number that should not be 0.
To illustrate, please see images below serving as proof.
At 2:52am EDT, I received a telegram message showing the following:
Following the source code formula, “Negative Pips Converted to Positive” is calculated as “position.pips * -1.” So following this message, when I look at my trading platform, NZDUSD sell position should be 0 pips right? Instead, this is what I saw:
As you can see, the sell position was at -37.6 pips, which is way lower than -6 pips, and following the condition in my cbot, the buy position should not have opened. Looking at the m15 chart, price was nowhere near the sell position so it is impossible to be at 0 pips awhile ago. My question is, why then did the cbot disregard the condition and opened a buy position? My guess is, it did not violate the condition, rather position.pips was read as 0 instead of -37.6 pips, leading the bot to think that it was higher than -6 pips (0 is higher than -6 pips) and thus, open the buy position.
My question is, why did ctrader read the position.pips as 0 instead of -37.6 pips? Is that a bug? I don’t think it’s an issue with my cbot especially considering that it ran perfectly during the backtesting.
This is a big bug/glitch, if ever, as a lot of cbots, including mine, depend on the accurate reading of the position.pips I presume.
—
By the way, during forward testing, ctrader read position.pips accurately at times, like these ones:
Other times, it reads position.pips incorrectly, like these times:
I would like to have this issue resolved as soon as possible please.
Thanks.
Replies
ryanoia@gmail.com
19 Jul 2019, 11:14
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; using System.Collections; using System.IO; namespace cAlgo.Robots { [Robot(TimeZone = TimeZones.EasternStandardTime, AccessRights = AccessRights.FullAccess)] public class Velocity : Robot { [Parameter("Volume", DefaultValue = 1000)] public int Volume { get; set; } [Parameter("Limit Range", DefaultValue = 3)] public double LimitRange { get; set; } [Parameter("Take Profit In Pips", DefaultValue = 20)] public double TakeProfitInPips { get; set; } [Parameter("Stop Loss In Pips", DefaultValue = 100)] public double StopLossInPips { get; set; } [Parameter("Email Message", DefaultValue = "Message")] public string EmailMessage { get; set; } [Parameter("Sender Email Address", DefaultValue = "sender@gmail.com")] public string SenderEmailAddress { get; set; } [Parameter("Recipient Email Address", DefaultValue = "recipient@gmail.com")] public string RecipientEmailAddress { get; set; } protected override void OnStart() { } protected override void OnBar() { } protected override void OnTick() { if ((Positions.Find("Wave 0", SymbolName, TradeType.Buy) == null) && (Positions.Find("Wave 0", SymbolName, TradeType.Sell) == null) && (Symbol.Spread / Symbol.PipSize < LimitRange) && (Server.Time.Hour != 4) && (Server.Time.Hour != 5) && (Server.Time.Hour != 6)) { ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "Wave 0", StopLossInPips, TakeProfitInPips, LimitRange); ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "Wave 0", StopLossInPips, TakeProfitInPips, LimitRange); Notifications.SendEmail(SenderEmailAddress, RecipientEmailAddress, SymbolName, EmailMessage); } //refresh buy side if ((Positions.Find("Wave 0", SymbolName, TradeType.Buy) == null) && (Symbol.Spread / Symbol.PipSize < LimitRange)) { foreach (var position in Positions) { if ((position.Pips * -1 <= LimitRange * 2) && (position.SymbolName == Symbol.Name) && (position.TradeType == TradeType.Sell)) { Notifications.SendEmail(SenderEmailAddress, RecipientEmailAddress, SymbolName, "Buy Side Refresh One Side " + " Negative Pips Converted to Positive = " + position.Pips * -1 + " Limit Range * 2 = " + LimitRange * 2); ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "Wave 0", StopLossInPips, TakeProfitInPips, LimitRange); } } } //end of refresh buy side //refresh sell side if ((Positions.Find("Wave 0", SymbolName, TradeType.Sell) == null) && (Symbol.Spread / Symbol.PipSize < LimitRange)) { foreach (var position in Positions) { if ((position.Pips * -1 <= LimitRange * 2) && (position.SymbolName == Symbol.Name) && (position.TradeType == TradeType.Buy)) { Notifications.SendEmail(SenderEmailAddress, RecipientEmailAddress, SymbolName, "Sell Side Refresh One Side " + " Negative Pips Converted to Positive = " + position.Pips * -1 + " Limit Range * 2 = " + LimitRange * 2); ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "Wave 0", StopLossInPips, TakeProfitInPips, LimitRange); } } } //end of refresh sell side } }
@ryanoia@gmail.com
ryanoia@gmail.com
19 Jul 2019, 11:32
( Updated at: 21 Dec 2023, 09:21 )
Received a telegram message just 7 minutes ago:
GBPCHF Buy not even close to 0 pips or higher than -6 pips:
Feel free to look at GBPCHF now.
@ryanoia@gmail.com
PanagiotisCharalampous
29 Jul 2019, 09:26
Hi ryanoia@gmail.com,
I ran the cBot for several days but could not reprodce this behavior. Can you isolate the problem in a cBot that prints the value in the log instead of sending it to Telegram and post it alongside with some screenshots of the log?
Best Regards,
Panagiotis
@PanagiotisCharalampous
ryanoia@gmail.com
31 Jul 2019, 16:17
I can, but can't do this right away. In the meantime, I was able to implement a workaround by adding a condition whereby if position.pips == 0, do not execute.
@ryanoia@gmail.com
PanagiotisCharalampous
19 Jul 2019, 10:56
Hi ryanoia@gmail.com,
Can you please post the complete cBot code?
Best Regards,
Panagiotis
@PanagiotisCharalampous