Topics
Replies
firemyst
30 Sep 2020, 10:34
RE:
PanagiotisCharalampous said:
Hi firemyst,
Not it hasn't. At the moment you set the commissions yourself, through the backtesting settings.
Best Regards,
Panagiotis
I'm looking for a way to estimate commissions in indicators and bots _before_ a position is opened while a bot or indicator is running. I can hard-code a fixed figure, but obviously that wouldn't be accurate. This isn't for any sort of back-testing.
Any "creative ways" to figure that out? :-)
@firemyst
firemyst
29 Sep 2020, 08:43
RE:
Spotware said:
You can not retrieve such information at the moment. At some point we will add Commissions to the Symbol object.
Please vote for your favorite features: http://vote.spotware.com/forums/229166-ideas-and-suggestions-for-ctrader-and-calgo/category/76800-calgo
@Panagiotis / @Spotware:
Has this feature been implemented yet?
I don't see any kind of "commission" property yet directly available from the "Symbol" object.
Thank you.
@firemyst
firemyst
28 Sep 2020, 08:52
( Updated at: 21 Dec 2023, 09:22 )
RE:
Hi @Panagiotis:
Thank you for the "inventive" solution!
It does lead to, however, an issue I've pointed out earlier with the short-comings of cTrader which I think your team at @Spotware really needs to consider implementing.
Look at the screen capture. What do you think is more "user friendly" and that users would appreciate more?
Having the configurations displayed as they are under the "Lines" section (2) ? Or having to create separate parameters for the color and styles without any sort of previews (1)?
Options #2 is definitely more "user friendly" and I think @Spotware seriously needs to consider allowing through the API the ability to access the color, style, size properties of "lines".
In this case, I would want to create an indicator data series (that holds nothing and just set to null) so I can allow users to select the color/style/size options nicely. Then in the API read those settings, and apply those to the chart icons drawn.
Thank you again though for the sample code solution.
@firemyst
firemyst
25 Sep 2020, 13:40
RE:
Hi @Panagiotis:
Your code works for drawings, but how do you get it to work for indicators?
Example. Take the code below. Insert it on an H1 chart and set the timeframe of the indicator to be M5. I'd expect to see 12 psar dots in the space of one bar (60 / 5 = 12).
I can't get it to work because of the Result[index] that's needed; I've tried doing it with Result[altIndex] to no avail.
using System;
using System.Collections.Generic;
using cAlgo.API;
using cAlgo.API.Indicators;
namespace cAlgo.Indicators
{
[Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
public class Test : Indicator
{
[Parameter()]
public TimeFrame SourceTimeFrame { get; set; }
[Parameter("Min AF", DefaultValue = 0.02)]
public double MinAF { get; set; }
[Parameter("Max AF", DefaultValue = 0.2)]
public double MaxAF { get; set; }
[Output("Main", PlotType = PlotType.Points, LineStyle = LineStyle.Dots, LineColor = "White", Thickness = 2)]
public IndicatorDataSeries Result { get; set; }
private Bars _marketSeries;
private ParabolicSAR _psar;
int previousAltIndex = 0;
protected override void Initialize()
{
if (SourceTimeFrame != null)
_marketSeries = MarketData.GetBars(SourceTimeFrame, Symbol.Name);
else
_marketSeries = MarketData.GetBars(Bars.TimeFrame, Symbol.Name);
_psar = Indicators.ParabolicSAR(_marketSeries, MinAF, MaxAF);
}
public override void Calculate(int index)
{
int altIndex = index;
if (Bars.TimeFrame != _marketSeries.TimeFrame)
{
altIndex = _marketSeries.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
}
Result[index] = _psar.Result[altIndex];
//if (Bars.TimeFrame != _marketSeries.TimeFrame)
//{
// altIndex = _marketSeries.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
// for (int i = previousAltIndex; i < altIndex; i++)
// {
// Chart.DrawVerticalLine(_marketSeries.OpenTimes[i].ToString(), _marketSeries.OpenTimes[i], Color.Red);
// }
// altIndex = previousAltIndex;
//}
// blah blah blah
}
}
}
@firemyst
firemyst
25 Sep 2020, 11:14
RE:
PanagiotisCharalampous said:
Hi firemyst,
OnCalculate method is called once per bar when the indicator is calculated for past values. Having that in mind, if you want your indicator to display values from lower timeframes, you need to write the corresponding logic that will take this into consideration. Here is a starting point, an indicator drawing vertical lines on lower tiimeframe open times
Note that for current values, OnCalculate() is called on every tick, in case you need to take that into consideration.
Best Regards,
Panagiotis
Thanks for the code sample, but I don't believe it works.
It's because of this line:
altIndex = _marketSeries.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
Here's why.
I'm on a 15-minute chart.
Let's say "index" number "500" is at 08:00; the next time Calculate is called index will be "501", but the time will be "08:15".
So when calling "Bars.OpenTimes[index]", it will be either 500 or 501, which is 08:00 or 08:15 respectively. The 5 minute indicator also needs the open times of 08:05 and :08:10.
Because it doesn't get that, the M5 indicator will only display the value from index 500 or 08:00, missing all the subsequent values until index 501 at 08:15.
So how to get those intermediate values too?
Or am I completely missing something?
@firemyst
firemyst
25 Sep 2020, 10:28
RE:
PanagiotisCharalampous said:
Hi firemyst,
You will need to program your own methods to calculate those times.
Regarding
Does cTrader have the ability to plot 3 smaller time frame bar values in the space of 1 bar on a higher time frame?
I did not understand the question. You are trying to do something here but I do not understand what it is. Maybe it would be better to explain what are you trying to do instead discussing about a solution you thought would work.
Best Regards,
Panagiotis
I have a 15 minute chart, or a 1 hour chart, and I want to plot an indicator's values from the 5 minute timeframe on it.However, I can't find a way to plot those. For instance, all I can get it 1 M5 plot (instead of 3) for every M15 bar; or 1 M5 plot (instead of 12) for every H1 bar.
The only thing I can manage to do is pull up an M5 chart with just the one indicator I want the M5 value on, and then have to put the other indicators on the M5 chart and set them to either 15 minutes or 1 hour.
So I have an M15 chart:
* 1 indicator I want plotted against the M5 timeframe
* 5 indicators I want plotted on the M15 timeframe.
Best I can figure out is instead set the chart timeframe to M5 and:
* put the 1 M5 indicator on it
* 5 multi time frame indicators set to M15.
Does that make it more clear on what I'd like?
@firemyst
firemyst
20 Sep 2020, 17:52
RE: RE: RE:
defontein93 said:
firemyst said:
In your bot get the MACD based on the 1 hour time frame data instead of the 15 minute data.
Sample code off the top of my head:
var _macd = Indicators.MacdCrossOver(MarketData.GetBars(TimeFrame.Hour, Symbol.Name), MACDLongPeriod, MACDShortPeriod, MACDSignalPeriod);
You have to fill in the MACD Long/Short/Signal period variable values are per what you want them to be.
Good luck :-)
Dear firemyst,
Thank you for responding :-)
I have tried your suggestions and the following error codes show up :
Error CS1502: The best overloaded method match for 'cAlgo.API.Internals.IIndicatorsAccessor.MacdCrossOver(cAlgo.API.DataSeries, int, int, int)' has some invalid arguments
Error CS1503: Argument 1: cannot convert from 'cAlgo.API.Bars' to 'cAlgo.API.DataSeries'Unlike EMA / RSI / ATR, it seems that for MacdCrossOver (the same goes for MacdHistogram), format DataSeries is needed, so it cannot be filled with MarketData.GetBars(TimeFrame.Hour) ?
Any ideas for a workaround or maybe other suggestions ?
It can.
All you have to do is make it a data series.
For instance, ".ClosePrices" is a data series.
.HighPrices is a data series.
.LowPrices is a data series.
.OpenPrices is a data series.
Which one do you want to use?
Just add it on to turn the "cAlgo.API.Bars" into a "cAlgo.API.DataSeries".
I'd do it for you, but then you'd never learn. :-)
@firemyst
firemyst
20 Sep 2020, 14:36
RE:
defontein93 said:
Dear Experts,
I am developing a bot to run in the 15-Minutes Time Frame,
and I need the bot to only enter a trade according to the MACD Histogram in the 1-Hour Time Frame.
Is this possible to be done and how would it be done ?Any response would be highly appreciated. Thank you.
Note : I have tried the EMA/RSI/ATR Multi Time Frame examples and all works well with the bot,
but have no success with the MACD Histogram.
In your bot get the MACD based on the 1 hour time frame data instead of the 15 minute data.
Sample code off the top of my head:
var _macd = Indicators.MacdCrossOver(MarketData.GetBars(TimeFrame.Hour, Symbol.Name), MACDLongPeriod, MACDShortPeriod, MACDSignalPeriod);
You have to fill in the MACD Long/Short/Signal period variable values are per what you want them to be.
Good luck :-)
@firemyst
firemyst
19 Sep 2020, 08:19
An issue you have is with the statements:
LastResult.Position.GrossProfit
Let's say you have 3 positions #1, #2, #3.
the LastResult is Position #3.
However, your system could then close position #3.
so the next OnTick it checks the LastResult.Position, it no longer exists (since it was closed), thus you have a null reference.
@firemyst
firemyst
17 Sep 2020, 12:13
RE: RE: RE: RE: RE: RE:
xammo said:
yeh I’m expecting notification of at least a partial refund for the outage will wait and see/contact them if don’t hear anything
Thanks for explaining your strategy and I don’t want to keep on about this as I know it is never possible to account for all the markets can throw at us (but this is not actually about the market) but even so with what you are doing what if the outage occurs when you’re sleeping? (low equity a thousand pounds or so ok can live with it but what about 10’s or 100’s of pounds equity?) I see NYC Servers offer a service to start up trading software after a restart (so umm isn’t that kinda admitting sh*t can happen even for them?) but I think this is only for MT - not possible with cTrader (and anyway starting cBots unattended with all their variables possibly in a mess due to the ’missing time’ spent in the outage/again depends on style of trading/cBot code would not be too cool)
Anyway I don’t know what the solution would be and as Panagiotis said there are many (most probaly all) running on a single VPS so I guess an outage and any potential loss caused by it would just be put down to experience and the overall P&L of trading as a whole... btw I did try running both VPS’s with same cBots at the same time and there were no issues when a trade closed/triggerd the next trade EXCEPT for the fact that each cBot placed a trade when it should have only been one (I use/depend on the TradeResult in the code to hold back further trades until initial has been registered succesful - obvously this result cannot (that I know of) be shared between the two cBots so I don’t reckon that idea is going to work for me anyway at least not for the current code but good to know it is ‘possible’
No worries on asking questions - I'm happy to answer.
" but even so with what you are doing what if the outage occurs when you’re sleeping?"
My bots have certain time limitations I can configure. For example, I have it configured so no trades are placed about an hour before I typically go to bed. An hour before going to bed any trades I'm in should have at least turned a profit where I could have locked something in.Otherwise, I might tighten the SL a bit and then just let it manage the position overnight. But definitely no new positions will be opened.
In regards to your issue with the cBots bot placing orders, obviously one thing to do is check the Positions[] for the same symbol/timeframe/label just before opening a new one. All my bots have a uniquely encoded position label, so I can easily check that. It also allows me to open multiple positions of the same symbol across multiple time frames with the following:
_p = Positions.Find(_positionLabel);
You can narrow it down further via the API with:
_p = Positions.Find(_positionLabel, Symbol.Name);
_p = Positions.Find(_positionLabel, Symbol.Name, _p.TradeType);
But I have everything encoded in the label so it's less work the Find method has to do. :-)
@firemyst
firemyst
17 Sep 2020, 10:44
RE: RE: RE: RE:
xammo said:
Just curious - what would you do if that one NYC VPS went down for 5/10/15+minutes? obviously no idea your equity level or if you’re similarily just testing with low equity or what your current situationn is but yeh would that cause you a problem and/or could you recover from it relatively quickly/easily with minimum to no ‘hurt’?
I would definitely do at least 2 things:
1) Demand a refund from the hosting company since they guarantee 100% uptime
2) This is where running the bots on a completely separate, second computer helps. I would run them on my local computer because it has the same bot code and bot settings. I also keep the computer and cTrader up during the day, so I can see the trades, see what's happening, and manually manage them when need be (like when I see divergence going against me). I rarely, if ever, let bots (even my own) run 100% of the time unmanaged by me because we can never account for everything that might happen in the markets.
@firemyst
firemyst
17 Sep 2020, 07:48
RE:
luca.tocchi said:
hi my bot should modify the stop loss (using ModifyOrder) when it reaches the stop loss minus 0.2 pips
how can I do?
thanks
//for long positions
if ((Symbol.Bid - CurrentStopLossValue) / Symbol.PipSize <= 0.2)
{
//price is within 0.2 pips of SL
p.ModifiyStopLossPips //or p.ModifyStopLossPrice depending on what you want to do
}
@firemyst
firemyst
16 Sep 2020, 14:05
( Updated at: 21 Dec 2023, 09:22 )
RE: RE:
xammo said:
Hi Firemyst
...
(1 CPU/1GB RAM) for ctrader which doesn’t give me much confidence as it simply won’t run on those specs but yeh the standard looks ok but even 2CPU/4GB RAM will only just get cTrader running but can choke if a few cBots running especially more so as time passes and cTrader eats into RAM/CPU for inexplicable reasons only cleared by a restart of the VPS
No worries on the advice.
I can say I currently have that 2CPU/4GB package deal from NYC Servers and it runs cTrader great for me.
On the VPS, I actually run TWO copies of cTrader at the same time running the same bot. However, I have 26 instances of the bot running (13 instances running between each running copy of cTrader).
Here's a capture of the performance stats (these two cTraders have been running the bots for over 24 hours straight now):
So as you can see, with 4GB and 2CPUS, the VPS isn't hurting at all. Everything is very responsive, and I can even run other programs on there at the same time (like Google Chrome and such).
There are 2 big tricks to running cBots under cTrader so memory isn't consumed:
1) when starting the bots, don't click on each bot instance to load the chart. That causes cTrader to suck up more memory. Just click the play button and that's it.
2) don't write many Print statements. When they will up the log, cTrader really sucks up memory. Instead create some sort of log mode switch so you only print statements when you absolutely have to.
:-)
@firemyst
firemyst
15 Sep 2020, 13:27
RE:
ctid2568413 said:
@firemyst, this might be what I am missing. Which part of the code is it to be defined?
@PanagiotisCharalampous, possibly the above will solve it.
I can't tell where because I don't have your code, but you should do it wherever you check the conditions.
For example:
//check the symbol and time frame are the same as what's on the current chart this indicator is attached to.
if (Bars.TimeFrame == Chart.TimeFrame && Symbol.Name == Bars.SymbolName)
{
//You know both the symbol and timeframe match, so this is where you do what you need to.
}
else
{
//this is some other symbol name / timeframe combo
}
@firemyst
firemyst
15 Sep 2020, 06:04
Hi @MaxT:
“Is it possible to run two (or more!) cTrader installations logged into the same account on separate servers running the same cBots?”
Yes in that I have bots running on a VPS and while they are running, I have also had them running on my local home desktop machine connected to the internet.I've even done it with same instance pairs and same time frame.
I can't say anything in regards to syncing with OneDrive as I wouldn't do that:
1) it can cause lots of network lag
2) OneDrive isn't 100% guaranteed uptime
3) if you're running on more than one computer, syncing to the same OneDrive, who knows what kind of file bashing/hashing/coordination has to go on, how long that takes, and if the delay is significant, can certainly halt cTrader if it doesn't get enough network bandwidth or fast enough speeds when writing to the local disk.
What I do is just drag/drop the c:\Documents\cAlgo|cTrader folders over to a local backup drive. Takes maybe 5 minutes to copy (if that).
The other thing you might consider doing is switching VPS providers. I currently have an account with NYC Servers, and they have been fantastic.
If you sign up through the above link, they offer special discounted rates for numerous brokers such as Pepperstone, IC Markets, and others.
Just scroll down the page to the section "VPS Service By Broker", select your broker, and go for the special rate. For example, as of this post, you can get a standard VPS:
- Runs 4-6 accounts
- 2 CPU cores
- 4GB ram
- 40GB SSD storage
- 100% uptime guarantee
for 1/2 price if you're with either Pepperstone or IC Markets. That's more than enough to run both cTrader and MT4/MT5 EA's.
Make sure you scroll down to the bottom of the NYC Servers page though to the "VPS Service By Broker" section to get the special rates.
Most people miss that.
Good luck.
@firemyst
firemyst
15 Sep 2020, 04:41
( Updated at: 21 Dec 2023, 09:22 )
RE:
ftmo91598958384 said:
Hello, I am having trouble increase my lot size on XAGUSD above 500. Every time I attempt to increase the lot size, the box is shaded red unless its below 500. Does anyone know how to fix this as I have missed a few trades today cause of this problem.
Thank you
Are you going over your margin levels? I don't see them on the screen. If you're increasing your size and it takes you above your allowed margin level, you won't be allowed to.
@firemyst
firemyst
09 Sep 2020, 06:18
RE: RE: RE:
luca.tocchi said:
firemyst said:
luca.tocchi said:
how do i check the direction of the moving averages in real time and if they go high i go buy if they go low i sell?
Thanks a lot
You get the current value of the MA and can compare it to the previous value to see if it's increasing or decreasing.
//example pseudo-code if (ma.Result.Last(0) > ma.Result.Last(1)) //open long position else if (ma.Result.Last(0) < ma.Result.Last(1)) //open short position else //the ma values are equal. What do you want to do?
Yes sure
but I have to check 3 moving averages, if all 3 are up go buy, if all 3 are down go sell
but if at least one of these averages goes in the opposite direction, the program must wait for all three to go in the same direction
I would be grateful if you could help me
Then do the same thing for the 3 moving averages:
//example pseudo-code
if (ma1.Result.Last(0) > ma1.Result.Last(1)
&& ma2.Result.Last(0) > ma2.Result.Last(1)
&& ma3.Result.Last(0) > ma3.Result.Last(1))
//open long position
else if (ma1.Result.Last(0) < ma1.Result.Last(1)
&& ma2.Result.Last(0) < ma2.Result.Last(1)
&& ma3.Result.Last(0) < ma3.Result.Last(1))
//open short position
else
//the ma averages are all not going in the same direction. What do you want to do?
@firemyst
firemyst
02 Oct 2020, 08:17
RE:
PanagiotisCharalampous said:
Hi @Panagiotis:
How do I use Open API from within a bot or indicator to retrieve the commission from the symbol information? I thought commission information isn't available?
Thank you.
@firemyst