
Topics
Replies
PanagiotisCharalampous
13 Feb 2018, 10:15
Hi dordkash@gmail.com,
Can you share your cBot code? Also please provide some more information on what the cBot is supposed to do.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
13 Feb 2018, 10:02
Hi swingfish,
Did you try it and noticed any performance issues? What you describe is a simple loop therefore not much things can be done from an algorithmic perspective. I would advise you to use ModifyPositionAsync to modify your TP and SL to improve the speed of execution of your bulk changes.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
13 Feb 2018, 09:51
Hi boutainachakir13,
Try to perform a clean installation and let me know if this resolves the problem.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
13 Feb 2018, 09:47
Hi tmc.
We have added this issue to the backlog to be addressed.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
13 Feb 2018, 09:33
Hi waisuklondon@gmail.com,
Thanks for posting in our forum. What do you mean to convert an indicator to a cBot? Do you mean to access the indicator through a cBot, read its values and trade based on them?
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
12 Feb 2018, 12:10
Hi juangmez87,
Stop Limit Order is currently not available in cAlgo.API. It will be added in a future release.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
12 Feb 2018, 11:49
Hi itmfar,
I was with the impression that you wanted to place orders only on the D sign, Here it is for S sign as well
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; using System.Collections.Generic; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class NewcBot : Robot { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } [Parameter("MA Type", DefaultValue = MovingAverageType.Simple)] public MovingAverageType maType { get; set; } private StochasticOscillator _stochastic; private readonly List<bool> _ssdRising = new List<bool>(); [Parameter("Source")] public DataSeries Source { get; set; } protected override void OnStart() { _stochastic = Indicators.StochasticOscillator(9, 3, 9, maType); } protected override void OnBar() { _ssdRising.Add(_stochastic.PercentD.IsRising()); if (_ssdRising.Count > 1) { FindSSCrossovers(Source.Count - 1); DrawLinesSSD(Source.Count - 1); } } private void FindSSCrossovers(int index) { if (_stochastic.PercentD.HasCrossedAbove(_stochastic.PercentK, 0)) { ChartObjects.DrawText("MAXss1" + index, "S⮟", index, Source[index], VerticalAlignment.Top, HorizontalAlignment.Center, Colors.Yellow); ExecuteMarketOrder(TradeType.Sell, Symbol, 1000, "lalbelmax", 120, 200); } else { ChartObjects.RemoveObject("MAXss1" + index); } if (_stochastic.PercentK.HasCrossedAbove(_stochastic.PercentD, 0)) { ChartObjects.DrawText("Minss1" + index, "S⮝", index, Source[index], VerticalAlignment.Bottom, HorizontalAlignment.Center, Colors.Yellow); ExecuteMarketOrder(TradeType.Buy, Symbol, 1000, "lalbelmax", 120, 200); } else { ChartObjects.RemoveObject("Minss1" + index); } } private void DrawLinesSSD(int index) { if (_ssdRising[_ssdRising.Count - 2] != _ssdRising[_ssdRising.Count - 1] && _stochastic.PercentD[index] > 60 && _ssdRising[_ssdRising.Count - 1] == false) { ChartObjects.DrawText("maxrssd" + index, "D⮟", index, Source[index], VerticalAlignment.Top, HorizontalAlignment.Center, Colors.White); ExecuteMarketOrder(TradeType.Sell, Symbol, 1000, "lalbelmax", 120, 200); } else { ChartObjects.RemoveObject("maxrssd" + index); } if (_ssdRising[_ssdRising.Count - 2] != _ssdRising[_ssdRising.Count - 1] && _stochastic.PercentD[index] < 40 && _ssdRising[_ssdRising.Count - 1] == true) { ChartObjects.DrawText("minrssd" + index, "D⮝", index, Source[index], VerticalAlignment.Bottom, HorizontalAlignment.Center, Colors.White); ExecuteMarketOrder(TradeType.Buy, Symbol, 1000, "lalbelmax", 120, 200); } else { ChartObjects.RemoveObject("minrssd" + index); } } protected override void OnStop() { // Put your deinitialization logic here } } }
Let me know if this works.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
12 Feb 2018, 11:35
Hi irmscher9,
Why do you say that the code is not working? Do you get an exception? Do you get unexpected results? If you give us more information, it will be easier for us to help you.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
12 Feb 2018, 11:22
Hi thegreat.super,
You can find an explanation for this kind of exceptions here. The problem probably occurs because you are checking lastposition without checking if it is null first. See below
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class ashi : Robot { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } [Parameter("ProfitTarget", DefaultValue = 300)] public double ProfitTarget { get; set; } [Parameter("Volume", DefaultValue = 10000)] public int Volume { get; set; } public double balance; public double lastTradePrice; public TradeResult lastposition; protected override void OnStart() { // Get the initial balance balance = Account.Balance; Print(balance); // Start hedge grid lastposition = ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "buy", 0, 2); ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "buy", 0, 2); } protected override void OnTick() { // Open more trades if the price moved 5 pips if (lastposition != null && lastposition.Position.Pips > 5) { lastposition = ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "buy", 0, 2); } if (lastposition != null && lastposition.Position.Pips < -5) { lastposition = ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "sell", 0, 2); } // Check if equity is in profit then shut down the grid cycle if (Account.Equity >= balance + 2) { foreach (var position in Positions) { ClosePosition(position); } balance = Account.Balance; Print(balance); // Start hedge grid ExecuteMarketOrder(TradeType.Buy, Symbol, 1000, "buy", 0, 2); ExecuteMarketOrder(TradeType.Sell, Symbol, 1000, "sell", 0, 2); } } protected override void OnStop() { // Put your deinitialization logic here } } }
Let me know if the above resolves the problem.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
12 Feb 2018, 11:12
Hi dordkash@gmail.com,
Let me know if this works for you
if (Symbol.Bid - MarketSeries.High.LastValue > Symbol.PipSize) { // Do something }
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
12 Feb 2018, 10:51
Hi tradingu,
Currently our servers are located in LD5. Therefore you should preferably look for a VPS provider located in LD5.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
09 Feb 2018, 17:04
Hi tmc.
It is going to take some time to fix this issue due to some architectural changes that need to take place. The issue has to do with the fact that TP and SL messages are sent slightly after the position is opened resulting to the arguments not having this information. However if you can wait for a little you can TP and SL are updated and you can read the information. See my code sample below
using System; using cAlgo.API; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class SampleOnPositionOpenedBug : Robot { private readonly Action[] _actions = new Action[6]; private int _index; protected override void OnStart() { Positions.Opened += Positions_Opened; _actions[0] = () => PlaceStopOrderAsync(TradeType.Buy, Symbol, 1000, Symbol.Ask, "label", 5, 5, null, "Stop Order Async"); _actions[1] = () => PlaceLimitOrderAsync(TradeType.Buy, Symbol, 1000, Symbol.Bid, "label", 5, 5, null, "Limit Order Async"); _actions[2] = () => ExecuteMarketOrderAsync(TradeType.Buy, Symbol, 1000, "label", 5, 5, null, "Market Order Async"); _actions[3] = () => PlaceStopOrder(TradeType.Buy, Symbol, 1000, Symbol.Ask, "label", 5, 5, null, "Stop Order"); _actions[4] = () => PlaceLimitOrder(TradeType.Buy, Symbol, 1000, Symbol.Bid, "label", 5, 5, null, "Limit Order"); _actions[5] = () => ExecuteMarketOrder(TradeType.Buy, Symbol, 1000, "label", 5, 5, null, "Market Order"); Timer.Start(2); } protected override void OnTick() { foreach (var position in Positions) { Print("{0} (TP: {1} SL: {2})", position.Comment, position.TakeProfit, position.StopLoss); } } protected override void OnTimer() { if (_index >= _actions.Length) { Stop(); } _actions[_index](); _index++; } private void Positions_Opened(PositionOpenedEventArgs e) { if (e.Position.Label == "label") { Print("{0} filled (TP: {1} SL: {2})", e.Position.Comment, e.Position.TakeProfit, e.Position.StopLoss); } } } }
Could we work on a workaround based on the above?
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
09 Feb 2018, 14:34
Hi itmfar,
See below
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; using System.Collections.Generic; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class NewcBot : Robot { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } [Parameter("MA Type", DefaultValue = MovingAverageType.Simple)] public MovingAverageType maType { get; set; } private StochasticOscillator _stochastic; private readonly List<bool> _ssdRising = new List<bool>(); [Parameter("Source")] public DataSeries Source { get; set; } protected override void OnStart() { _stochastic = Indicators.StochasticOscillator(9, 3, 9, maType); } protected override void OnBar() { _ssdRising.Add(_stochastic.PercentD.IsRising()); if (_ssdRising.Count > 1) { FindSSCrossovers(Source.Count - 1); DrawLinesSSD(Source.Count - 1); } } private void FindSSCrossovers(int index) { if (_stochastic.PercentD.HasCrossedAbove(_stochastic.PercentK, 0)) { ChartObjects.DrawText("MAXss1" + index, "S⮟", index, Source[index], VerticalAlignment.Top, HorizontalAlignment.Center, Colors.Yellow); } else { ChartObjects.RemoveObject("MAXss1" + index); } if (_stochastic.PercentK.HasCrossedAbove(_stochastic.PercentD, 0)) { ChartObjects.DrawText("Minss1" + index, "S⮝", index, Source[index], VerticalAlignment.Bottom, HorizontalAlignment.Center, Colors.Yellow); } else { ChartObjects.RemoveObject("Minss1" + index); } } private void DrawLinesSSD(int index) { if (_ssdRising[_ssdRising.Count - 2] != _ssdRising[_ssdRising.Count - 1] && _stochastic.PercentD[index] > 60 && _ssdRising[_ssdRising.Count - 1] == false) { ChartObjects.DrawText("maxrssd" + index, "D⮟", index, Source[index], VerticalAlignment.Top, HorizontalAlignment.Center, Colors.White); ExecuteMarketOrder(TradeType.Sell, Symbol, 1000, "lalbelmax", 120, 200); } else { ChartObjects.RemoveObject("maxrssd" + index); } if (_ssdRising[_ssdRising.Count - 2] != _ssdRising[_ssdRising.Count - 1] && _stochastic.PercentD[index] < 40 && _ssdRising[_ssdRising.Count - 1] == true) { ChartObjects.DrawText("minrssd" + index, "D⮝", index, Source[index], VerticalAlignment.Bottom, HorizontalAlignment.Center, Colors.White); ExecuteMarketOrder(TradeType.Buy, Symbol, 1000, "lalbelmax", 120, 200); } else { ChartObjects.RemoveObject("minrssd" + index); } } protected override void OnStop() { // Put your deinitialization logic here } } }
Let me know if this is working for you,
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
09 Feb 2018, 11:41
Hi megna,
See below an example of an Order Mass Status Request
8=FIX.4.4|9=117|35=AF|34=3|49=theBroker.12345|52=20170404-07:20:55.325|56=CSERVER|57=TRADE|225=20170404-07:20:44.582|584=mZzEY|585=7|10=065|
Let me know if this is what you are looking for
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
09 Feb 2018, 09:55
Hi jetza,
Currently there is no such feature in cTrader. You can post it as a Suggestion so that it can be considered by the product team.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
08 Feb 2018, 16:58
Hi thegreat.super,
I understand that. But the code you posted, closes all of them. Did you try to run it on cTrader and it did not close all positions? Did you just backtest it? I am just trying to understand how you reached to the conclusion that it is not working.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
08 Feb 2018, 16:45
Hi itmfar,
I don't know what to suggest since I cannot reproduce the problem and understand what is going wrong. Could you share a short video demonstrating the problem? Also, I don't understand how you will solve the problem by calling Calculate on a more frequent basis. Calculate is called on every tick therefore frequently enough. Do you mean redrawing the entire indicator instead? Even if this is what you are looking for, it is not a proper solution. It would be easier to understand how the issue is caused and apply a proper solution instead of forcing a brute force redrawing of the indicator.
Best Regards
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
08 Feb 2018, 12:39
Hi gallderhen,
Thanks for posting in our forum. Unfortunately it is not possible to change the Symbol of an Indicator. It is always the Symbol of the chart to which the indicator is attached to.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
08 Feb 2018, 11:20
Hi thegreat.super,
From what i see
foreach (var position in Positions) { ClosePosition(position); }
closes all positions.
Why do you say that it closes only profitable ones?
Best Regards
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
13 Feb 2018, 10:30
Hi Alexander,
Can I have your exact backtesting configuration (broker, timeframe, start and end dates, cbot parameters, starting volume etc) so that I can reproduce and see if I can advise you on this?
Best Regards,
Panagiotis
@PanagiotisCharalampous