Topics
Replies
firemyst
04 Oct 2019, 10:23
RE:
andrea.franchi96 said:
I advice for an advanced stop loss with more levels than one similiar to advanced take profit. For example something like this: at 50 pips gain shifts stop at breakeven, then, the second level, at 150 pips gain shifts stop to 50 pips, and so on. So, multiple levels for advanced stop loss that works differently from trailing stop.
While this isn't in cTrader itself, it's easily programmable in a bot.
Do you need help with that?
@firemyst
firemyst
03 Oct 2019, 04:11
( Updated at: 21 Dec 2023, 09:21 )
RE:
Panagiotis Charalampous said:
Hi jalmir.coelho@gmail.com,
cBots are built without source code by default. See image below
Therefore if you distribute your .calgo file and you have not use "Build with Source Code" option, then the code will not be available.
Best Regards,
Panagiotis
HI @Panagiotis:
Just for confirmation, is this true when using Visual Studio as well?
That is:
- if I always build an indicator in Visual Studio and not cTrader, by default it will be built without the source code?
- if I want to include the source code in a build while using Visual Studio, I have to come back to cTrader and select the "Build with Source code" option?
Thank you.
@firemyst
firemyst
26 Sep 2019, 03:57
RE:
Panagiotis Charalampous said:
Hi micderaj,
Seems like a non repainting to me.
Best Regards,
Panagiotis
@Panagiotis: can you clarify a bit more why you think it's non-repainting?
Since the "Source" is a parameter, this indicator may or may not repaint depending on whether the source is the "Open" price, "Close" price, or something else.
If it's "Open", the indicator won't repaint as the data won't change until the open of the next bar; if any of the sources are something other than "Open", then the indicator will repaint because the current bar is constantly updating the Low, High and Close values with new values.
It might not be updating all past values, but it will constantly be updating current values.
To me, that is repainting.
@firemyst
firemyst
22 Sep 2019, 16:06
RE:
alex_mihail said:
I understand MT4 is based in NY and there are some great <1ms options latency options for there but what about cTrader which is LD4/5 based? What is the best low latency VPS solution?
I use NYC Servers and have had no issues with them.
Speed has been great.
They also have discounted VPS plans with some brokers (Pepperstone is one). The discounts can be 20-25% off depending on the VPS plan you sign up for.
@firemyst
firemyst
22 Sep 2019, 15:55
RE:
eliezer_barros said:
I wish only one open position in this hour and again next day, in the same hour, even that I am using the frame different of hours, for example 15 min, or 30 min.
I appreciate this help
Tks
//Only enter at specified time if (Server.Time.Hour == ServerHourToPlaceOrderParameter) { ///place your order }
@firemyst
firemyst
22 Sep 2019, 15:53
RE:
ryanoia@gmail.com said:
Hello,
Is there any way to prevent the cbot from executing market orders if the resulting margin level due to the opening of the said position results in a less than x % margin level, where x is a user-defined parameter?
Thanks for the assistance, if any.
You can easily check the margin levels before entering a position.
Code sample below:
if (Account.MarginLevel.HasValue && Account.MarginLevel >= minimumMarginLevelsToEnterPositions) { //place your orders here }
Otherwise, the only way I know of is immediately after executing your order successfully, check the margin levels and if it's below the threshold, close the position.
Example:
TradeResult r = ExecuteMarketOrder( .... ); if (r.IsSuccessful && Account.MarginLevel < minimumMarginLevelParameter) { //close the position and anything else you want to do }
@firemyst
firemyst
22 Sep 2019, 15:47
RE:
psz5mc@gmail.com said:
Hi
I need a method or something in API to be possible restarting a robot itself. Not when cTrader restart and only that robot can restart who initiated. When a robot decide to want a fresh start, call a RestartRobot() method that initiate the stop sequence and then cTrader start again the caller robot with the same parameters, etc.
Additionally for security reasons may need (or not) the FullAccess permission.
Thanks
SpotWare may be working on an API to allow one bot control another bot.
It's a wait and see game.
@Panagiotis may be able to elaborate further if they are.
@firemyst
firemyst
22 Sep 2019, 15:42
RE:
trader.calgo said:
Many entities, such as sockets, require execution closing methods, but indicators do not have OnStop(); It is very important to add this logic.
Have you tried surrounding your socket code with the C# using statement?
For example:
using (var socket = new Socket(/*...*/)) { // operations socket.Shutdown(SocketShutdown.Both); socket.Close(); }
The above code is expanded into the following by the compiler at compile time:
{ Socket socket = new Socket(/*...*/); try { // operations socket.Shutdown(SocketShutdown.Both); socket.Close(); } finally { if (socket != null) ((IDisposable)socket).Dispose(); } }
It will suck with each call to the calculate method as you'll have to open/close the socket each time, but at least it gives you a temporary work around if you need it.
Past values of the indicator won't be too bad; it's the latest calculate index that'll cause the problem. So other options are:
1) only open the socket if the parameter "index" for calculate has changed from the previous value
2) if you need the socket open more frequently for the current index, only open it every 5, 8, 13, or whatever calls to calculate on the current index. For example:
calculate (int index) { //_calculateCount is a global variable if ( _calculateCount % 5 == 0) { using (Socket s = new Socket....) {} } _calculateCount += 1; }
@firemyst
firemyst
22 Sep 2019, 15:27
( Updated at: 21 Dec 2023, 09:21 )
RE:
1goodtrade said:
Hi, can anyone help me to plot a Simple Moving Average on Volume in cTrader (Desktop 3.5) please?
Below is a screen shot from another charting service demonstrating what I am trying to achieve within cTrader preferably.
The volume histagram has a 20 period (variable) SMA plotted in orange - can this be done in cTrader and within the price panel (rather than a separate panel)?
Thanks to anyone that can offer some help :) Scotty.
It can be done quite easily in a display area below the main chart panel.
@firemyst
firemyst
18 Sep 2019, 17:09
RE:
tomopeov said:
2- Is it possible to close all open trades and orders once the price reaches a certain point?Thanks
This one is relatively simple to write pseudo-code (which may work) in a quick few minutes. In your OnTick method, do something similar to:
double closeThreshold = 1.02; //or whatever your price threshold is where you want to close everything if (Symbol.Ask <= closeThreshold) { CloseEverything(Symbol.Name); }
Here's the supporting function:
private void CloseEverything(string theSymbol) { foreach (Position p in Positions.FindAll(theSymbol)) //oryou could specify the "label" if you'll be labelling all your positions the same way { TradeResult r = p.Close(); if (r.IsSuccessful) { Print("Successfully closed position \"{0} {1}\" to true.", p.Id, p.Label); } else if (!r.IsSuccessful) { Print("WARNING! Could not close position \"{0} {1}\"!", p.Id, p.Label); Print("Error message: {0}", r.Error.Value); } } }
@firemyst
firemyst
10 Sep 2019, 03:38
RE:
Panagiotis Charalampous said:
Hi FireMyst,
The charts are displaying different values because you are using the wrong index. Replace line 41 to the below
Result[index] = _averageTrueRange.Result[_marketSeries.OpenTime.GetIndexByTime(MarketSeries.OpenTime[index])];Best Regards,
Panagiotis
That's awesome.
Thank you so much @Panagiotis! :-)
@firemyst
firemyst
06 Sep 2019, 16:13
RE:
alexsanramon said:
I see that you have discovered the flaw in ctrader resource management design. Thanks for the tip. Although it would only work if you know the source code of all the indicators you are going to use. The problem is most indicators by ctrader are closed.
They are closed yes. But as I said, you can easily look up their formulas.
For example, I gave you the Momentum one above.
The Keltner Channel can be calculated with the defaults as follows:
Middle Line: 20-day exponential moving average
Upper Channel Line: 20-day EMA + (2 x ATR(10))
Lower Channel Line: 20-day EMA - (2 x ATR(10))
Bollinger Bands are similar:
Middle Band = 20-day simple moving average (SMA)
Upper Band = 20-day SMA + (20-day standard deviation of price x 2)
Lower Band = 20-day SMA – (20-day standard deviation of price x 2)
Bollinger Bandwidth:
(Upper Bollinger Band - Lower Bollinger Band) / Middle Bollinger Band
Simple Moving Average:
(Price1 + Price 2 + ... + Price N) / N
etc etc.
@firemyst
firemyst
05 Sep 2019, 11:27
RE:
alexsanramon said:
If I understand you correctly, what you are saying is: instead of using GetIndicator<>, you place the calculation in the cbot code?
Exactly. Any you get from https://ctrader.com/algos/indicators
that includes the code you can put in your bot almost directly (depends on how you have your bot coded of course).
Even some that come with cTrader you can eliminate the GetIndicator<> call because the calculations are simple.
For example, the Momentum Indicator. It's calculation is just:
Momentum[index] = MarketSeries.Close[index] - MarketSeries.Close[index - Momentum_Period];
which you can easily insert into your bot code by creating your own array with however many bars back your bot will need to look. For instance, if all your bot does it look at the current value, and previous bar value, then you just need two values at any one time at most. So:
double[] Momentum = new double[] { 0, 0 }; //initialize
where Momentum[0] is the latest value (replicates "indicator.Result.Last(0)") and Momentum[1] is from 1 bar ago (replicates "indicator.Result.Last(1)").
Your single Momentum array will take up significantly less memory, never expand because it won't store more than 2 values, and will ultra fast for the CPU to deal with as opposed to the Momentum IndicatorDataSeries object which has a bigger memory footprint, is always growing with each OnBar, and takes more processing time for the CPU.
:-)
@firemyst
firemyst
03 Sep 2019, 08:37
RE:
Panagiotis Charalampous said:
Hi all,
We are aware of the issue and we will fix it the soonest.
Best Regards,
Panagiotis
Given that this has happened at least twice in the last few years according to dates on this thread alone:
1) does SpotWare have any automated testing systems in place? The "OnBar" method is a critical piece of event code unlike some obscure API call that's rarely used. And now, because of this bug which is at least 8 days old, renders a lot of bots that depend on it utterly useless.
2) does SpotWare plan to implement any sort of "critical bug contact list" that people can sign up to? 8+ days is a loooooooooong time to have such a critical issue unresolved, and developers/users of bots that depend on this piece of code should be notified instead of letting their now potentially hazardous code run without their knowing there's a critical bug. At the very least, that would be the socially responsible, "customer service", thing to do.
Thank you.
@firemyst
firemyst
02 Sep 2019, 08:44
Looks like this is an issue with cTrader.
Same issue was reported here which I didn't see earlier.
Sorry for the duplicate post:
https://ctrader.com/forum/calgo-support/3349
@firemyst
firemyst
02 Sep 2019, 08:43
Same issue happening to me.
Posted here:
https://ctrader.com/forum/calgo-support/21850
@firemyst
firemyst
27 Aug 2019, 14:27
@srubtsov, @Panagiotis:
Yes,after rereading everything, you both are right. My apologies.
Fair question though -- is it good behaviour for cTrader to ignore a SL when it falls within a spread and not even give a warning or something? Otherwise, unless there's specific checks for a stoploss after placing an order with a stoploss, the bots would never know.
Or is the behaviour srubtsov mentioned going to be released in a future version?
Thank you.
@firemyst
firemyst
27 Aug 2019, 08:59
RE: RE: RE:
srubtsov said:
FireMyst said:
I'll do you one better. Here's the source code needed to reproduce this issue. Details on what to do are in the comments.
Screen capture below too from Visual Studio showing the the breakpoints, and that it goes into the code block that the position's stoploss is zero immediately after fulfilling the order with a 1.2 pip SL.
What's happening to cause this?
Thank you.
In that case in backtesting problem is stop loss pips is less than spread. Spread is 1.6, StopLossPips is 1.2. Empty StopLoss for that is ok.
That is not so clear, currently in that case `TradeResult.IsSuccessful = true; TradeResult.ErrorCode = null`. In future versions it will be more clear, `ErrorCode` won't be null.
It doesn't matter what the spread is -- when a stop loss is set it should be set. Spread size has nothing to do with it. The spread is the difference between the bid/ask prices; a SL for a buy order is measured from below the BID; a SL for a sell order is measured from above the Ask.
Also, as with the original post, this same situation occurred when I had a stoploss of 10.4 pips.
There's a bug with cTrader and/or the server, and it needs to be fixed.
@firemyst
firemyst
04 Oct 2019, 10:51
Awesome!
Thank you for the confirmation @Panagiotis!
@firemyst