Topics
Replies
lavio@gigalink.com.br
14 Aug 2018, 14:57
RE:
Panagiotis Charalampous said:
Hi Lavio,
Regarding the two instances, cBots are not saved in workspaces. Therefore you should not expect to see the cBots you loaded on one computer being loaded in another computer. Also I was with the impression that you needed one instance for cTrader Trade and one for cTrader Automate, not two instances of cTrader Trade.
Best Regards,
Panagiotis
Hi Panagiotis,
This one I did not understand.
One instance for CTrader Trade and one for CTrader Automate??
But aren't them integrated now in version 3??? That's the reason I always ask for an independant executable for the good and now obsolete cAlgo.
Also, notice how important is to save the cbots in each chart!
If they aren't saved in workspace, where are them saved?? Why they load when I use only one intance of Crader integrated?
That's the reason I ask for a more simple method to save things, saving EVERYTHING without doing such mess. Everytime I close CTrader Integrated, I do not know if the cbots will load again next time I reinitiate the application! This is terrible. I learned by experience (a bad one) that if I close the application using Task Manager then the cbots always star up correctly in the charts. But if I close using the Ctrader exit, not always. This is a mess.
Thanks, Lavio
@lavio@gigalink.com.br
lavio@gigalink.com.br
14 Aug 2018, 04:30
One more bug
Hi Panagiotis,
One more big bug did happen today.
In a previous message I said CTrader was using 20% of CPU resources.
Well.... today when I closed the application, as mentioned in the previous message about running two instances, I noticed that in the Task Manager the application was still there, using from 15 to 20% of CPU all time.
Then I waited about 5 minutes because I already noticed that after I stop an optimization manually, CTrader keep some running threads until they finish (what is also another bug I think).
CTrader was still there running ... a CTrader ghost I removed using Task Manager.
Notice I HAVE NOT used it to optimize. Maybe one or two backtests and some robot editions and rebuild.
When I reinitated CTrader, it was using about 5% of CPU time, not 20%.
Get you now there are looping ghost bugs making Ctrader application to overload very easily?
THanks, Lavio
@lavio@gigalink.com.br
lavio@gigalink.com.br
14 Aug 2018, 04:19
RE:
Panagiotis Charalampous said:
Hi Lavio,
1) I still do not understand why you cannot run two instances of cTrader, one for trading and one for developing. I trade and write robots myself and I do not see any problem doing that. It is exactly the same thing as running two different applications.
2) For cTrader to stop responding, then probably the application is overloaded, mostly because of the robots running at that time. In order to help you further with this, I will need the cBots code.
Best Regards,
Panagiotis
Hi Panagiotis,
Well, today I tried to open two instances of CTrader.
First, I closed the CTrader instance running in my first computer with the 9 charts and 33 robots.
Then on a second computer for safety I did open two instances, opened different charts, added different robots using two different demo accounts... just to test, and saved each one in a different workspace.
Then I closed both instances.
Then I opened one... and then the other. Ok, all robots did open as also the charts, if you manually open the desired workspace and select the corresponding account.
Then... I tried to open in one of the instances the main workspace I use in my first computer, with 9 charts and 33 robots. It opened the charts, BUT ZERO ROBOTS.
Then I get a bad feeling... I guess you are thinking too ... I returned to the first computer, initiated a unique instance of CTrader in the right workspace.... and then all charts were there, but NO ROBOTS AT ALL !!!!!!!!!!!!! They vanished.
This was EXACLTY the reason I asked you twice to tell me HOW to open two instances and TO BE SURE I would NOT lose all open robots.
Again again I suggest the most simple and obvious: save everything (charts, robots and associated account) in one file in user computer. No cloud, no Facebook, no CTD id, no workspace, no mess... please.
Thanks, Lavio
@lavio@gigalink.com.br
lavio@gigalink.com.br
13 Aug 2018, 04:38
Another "Not responding" case
If you hybernate the machine, in Windows 10, when you restart .... CTrader ALWAYS locks de system for SEVERAL minutes.
Only CTrader. Even with market closed and cpu utilization less than 5% for CTrader, when finally it runs.
Now reading above message from other user teeling similar problems... I also use a SSD in drive CD:
Lavio
@lavio@gigalink.com.br
lavio@gigalink.com.br
12 Aug 2018, 05:59
Overload and another bug
Panagiotis Charalampous said:
Hi Lavio,
1) The reason that I am asking for the cBots is to be able to reproduce this on my local computer so that the team can find out why this happens. You presume that the reason is the integration but I am pretty sure this is not the problem. If you don't want to share your robot publicly, send it to me at community@spotware.com.
2) cTrader Trade charts and cTrader Automate charts do not affect each other. So if you use cTrader Trade on one instance and cTrader Automate on another, no mixup will happen. It will be exactly like running cTrader and cAlgo in parallel.
Best Regards,
Panagiotis
Hi Panagiotis,
About the overload... I need to say that there are many situations the application gets the "non responding" state for some seconds up to some minutes, specially when optimizing and you change robot to make something else and then try to return to the optimization page... it gets crazy usually non responding, with gray screens and such things. In other words... it gets overloaded VERY easy. Try to do one opt (preferably using ticks) and one backtest at the same time to see what happens if you change pages frequently. I recommend you to keep the Task Manager running to be able to end a task manually...
Also, another bug ... usually, after an optimization, the backtest does NOT work. For example, you click the APPLY buttton to copy the parameters of an optimization to the robot list so you can do a backtest to see the result in a chart do play with the parameters. So, you click the play buttton. Ahahahah... nothing happens. It does not work. Sometimes, if I build the code again, then the backtest works again. But not always. Sometimes I need to close the application and start over !
I sugest you strongly to increase the ONLY 20 best optimizations it keeps in memory. This is nothing ! Many times, you change a optimization criteria to get a different point of view and there is no chart, no history... this is very bad and imposes to apply the parameters to the robot to run a backtest to see the curve and other data. But then the backtest button does not work.... and I really get very upset with this version 3. In version 2, none of these very annoying problems did happen.
Thanks,
Lavio
@lavio@gigalink.com.br
lavio@gigalink.com.br
10 Aug 2018, 20:56
RE:
Hi Lavio,
1) The reason that I am asking for the cBots is to be able to reproduce this on my local computer so that the team can find out why this happens. You presume that the reason is the integration but I am pretty sure this is not the problem. If you don't want to share your robot publicly, send it to me at community@spotware.com.
2) cTrader Trade charts and cTrader Automate charts do not affect each other. So if you use cTrader Trade on one instance and cTrader Automate on another, no mixup will happen. It will be exactly like running cTrader and cAlgo in parallel.
Best Regards,
Panagiotis
Hi,
1) There are 9 charts and 33 robots. I do not think that sending you all our (I have a partner on this enterprise) robots will be possible. Also, you are ignoring the fact that the same robots and environment was working fine in version 2. That's the reason I asked you how I could go beck to the version 2, because I know that then I would ger rid of most current problems.
2) Maybe I did not explain my question as good as I should. Let me yry again.
Ok, there is a section you call "Trade charts" and other section you call "cTrader Automate".
My point is not about the charts mixing up. But when you start one instance of the Ctrader application, what charts AND ROBOTS on each chart will appear, start up?
Using ONE instance, I can exit the application (for a Windows restart, for example, or a CTrader update) and I am sure when I start the application again, the same instance with the same charts and the SAME robots will start up. Only the robots will be in a stop state instead of running as they were when I exited the application instance.
However... if I run TWO instances, one with my 9 charts and 33 robots I use only for the "Trade charts" and other with only one chart, zero robots in the Trade charts section, I use only for the "CTrader Automate" ... and then I close both instances for some external reason .... and then I start the Ctrader application ... what previous instance (from the TWO I had closed) will open???
Notice I really need one of them with all the information saved and restored.
Based on observation of how it works, it will restore ONLY the LAST saved instance. And that would be dangerous if I forget to save LAST the full one, the one with all robots running in the Trade Charts section. If, for example, power ends, the nobreak does not work at all, and Windows collapses... when I restart computer, WIndows and run the application once, what instance would be restored ??????? How to be able to restore the instance I need? That's the reason I suggested in other thread to make a saving system more clear, simple and straight: to save / load charts, settings and robots running using a filename you can save in your own computer. Simple approaches are always better. Too much "automation" usually leads you to problems.
Right now, the only secure solution I have is to run a second instance of IC Markets CTrader in another computer, increasing my energy expenses, I would like to avoid.
By the way... why Ctrader does not install in a regular, independant and simple directory, instead of spreading out files in every Windows corner? This is a nightmare if you want to make things easier to work.
Lavio
@lavio@gigalink.com.br
lavio@gigalink.com.br
10 Aug 2018, 16:40
RE:
Panagiotis Charalampous said:
Hi Lavio,
1) I still do not understand why you cannot run two instances of cTrader, one for trading and one for developing. I trade and write robots myself and I do not see any problem doing that. It is exactly the same thing as running two different applications.
2) For cTrader to stop responding, then probably the application is overloaded, mostly because of the robots running at that time. In order to help you further with this, I will need the cBots code.
Best Regards,
Panagiotis
About the two instances... ok, I will try again.
Can you tell me how it saves the robots in each chart?
This is not in the workspace saving, only the charts.
I notice that when I close the application and reinitiate, all charts and ROBOTS are there. Ok. Fine.
But if I use TWO instances, each one with different charts and robots ... and if I close the empty one LAST... when I start the full instance will it open empty or full?
@lavio@gigalink.com.br
lavio@gigalink.com.br
10 Aug 2018, 16:35
Hi Panagiotis,
Overloading...
I do not think the reason are the robots. Probably, the reason is in the application. This is why:
Why a very similar situation using Ctrader 2.0 did not overloaded the application to such non responsive point??
Also, it is using, right now, up to 20% of CPU time, in a moment the movement (number of ticks) is the higher (about 10-11 hr am here).
I am telling you man... I used almost the same robots and charts up to three months ago before this "integration" and I had NOT such problems. And I am here exactly because to use this version 3 become difficult.
Yes, of course now it is being very overloaded in some moments! But notice... only in some very specific moments I do not see a good reason to be (not in my environment). And obviously the integration does not help. On the contrary, how can you think it could work on such circunstances? If the CTrader side is already being overloaded when the connection blinks ... now imagine how can the Calgo side work?? Ok, then you have to notice big and loud the system cannot handle more than about 10 robots using ticks and you cannot use Calgo AND CTrader together. Is this good??? Of course it is not. But that what is happening.
Thanks, Lavio
@lavio@gigalink.com.br
lavio@gigalink.com.br
10 Aug 2018, 15:52
Hi Panagiotis,
I have three computers. All with Windows 10, Intel I7, 12GB ram to run demo accounts. And also use a Cloud installation of CTrader to run a live account.
I have used CTrader last 3 or 4 years, mostly to create robots using IC Markets and FxPro.
Using CTrader 2.X, AND AN INDEPENDENT CALGO, I had no big problems.
But after this terrible integration...
Come on. I don't believe you do not know what happens. Just try to work hard on this integrated version. Do it. And you will understand. Put several robots running on CTrader and then try to do something using the "calgo" side. IT DOES NOT WORK.
It was very unwise to put CTrader and CAlgo together. One disturbs the other.
I can tell you two main reasons to have a CALGO independant:
1) Security; If you run CTrader in several charts with several robots, to do experiments using backtesting and optimizations can crash everything.
2) Slow down. The "calgo" editor + backtesting + optimization gets VERY speed truncated, VERY slow; it is a nightmare to do something with CAlgo if, on the other side, CTrader, you are running a lot of robots. It is unfeasible.
As I said I had to change from ticks to M1 to be able to accomplish simple tasks. And even so, the "zero volume"and the "bad stops" errors popup after a "non responsive" status of 10 minutes(!) that happens under some circunstances (maybe related to minimization - if I keep CTrader window maximized, it does not happen - maybe related to some operations Windows does in background when the user does not work on the computer using mouse/keyboard for some hours). For example, I let verything running at night. But if I let CTrader minimized, next morning when I try to open it... the "non responsive"' problem pops up. Maybe it can also be related to general Internet (or only to the broker) short disconnections. It DID happen sometimes that, after a period of bad connection, that goes of/on several times in sequence, for some minutes, then CTrader is not able to reconnect again and stops responding for several minuts (I did close it by force and reinitaite sometimes, but now I guess that if I wait for several minutes it would return to work again... and probably with the bad volume, bad stops errors).
Notice that the SAME robots using CTrader 2.X with Calgo independant never raised such rude and basic errors.
IT IS A MUST to have an independant version of CALGO.
I want to optimize in IC Markets, because this is where the live account is.
BUT... I cannot do it in the integrated version because of the two reasons mentioned above. Then I run a FxPro version, INDEPENDANT... to be able to work on the robots. BUT... this is not what I need.
As I asked on other message, tell me FOR SURE how I can run TWO CTrader executable from the same broker (ICM in my case) so one does not disturb the other when saving things because I am afraid to save (or just close) one instance and lose everything I have running on the other instance. It would be a nightmare to reinitiate all charts and all robots again.
Lavio
ps: it is happening right now ... after the time I wrote this ... I heard the "beep" notifying the connection to the broker was OFF ... then I clicked in the CTrader icon to see it and it opens all black... with only the status on the upper bar is saying "IC Makets cTrader 3.0 (not responding)".
I will wait until it comes back. And I bet it will. This already happened several times. Then I will see if the non sense errors start poping.
Please, do an independant version of CAlgo. This integration was a very, very, very bad idea.
@lavio@gigalink.com.br
lavio@gigalink.com.br
08 Aug 2018, 05:30
When trying to open a position, market or limit pending, sometimes it says the volume is abnormal, 0 lots.
Other times, it says the stops are bad.
However, 1) such errors never did happen before version 3; 2) the code DOES not send crazy volumes or stops.
And 3) it seems they start after a "reconnecting..." issue ou a "not responding..." state that takes from 5 to 15 minutes to recover.
This "not responding" problem is very common if you minimize the program and let the machine working alone, doing nothing. Notice that the computer never stops (suspention or hibernation) for any reason (energy savings or whatever). But when you try to open the program again, to maximize, voila, it gets stuck on the "not responding..." state for several minutes.
Today it did happen again twice. The first time I stopped the suspicious robots and reinitiated them. Ok, it worked for a couple of hours. It started again and then I exited the program (CTrader), reopened the program and reinitiated every robot, manually (they all start stopped). And this did work, the errors vanished. The same robots now started to open positions as expected.
Any possible explanation and solution?
Lavio
@lavio@gigalink.com.br
lavio@gigalink.com.br
06 Aug 2018, 17:04
Hi Panagiotis,
I tried.
But it opened the same charts and robots, not running, and I was afraid to change things in one side and affect the other side.
I CANNOT lose the charts (workspace) and the several robots running on each chart. The work to open everything manually would be a nightmare.
Now, if you can tell me a SECURE way to open two CTrader executable and do not mess things among them, tell me please. Remember there is already one ICM CTrader running with a lot of things I do not want to change.
Remember as well that once a while I need to restart Windows... those cumbersome, but necessary, updates. As also CTrader updates.
By the way... I guess CTrader should have a better amd more clear way to SAVE the charts AND the robots already running in the same place. It does this automatically for ONE running CTrader ... but also has a CTrader id and also saving workspace... do get it how messy it is? Honesty, I am not sure every time I close the program, if all robots previously running will open the same. Yes, it DID happen to me two or three times last three years they DID NOT open, only the charts.
Lavio
@lavio@gigalink.com.br
lavio@gigalink.com.br
01 Aug 2018, 15:21
Yes, but that is the problem, because using the same integrated executable to backtest now in version 3.0 is much slower than when CAlgo was a separate executable.
Then it is faster to run FxPro CTrader, for example, to do ONLY backtests. When you use the same executable to run robots (live or demo) AND to optimize, you get into severe problems: 1) speed, which is a must to optimize; 2) security.... and if a robot crashes CTrader? 3) one disturbs the other, it is common the running CTrader to enter into "non responsive" states for several minutes, specially when the connection chokes.
That's the reason I sugested on other thread here to continue to offer the CAlgo independant version. You can let the intergrated as it is. But for those who run a lot of backtests and optimizations, the integrated version is a drawback, a step back in efficiency.
In fact, I was used to use only ticks. But after the integration, I WAS FORCED to use only M1 bars to simulate the ticks because of speed issues. In other words: the integration, to me, was an horrible choice and I really do not understand such move, unless you want to focus only the manual usage of CTrader and make the optimization obsolete, forcing robot people to migrate to other plataforms. To me, such choice was non sense.
Lavio
@lavio@gigalink.com.br
lavio@gigalink.com.br
01 Aug 2018, 02:23
shoked? Sorry for my English. I am trying...
@lavio@gigalink.com.br
lavio@gigalink.com.br
01 Aug 2018, 02:21
( Updated at: 21 Dec 2023, 09:20 )
If I can upload here three screen shots, you would be chocked.
Let me try...
And Spotware...
@lavio@gigalink.com.br
lavio@gigalink.com.br
31 Jul 2018, 21:50
And what does make an idea to be "in our immediate plans"?
I have noticed a lot of suggestions in the foruns. Some are good. But...
It is a pity. I think CTrader is the best plataform to manual usage. But, if you want to program robots... and this means a lot of backtesting and optimization based on reliable data, it is not so good.
The optimization is weak. Why do not you focus on this issue?
A * very important * optimizing feature is that one you find in other plataforms ... I do not remember now how they call it and I am trying to remember exacly how it works ... you take a piece of past data, optimize the robot and WALK backtesting forward applying the best optimization to see the result... then do this in a loop, stepping over the past to the present. This gives you a real overview on how an optimization works in a relative future.
Also, you say it is a "genetic algorithm". But I do not see any genetic about it. It seems to be just random paramenter choices. If it has any algorithm it seems to be very superficial when compared with the ones used in Ninja, for example. Why do not you make it better? It is quit obvious it needs to.
Lavio
@lavio@gigalink.com.br
lavio@gigalink.com.br
31 Jul 2018, 16:02
And will it never be?
It could be very usefull for a strategy.
Lavio
@lavio@gigalink.com.br
lavio@gigalink.com.br
31 Jul 2018, 15:39
Yes, but it builds succssefully (!?) using CTrader 3.0 (from ICM and FxPro).
@lavio@gigalink.com.br
lavio@gigalink.com.br
31 Jul 2018, 00:46
The editor here did a mess when copying.
Put this on the CalcVol(x):
private double CalcVol(double alav) {
return((double)VolFixo);
}
Just a dumb thing is fine. The calculation is not relevant to the issue.
It compiles on any CTrader without the warning stuff if you set the /* ... */ accordingly.
But only runs on the Spotware version 3.01.
In others, IC Markets and FxPro 3.0, it crahes the OnTimer(): Crashed in OnTimer with TypeLoadException: Not possible to load type cAlgo.API.Color from assembly cAlgo.API, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3499da3018340880.
I also had problems in the " API.HorizontalAlignment" setting, because without the "API." (my kick) it says there are two conflicting versions of the HorizontalAlignment property, one used by API and other by Windows. I guess there is a mess on such libraries, .NET, references ...
Lavio
@lavio@gigalink.com.br
lavio@gigalink.com.br
31 Jul 2018, 00:31
/*
Roleta original (acaso ou alternador)
Turbo com prazo
*/
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
using System.IO;
using System.Windows.Forms;
// referenciar System.Windows.Forms no .NET Framework
using System.Security.Permissions;
using System.Collections;
namespace cAlgo
{
[Robot(TimeZone = TimeZones.ESouthAmericaStandardTime, AccessRights = AccessRights.FullAccess)]
public class ROL : Robot
{
private string robi = "ROL";
[Parameter("Alavanca proporcional?", DefaultValue = true)]
public bool alavprop { get; set; }
[Parameter("Acaso(1) ou Alternar(0)", DefaultValue = 0, MinValue = 0, MaxValue = 1)]
public int acaso { get; set; }
[Parameter("Trocar sinc erros>=X (0 não usa)\nSe acaso, não usa", DefaultValue = 3, MinValue = 0)]
public int xacertos { get; set; }
[Parameter("SG pips", DefaultValue = 100, MinValue = 1)]
public double sgp { get; set; }
[Parameter("SL = sg + DELTA pips", DefaultValue = 10)]
public double slpdelta { get; set; }
[Parameter("TSL ganhando 0=nao usar", DefaultValue = 0, MinValue = 0, Step = 1)]
public double tstop { get; set; }
[Parameter("Boost de volume > N (0 não usa)", DefaultValue = 3, MinValue = 0, MaxValue = 5)]
public int boostvol { get; set; }
[Parameter("Turbo...\n0:não\n1:alavancar\n2:anular", DefaultValue = 0, MinValue = 0, MaxValue = 2, Step = 1)]
public int anular { get; set; }
[Parameter("Max erros p/ turbo", DefaultValue = 3, MinValue = 1)]
public int maxerr { get; set; }
[Parameter("Max prazo p/ dividir turbo", DefaultValue = 1, MinValue = 1)]
public int maxprazo { get; set; }
[Parameter("Roda a cada N ticks", DefaultValue = 1, MinValue = 1, Step = 1)]
public int NTICKS { get; set; }
[Parameter("C (1), V (-1) ou ambos (0)", DefaultValue = 0, MinValue = -1, MaxValue = 1, Step = 1)]
public int xcv { get; set; }
[Parameter("Janelinha (1-9), 1=top left", DefaultValue = 5, MinValue = 1, MaxValue = 9)]
public int jinha { get; set; }
private Position _position = null;
private int VolFixo = 1000;
private int maxpos = 1;
private double LUCRO = 0;
private double pnl;
private int ST1 = 0;
private int ctot;
private bool busy = false;
private double capmax;
// capital máximo a que chegou
private double capini;
private double caprobi;
private int pulabar = 0;
// contador acertos consecutivos
private int csim = 0;
// cont erros consecutivos
private int cnao = 0;
private int csimtot = 0;
private int csimcount = 0;
private int cticks;
private int c10segs = 0;
// contador do timer de 10 segs
private int currbar;
private double slp;
private double sgpnovo;
private int somador = 0;
private int limsoma = 5;
// limite dos contadores
private int cacertos = 0;
private double slip = 1;
private int copsbar = 0;
// contador de ops por barra
private int xpulabar = 0;
private int lastop = 0;
private double alavanca = 1;
protected override void OnStart()
{
robi = GetNomeRobi(robi, jinha);
Positions.Opened += OnPositionsOpened;
Positions.Closed += OnPositionsClosed;
capini = Account.Balance;
capmax = capini;
caprobi = capmax;
cticks = NTICKS;
LerLucro();
slp = sgp + slpdelta;
sgpnovo = sgp;
if (slp <= 0)
{
Stop();
return;
}
if (alavprop)
alavanca = 1.0;
else
alavanca = 0;
cprazo = maxprazo;
Timer.Start(10);
}
// evento
protected override void OnStop()
{
Timer.Stop();
Print("STOPing...");
foreach (var pos in Positions.FindAll(robi, Symbol))
{
Print("POS {0} type: {1}, PNL: {2}", pos.Id, pos.TradeType, pos.GrossProfit);
LUCRO = LUCRO + pos.NetProfit;
ctot++;
busy = true;
ClosePosition(pos);
busy = false;
}
CancelarPendentes();
SalvarLucro();
}
/* versão 3.01 */
protected override void OnTimer()
{
if (IsBacktesting)
return;
API.Color cor;
string s;
if (IsBacktesting)
return;
double x = 0;
foreach (var pos in Positions.FindAll(robi))
x = x + pos.NetProfit;
pnl = CalcPNL(robi);
if (maxpos == 1)
{
ST1 = GetPosition();
s = "ROL\nPNL: $" + pnl.ToString("0.00") + "\nLUCRO: $" + LUCRO.ToString() + "\nST1: " + ST1.ToString() + "\nOPS: " + ctot.ToString();
}
else
{
int cposC = ContarPosicoesBuy(robi);
int cposV = ContarPosicoesSell(robi);
s = "ROL\nPNL: $" + pnl.ToString("0.00") + "\nLUCRO: $" + LUCRO.ToString() + "\nPOSC: " + cposC.ToString() + "\nPOSV: " + cposV.ToString() + "\nOPS: " + ctot.ToString();
}
if (LUCRO < 0)
cor = Color.Red;
else if (LUCRO > 0)
cor = Color.Green;
else
cor = Color.Yellow;
//ChartObjects.DrawText("lucro", s, GetJanelinha(jinha), cor);
API.HorizontalAlignment h;
API.VerticalAlignment v;
GetJanelinha(jinha, out h, out v);
Chart.DrawStaticText("lucro", s, v, h, cor);
c10segs++;
if (c10segs >= 360)
{
// 1 hs
SalvarLucro();
c10segs = 0;
}
}
/* versão 3.0
protected override void OnTimer()
{
Colors cor;
string s;
if (IsBacktesting)
return;
pnl = CalcPNL(robi);
if (maxpos == 1)
{
ST1 = GetPosition();
s = "ROL\nPNL: $" + pnl.ToString("0.00") + "\nLUCRO: $" + LUCRO.ToString() + "\nST1: " + ST1.ToString() + "\nOPS: " + ctot.ToString();
}
else
{
int cposC = ContarPosicoesBuy(robi);
int cposV = ContarPosicoesSell(robi);
s = "ROL\nPNL: $" + pnl.ToString("0.00") + "\nLUCRO: $" + LUCRO.ToString() + "\nPOSC: " + cposC.ToString() + "\nPOSV: " + cposV.ToString() + "\nOPS: " + ctot.ToString();
}
if (LUCRO < 0)
cor = Colors.Red;
else if (LUCRO > 0)
cor = Colors.Green;
else
cor = Colors.Yellow;
ChartObjects.DrawText("lucro", s, GetJanelinha(jinha), cor);
//Chart.DrawStaticText();
c10segs++;
if (c10segs >= 360)
{
// 1 hs
SalvarLucro();
c10segs = 0;
}
}
*/
protected override void OnTick()
{
cticks--;
if (cticks > 0)
return;
cticks = NTICKS;
if (pulabar > 0)
return;
// FECHAR
pnl = CalcPNL(robi);
if (tstop > 0)
SetTrailingStop(tstop);
}
protected override void OnBar()
{
copsbar = 0;
currbar = MarketSeries.Close.Count;
if (pulabar > 0)
{
pulabar--;
return;
}
int cpos = ContarPosicoes(robi);
int cpend = ContarPendentes(robi);
// ABRIR
if (cpos + cpend < maxpos)
{
int cv = Selecionar();
if (cv == 1 && xcv >= 0)
{
BuyMarket(CalcVol(alavanca));
pulabar = xpulabar;
}
if (cv == -1 && xcv <= 0)
{
SellMarket(CalcVol(alavanca));
pulabar = xpulabar;
}
}
}
private int lastsel = 0;
private int Selecionar()
{
int x = 0;
if (acaso == 1)
x = MyRand(-1, 1);
else
{
if (lastop == 0)
{
x = 1;
}
else
{
x = -lastop;
//if (cnao == 1) x = -x;
if (xacertos > 0 && cacertos <= -xacertos)
{
x = -x;
// ressincronizar
cacertos = 0;
}
}
}
lastsel = x;
return (x);
}
private Random random = new Random();
private int MyRand(int n1, int n2)
{
return (random.Next(n1, n2 + 1));
}
// calcvol com prazo e corrigido para uso de TSL e de PNL de fechar geral com ganho
private int cprazo;
private double CalcVol(double alav)
{
ret = VolFixo;
}
}
if (anular > 0 && ret > 10000)
ret = 10000;
d = slp * Symbol.PipValue * ret;
// se for mais do que tem e pode perder, limitar...
if (anular > 0)
{
// turbo
if (d > 0.5 * caprobi)
ret = 0.5 * caprobi / (slp * Symbol.PipValue);
}
else
{
// não turbo
if (d > 0.66 * caprobi)
ret = 0.66 * caprobi / (slp * Symbol.PipValue);
}
ret = Symbol.NormalizeVolumeInUnits(ret, RoundingMode.ToNearest);
if (ret > Symbol.VolumeInUnitsMax)
ret = Symbol.VolumeInUnitsMax;
else if (ret < Symbol.VolumeInUnitsMin)
ret = Symbol.VolumeInUnitsMin;
return (ret);
}
private double TimeDifMins(DateTime t1, DateTime t2)
{
TimeSpan tsp;
tsp = t2.Subtract(t1);
return (tsp.TotalMinutes);
}
// diferença entre t2 - t1 em BARRAS (fração)
private double TimeDifBarras(DateTime t1, DateTime t2)
{
TimeSpan tsp;
tsp = t2.Subtract(t1);
return (tsp.TotalMinutes / TimeFrameToMin());
}
// diferença entre t2 - t1 em DIAS
private double TimeDifDias(DateTime t1, DateTime t2)
{
TimeSpan tsp;
tsp = t2.Subtract(t1);
return (tsp.TotalDays);
}
private void CancelarPendentes()
{
foreach (var order in PendingOrders)
{
if (order.Label == robi && order.SymbolCode == Symbol.Code)
{
CancelPendingOrder(order);
}
}
}
private int GetPosition()
{
int ret;
_position = Positions.Find(robi, Symbol);
if (_position != null)
{
if (_position.TradeType == TradeType.Buy)
ret = 1;
else if (_position.TradeType == TradeType.Sell)
ret = -1;
else
ret = ST1;
// não muda
}
else
{
ret = 0;
}
return (ret);
}
// posições abertas
private int ContarPosicoes(string label)
{
int c = 0;
foreach (var position in Positions.FindAll(label, Symbol))
c++;
return (c);
}
private int ContarPosicoesBuy(string label)
{
int c = 0;
foreach (var position in Positions.FindAll(label, Symbol, TradeType.Buy))
c++;
return (c);
}
private int ContarPosicoesSell(string label)
{
int c = 0;
foreach (var position in Positions.FindAll(label, Symbol, TradeType.Sell))
c++;
return (c);
}
// qtos pendentes há?
private int ContarPendentes(string label)
{
int c = 0;
foreach (var order in PendingOrders)
{
if (order.Label == label && order.SymbolCode == Symbol.Code)
c++;
}
return (c);
}
private double CalcDeriva(DataSeries ds, int off)
{
return ((ds.Last(off) - ds.Last(off + 1)) / Symbol.PipSize);
}
// segunda derivada
private double CalcDeriva2Pips(DataSeries ds)
{
return (((ds.Last(0) - ds.Last(1)) - (ds.Last(1) - ds.Last(2))) / Symbol.PipSize);
}
private double CalcSL(int b, double frac)
{
double d = Functions.Maximum(MarketSeries.High, b) - Functions.Minimum(MarketSeries.Low, b);
return (frac * PriceToPip(d));
}
private DateTime CalcExpira(int nbarras)
{
int x = nbarras * TimeFrameToMin();
return (Server.Time.AddMinutes(x));
}
private TradeResult BuyMarket(double vol)
{
return (ExecuteMarketOrder(TradeType.Buy, Symbol, vol, robi, slp, sgp, slip));
}
private TradeResult SellMarket(double vol)
{
return (ExecuteMarketOrder(TradeType.Sell, Symbol, vol, robi, slp, sgp, slip));
}
private void BuyLimit(double vol, double d, double slp, double sgp, double expmin)
{
if (expmin > 0)
{
DateTime dt = Server.Time.AddMinutes(expmin);
PlaceLimitOrder(TradeType.Buy, Symbol, vol, d, robi, slp, sgp, dt);
}
else
PlaceLimitOrder(TradeType.Buy, Symbol, vol, d, robi, slp, sgp);
}
private void BuyStop(double vol, double d, double slp, double sgp, double expmin)
{
if (expmin > 0)
{
DateTime dt = Server.Time.AddMinutes(expmin);
PlaceStopOrder(TradeType.Buy, Symbol, vol, d, robi, slp, sgp, dt);
}
else
PlaceStopOrder(TradeType.Buy, Symbol, vol, d, robi, slp, sgp);
}
private void SellLimit(double vol, double d, double slp, double sgp, double expmin)
{
if (expmin > 0)
{
DateTime dt = Server.Time.AddMinutes(expmin);
PlaceLimitOrder(TradeType.Sell, Symbol, vol, d, robi, slp, sgp, dt);
}
else
PlaceLimitOrder(TradeType.Sell, Symbol, vol, d, robi, slp, sgp);
}
private void SellStop(double vol, double d, double slp, double sgp, double expmin)
{
if (expmin > 0)
{
DateTime dt = Server.Time.AddMinutes(expmin);
PlaceStopOrder(TradeType.Sell, Symbol, vol, d, robi, slp, sgp, dt);
}
else
PlaceStopOrder(TradeType.Sell, Symbol, vol, d, robi, slp, sgp);
}
private void OnPositionsOpened(PositionOpenedEventArgs args)
{
if (args.Position.Label != robi || args.Position.SymbolCode != Symbol.Code)
return;
_position = args.Position;
if (_position.TradeType == TradeType.Buy)
ST1 = 1;
else if (_position.TradeType == TradeType.Sell)
ST1 = -1;
copsbar++;
}
private void OnPositionsClosed(PositionClosedEventArgs obj)
{
if (obj.Position.Label != robi || obj.Position.SymbolCode != Symbol.Code)
return;
_position = null;
ST1 = 0;
if (!busy)
{
LUCRO = LUCRO + obj.Position.NetProfit;
ctot++;
}
else
busy = false;
caprobi = caprobi + obj.Position.NetProfit;
if (caprobi > capmax)
capmax = caprobi;
if (obj.Position.GrossProfit > 0)
{
csim++;
cnao = 0;
if (obj.Position.TradeType == TradeType.Buy)
{
somador = somador + 1;
lastop = 1;
}
else if (obj.Position.TradeType == TradeType.Sell)
{
somador = somador - 1;
lastop = -1;
}
cacertos++;
}
else if (obj.Position.GrossProfit < 0)
{
cnao++;
// acumula csim máx atingido
csimtot = csimtot + csim;
csimcount++;
csim = 0;
if (obj.Position.TradeType == TradeType.Buy)
{
somador = somador - 1;
lastop = -1;
}
else if (obj.Position.TradeType == TradeType.Sell)
{
somador = somador + 1;
lastop = 1;
}
cacertos--;
}
if (somador > limsoma)
somador = limsoma;
else if (somador < -limsoma)
somador = -limsoma;
if (cacertos > limsoma)
cacertos = limsoma;
else if (cacertos < -limsoma)
cacertos = -limsoma;
}
// calc pnl com múltiplas posições abertas
private double CalcPNL(string label)
{
double x = 0;
foreach (var pos in Positions.FindAll(label, Symbol))
x = x + pos.GrossProfit;
return (x);
}
private void FecharTudo()
{
CancelarPendentes();
FecharPosicoes(robi);
}
private void FecharPosicoes(string label)
{
foreach (var position in Positions.FindAll(label, Symbol))
ClosePosition(position);
}
private double PriceToPip(double price)
{
return (price / Symbol.PipSize);
}
private double PipToPrice(double pips)
{
return (pips * Symbol.PipSize);
}
private double PipToGrana(double pips, double volu)
{
return (pips * Symbol.PipValue * volu);
}
private double PriceToGrana(double price, double volu)
{
return (Symbol.PipValue * volu * price / Symbol.PipSize);
}
private double GranaToPip(double grana, double volu)
{
return (grana / (volu * Symbol.PipValue));
}
private int MinToBarras(double min)
{
return ((int)Math.Round(min / TimeFrameToMin()));
}
private double MyMax(DataSeries ds, int per, int off)
{
double xmax, d;
xmax = 0;
for (int i = 0; i < per; i++)
{
d = ds.Last(i + off);
if (d > xmax)
xmax = d;
}
return (xmax);
}
private double MyMin(DataSeries ds, int per, int off)
{
double xmin, d;
xmin = 99999;
for (int i = 0; i < per; i++)
{
d = ds.Last(i + off);
if (d < xmin)
xmin = d;
}
return (xmin);
}
/* BEGIN TRAIL STOP NOVO USANDO AUTOTS */
private void SetTrailingStop(double xstop)
{
double newstop;
foreach (var pos in Positions.FindAll(robi, Symbol))
{
if (pos == null)
continue;
if (pos.HasTrailingStop)
continue;
if (pos.Pips > xstop)
{
// trocar SL para entryprice e ativar autots
newstop = pos.EntryPrice;
// price
sgpnovo = PriceToPip(xstop);
ModifyPosition(pos, newstop, pos.TakeProfit, true, StopTriggerMethod.Trade);
}
}
}
/* END TRAIL STOP */
private int TimeFrameToMin()
{
int ret;
TimeFrame tf = MarketSeries.TimeFrame;
if (tf == TimeFrame.Minute)
ret = 1;
else if (tf == TimeFrame.Minute2)
ret = 2;
else if (tf == TimeFrame.Minute3)
ret = 3;
else if (tf == TimeFrame.Minute4)
ret = 4;
else if (tf == TimeFrame.Minute5)
ret = 5;
else if (tf == TimeFrame.Minute6)
ret = 6;
else if (tf == TimeFrame.Minute7)
ret = 7;
else if (tf == TimeFrame.Minute8)
ret = 8;
else if (tf == TimeFrame.Minute9)
ret = 9;
else if (tf == TimeFrame.Minute10)
ret = 10;
else if (tf == TimeFrame.Minute15)
ret = 15;
else if (tf == TimeFrame.Minute30)
ret = 30;
else if (tf == TimeFrame.Hour)
ret = 60;
else if (tf == TimeFrame.Hour2)
ret = 120;
else if (tf == TimeFrame.Hour3)
ret = 180;
else if (tf == TimeFrame.Hour4)
ret = 240;
else if (tf == TimeFrame.Hour6)
ret = 360;
else if (tf == TimeFrame.Hour8)
ret = 480;
else if (tf == TimeFrame.Hour12)
ret = 720;
else if (tf == TimeFrame.Daily)
ret = 1440;
else
ret = 0;
return (ret);
}
private TimeFrame MinToTimeFrame(int m)
{
TimeFrame tf;
tf = TimeFrame.Minute;
switch (m)
{
case 1:
tf = TimeFrame.Minute;
break;
case 2:
tf = TimeFrame.Minute2;
break;
case 3:
tf = TimeFrame.Minute3;
break;
case 4:
tf = TimeFrame.Minute4;
break;
case 5:
tf = TimeFrame.Minute5;
break;
case 6:
tf = TimeFrame.Minute6;
break;
case 7:
tf = TimeFrame.Minute7;
break;
case 8:
tf = TimeFrame.Minute8;
break;
case 9:
tf = TimeFrame.Minute9;
break;
case 10:
tf = TimeFrame.Minute10;
break;
case 15:
tf = TimeFrame.Minute15;
break;
case 30:
tf = TimeFrame.Minute30;
break;
case 60:
tf = TimeFrame.Hour;
break;
case 120:
tf = TimeFrame.Hour2;
break;
case 180:
tf = TimeFrame.Hour3;
break;
case 240:
tf = TimeFrame.Hour4;
break;
case 360:
tf = TimeFrame.Hour6;
break;
case 480:
tf = TimeFrame.Hour8;
break;
case 720:
tf = TimeFrame.Hour12;
break;
case 1440:
tf = TimeFrame.Daily;
break;
}
return (tf);
}
/* versão 3.01 */
private void GetJanelinha(int i, out API.HorizontalAlignment x, out API.VerticalAlignment y)
{
switch (i)
{
case 1:
x = API.HorizontalAlignment.Left;
y = API.VerticalAlignment.Top;
break;
case 2:
x = API.HorizontalAlignment.Center;
y = API.VerticalAlignment.Top;
break;
case 3:
x = API.HorizontalAlignment.Right;
y = API.VerticalAlignment.Top;
break;
case 4:
x = API.HorizontalAlignment.Right;
y = API.VerticalAlignment.Center;
break;
case 5:
x = API.HorizontalAlignment.Right;
y = API.VerticalAlignment.Bottom;
break;
case 6:
x = API.HorizontalAlignment.Center;
y = API.VerticalAlignment.Bottom;
break;
case 7:
x = API.HorizontalAlignment.Left;
y = API.VerticalAlignment.Bottom;
break;
case 8:
x = API.HorizontalAlignment.Left;
y = API.VerticalAlignment.Center;
break;
default:
x = API.HorizontalAlignment.Center;
y = API.VerticalAlignment.Center;
break;
}
}
/* versão 3.0
private StaticPosition GetJanelinha(int i)
{
StaticPosition ret;
switch (i)
{
case 1:
ret = StaticPosition.TopLeft;
break;
case 2:
ret = StaticPosition.TopCenter;
break;
case 3:
ret = StaticPosition.TopRight;
break;
case 4:
ret = StaticPosition.Right;
break;
case 5:
ret = StaticPosition.BottomRight;
break;
case 6:
ret = StaticPosition.BottomCenter;
break;
case 7:
ret = StaticPosition.BottomLeft;
break;
case 8:
ret = StaticPosition.Left;
break;
default:
ret = StaticPosition.Center;
break;
}
return (ret);
}
*/
private string GetNomeRobi(string nome, int j)
{
return (nome + "-" + Symbol.Code + "-J" + j.ToString() + "-M" + TimeFrameToMin().ToString());
}
private string[] Explode(string s, char[] carr)
{
if (carr == null)
carr = new char[]
{
';',
','
};
string[] x = s.Split(carr);
return (x);
}
// BEGIN FILE IO
string mypath = "C:\\CTRADER\\";
public bool SalvarLucro()
{
bool ret = true;
if (!IsBacktesting)
{
ret = SalvarTxt(mypath + robi + "-LUCRO.txt", LUCRO.ToString("0.00") + ";" + ctot.ToString());
}
return (ret);
}
public double LerLucro()
{
double d = 0;
string s;
string[] sarr;
if (!IsBacktesting)
{
s = FileReadTxt(mypath + robi + "-LUCRO.txt");
if (s != null)
{
sarr = Explode(s, null);
if (sarr != null)
{
LUCRO = double.Parse(sarr[0]);
ctot = int.Parse(sarr[1]);
}
}
else
{
LUCRO = 0;
ctot = 0;
}
}
return (d);
}
public bool SalvarTxt(string arq, string s)
{
try
{
File.WriteAllText(arq, s);
return (true);
} catch (IOException ex)
{
Print("ERRO: " + ex.ToString());
//MessageBox.Show(ex.ToString());
return (false);
}
}
// retorna stringão com tudo
public string FileReadTxt(string arq)
{
if (File.Exists(arq))
{
string s = File.ReadAllText(arq);
return (s);
}
else
return (null);
}
// END FILE IO
}
}
@lavio@gigalink.com.br
lavio@gigalink.com.br
15 Aug 2018, 15:54
RE:
Panagiotis Charalampous said:
This is not true. This is clear if I try to run a backtest or an optimization in the Automate tab when there are many cbots running in the Trade tab. Then is very easy to check, COMPARE and prove if you run another CTrader instance, as I do using FxPro Ctrader (not the IC Markets version where I have my cbots) without any cbot running in the Trade tab, and then I run the same backtest or optimization to compare speed in the Automate tab. The difference in performance is clear.
Notice you did not answer where the cbots information is saved. If I knew this, I could copy the file with the data manually and avoid a lot of nightmares. I hope, of course, it is not saved on some obscure cloud I am afraid it is.
The methods CTrader uses to save things is very messy. And because the files are spread on every Windows corner, simple manual solutions are unfeasible.
Notice I LOST all cbots information in one computer because I loaded the same workspace in another computer!!! How did they interact !? Because they used a common cloud? Obviously such things should not happen.
Again, if I could run two CTrader instances using different workspaces without MESSING ALL CBOTS information, I would not LOSE all cbots from my charts as did happen many times while I was trying to understand how Ctrader saves things.
The Automate must be an independant EXEcutable running in Windows if you do not want interactions and serious decrease in performance when running backtests AND there are many cbots running in the Trade tab. Windows gives each EXEcutable a priority and a cpu time. In the integrated version, Trade and Automate are fighting for the same time slot.
Performance speed is a must in the Automate.
AND.. do not forget security issues.
Imagine a client using a LIVE account. Then, in the Trade tab, all cbots are running for real. Then what you do? Go to the Automate tab and run a huge optimization or backtests on TESTING cbots? Never! And if everything crashes? You cannot guarantee this, even if you use the best programming techniques to avoid crashing. The integration was a crazy decistion.
Thanks, Lavio
@lavio@gigalink.com.br