If you don't want positions of the same symbol to overlap, then you need to find all positions first of the current symbol, and then doing a Positions.Count on that.
Doing a generic “Positions.Count” will count all open positions, even if you have several not open on the current symbol your bot instance is running.
For example, you could have an AUDUSD position open, a EURUSD position open, and EURJPY position open. If you only want to limit your bot so that you don't open another EURJPY position, then you need to search all positions that are just EURJPY.
Example:
int numPositionsAlreadyOpen = Positions.FindAll(p.Label, Symbol.Name).Count();
Hope that helps you even more :-)
Thanks Firemyst, that's also very helpful. I found something like that in the forum.
For now, I will apply this logic by grouping the long and short positions separately, in order to decrease exposure at times where the pairs are correlated. According to the results of QuantAnalyzer, this would greatly soften the portfolio curve, but I don't know how much to trust those hypothetical results. I'll try it first in demo.
I added it like this in each cbot. Please correct me if that´s wrong:
protected override void OnBar() {
var longPositionsCount = Positions.Count(p => p.TradeType == TradeType.Buy);
var shortPositionsCount = Positions.Count(p => p.TradeType == TradeType.Sell);
if (longPositionsCount == 0 && ShouldEnterLong()) { logic }
if (ShouldExitLong()) {CloseLongPositions();}
if (shortPositionsCount == 0 && ShouldEnterShort()) { logic }
if (ShouldExitShort()) {CloseShortPositions();}
}
I can't tell you if it's right or wrong because I'm not 100% sure what you want to do.
What your code will do though is found the number of buy positions and sell positions open across all active bot instances and won't open a long position for any symbol if you have a long position open anywhere in any account; likewise your code won't open a short position for any symbol if you have a short position open anywhere.
If you don't want positions of the same symbol to overlap, then you need to find all positions first of the current symbol, and then doing a Positions.Count on that.
Doing a generic “Positions.Count” will count all open positions, even if you have several not open on the current symbol your bot instance is running.
For example, you could have an AUDUSD position open, a EURUSD position open, and EURJPY position open. If you only want to limit your bot so that you don't open another EURJPY position, then you need to search all positions that are just EURJPY.
Example:
int numPositionsAlreadyOpen = Positions.FindAll(p.Label, Symbol.Name).Count();
Looking at the code, I see a lot of repetitive stuff that you should eliminate to reduce CPU and memory operations.
For starters:
1) you have "i * load" all over the place. That wastes at least 3 CPU cycles to reference i, reference load, and then do the multiplication. Do "i * load" ONCE at the start of the loop, save it into a local variable (that will be saved in faster memory access), and use that throughout.
2) same thing with "index - 1". Create a local variable int indexMinus1 and assign "index - 1" to it. Then use that local variable everywhere instead of having the calculation repeated over and over and over
3) Color.FromArgb(100, "A3FF6000"). Again geezsus. Set the color once in a local variable and reference that where needed instead of having the system to call that function over and over and over.
4) "stoch" + i + index : strings are immutable objects. Every time you do this, the CPU has to waste cycles creating a new string object in memory, storing it in memory, and then referencing it. Create another local variable, set it once, and then reference it throughout code. Ex: string strIdentifier = "stoch" + i + index; There. It's done once, and you've just freed up not only constant memory operations but also multiple CPU cycles.
As explained, we have no reason to block a specific ip address. If the site is accessible from everywhere else, then it is probably an issue of that machine not being able to reach out to the specific uri, not the site in general.
Best regards,
Panagiotis
You might not be doing it, but someone appears to be (AWS? A middle-man routing provider?) blocking, or not allowing, any addresses from the 77.90.x.x network.
My VPS provider responded that they can set up any number of fresh Windows 2019 Server VPS on the 77.90.x.x network, and it doesn't work anywhere:
Also, doing a TRACERT on one of the 77.90 machines, this is what happens for them:
which is consistent with the errors received in the browsers (this is from Firefox this time as I've already posted errors from Chrome previously in this thread) :
So even if Spotware isn't blocking IP addresses themselves, there's definitely “network interference" going on that's preventing Spotware users of cTrader from reaching Spotware's cTrader servers, and I would think Spotware would want to take an interest in it to find out why network traffic from at least one network with the ID of 77.90 isn't being allowed to reach their servers.
Spotware does not block any VPS. You should contact your VPS provider instead.
Best regards,
Panagiotis
See first screen capture from browser showing the errors.
How is it not an issue on Spotware's side if the browser itself is getting responses that it's timing out?
I've already spoken with the VPS provider as well. They themselves can access ct.spotware.com and the cTrader desktop from any of their other machines. I can run Pepperstone's cTrader, IC markets cTrader on the VPS, and visit any other website on from the VPS.
If it was an issue with the VPS provider, why would the browser show the error of “https://demo2.p.ctrader.com:9443/connections net:: ERR_TIMED_OUT” from the vendor-sentry.js file on https://ct.spotware.com but not https://ct.pepperstone.com/ ?
If you don't post screen captures or sample code reproducing the issue, how are you expecting people to help you?
No need for help! just posting a Bug.
So again, where's the sample code that reproduces the issue?
If it's a bug, you should be able to generate code that demonstrates the problem. Provide the code so people can investigate and replicate what's happening so it can be fixed.
firemyst
19 Dec 2023, 05:39
( Updated at: 19 Dec 2023, 06:44 )
Totally agree!
We can also select columns to display in the bottom panel showing our positions, so I have no idea why Spotware hasn't given up that option yet as well for the watchlist panel!
It is still hard to help you without exact steps on how to reproduce the issues on our machines. If you want the community to help you with coding issues, you need to help them reproduce the problem in two minutes :) Nobody will spend hours guessing what is wrong. We have our own problems to solve :)
Best regards,
Panagiotis
Ok, I'll try to be more exact:
I don't ‘think’ there's anything wrong with my code (although, happy to be corrected)- it seems to operate (in real-time), as expected.
My Question maybe should be: Does anyone else find that the Backtest doesn't seem to reflect anywhere near the Real-Time performance when testing a cBot that uses Pending Orders (i.e. Backtest performs amazingly, but in real-time shows poor results) and has anyone overcome this problem?
(Perhaps, a setting I need to change or an add-on I need to download, a certain library I should be using?)
So as @PanagiotisChar hinted in a previous post, how are you doing your back tests? What settings in the back testing mechanism do you use? Do you have any screen captures to show your back test results with your settings?
Like, you're not providing us with any details on how you are backtesting, what the parameter settings are, etc etc.
protected override void OnBar() { // Check if price is in a supply or demand zone foreach (var zone in supplyAndDemand.sList) { // Check if current bar's high price is greater than zone's high price // AND previous bar's high price was lower than zone's high price if (Bars.HighPrices.Last(1) > zone.high && Bars.HighPrices.Last(2) <= zone.high) { // Enter short trade as price entered a supply zone ExecuteMarketOrder(TradeType.Sell, Symbol, TradeVolume, Instance, null, null, null, "Supply Zone"); } }
foreach (var zone in supplyAndDemand.dList) { // Check if current bar's low price is lower than zone's low price // AND previous bar's low price was higher than zone's low price if (Bars.LowPrices.Last(1) < zone.low && Bars.LowPrices.Last(2) >= zone.low) { // Enter long trade as price entered a demand zone ExecuteMarketOrder(TradeType.Buy, Symbol, TradeVolume, Instance, null, null, null, "Demand Zone"); } } }
} }
Hello there - I actually took a look at this inside visual studio and noticed that the indicator Calculate() method isn't getting fired (when using the Robot - it's actually fine when using purely as an indicator).
I'm using cTrader v4.7.7 - could there be an issue here?? I tried creating a basic indicator from scratch inside cTrader and wiring it up to your Robot also and it also didn't fire the Calculate() override. I then went back to basics and created a vanilla custom indicator and robot and referenced the indicator from the new robot. same outcome - Calculate() doesn't get fired.
Can anyone else confirm the same outcome?? - oh and hello everyone, been lurking for a long-time due to my username getting blocked for no apparent reason!! However, big thanks to the cTrader community team, now unblocked and ready for, ermmm responding!! ;).
Happy to attach my vanilla code examples that illustrate the issue when using an indicator inside a robot script using v4.7.7.
anyway -cheers and hello from me.
Of course it's not being fired - you aren't calling the indicator in a way to force its values to be calculated. You do this directly by calling the Calculate method, or indirectly by calling methods such as “.LastValue" to get the last value of the indicator, “.Last(1)”, “.Last(2)” (to get the value 2 bars ago), etc etc.
One of the reasons i dont consider this plattform being suited for real trading.
This is really dangerous.
Dont like when plattforms are not made customizable.
Hi there,
You can hide the indicator titles in the Viewing Options
Best regards,
Panagiotis
The overall point of this thread is one can't trade nicely with the indicator tiles shown, because they get in the way that the user cannot “Grab” either the SL or TP lines when trading.
Even if on the chart if the eyeball is clicked or unclicked, a user simply cannot click and drag the SL/TP line. In this example below, the SL bar can't be grabbed and dragged unless someone moves the entire chart area down so graphically the SL and TP lines come down BELOW all the indicator tiles:
One when the chart is re positioned like so:
is one able to grab and move the SL/TP lines.
So in a nutshell, as of version cTrader v 4.8.30 Spotware still hasn't fixed this issue. All they should need to do is fix the indicator tiles shown so their Z-Axis value is lower than the SL/TP lines displayed.
Or as I suggested in my original post, INDENT the indicator tiles displayed so the SL/TP parts can be grabbed.
firemyst
30 Dec 2023, 12:00 ( Updated at: 31 Dec 2023, 16:08 )
RE: RE: Multiple cbots and only one position at a time
The_Dark_Knight said:
I can't tell you if it's right or wrong because I'm not 100% sure what you want to do.
What your code will do though is found the number of buy positions and sell positions open across all active bot instances and won't open a long position for any symbol if you have a long position open anywhere in any account; likewise your code won't open a short position for any symbol if you have a short position open anywhere.
@firemyst