Collectinos of Symbols and Robots
Collectinos of Symbols and Robots
06 Jul 2018, 09:40
Dear Panagiotis!
How do I describe a collection of Symbols,
as well as the collection of Robots, so I could use smth like
""
foreach (var symbol in Symbols)
or
foreach (robot in Robots)
""
Thank you,
regards,
Alexander
Replies
alexander.n.fedorov
06 Jul 2018, 09:59
collection of Symbols
I am running a portfolio wit a complex robot (same for each pair)
the bigger the portfolio the more likely is the positive result
The problem is margin
So when margin becomes an issue, I would like to close either the profitable Bots(which may have up to 8 martingale trades on each side and eat a lot of margin)
or close the enire Symbol (which may be in different timeframe with the same Bot)
sometimes I am doing it with hand, but I wanted to right a Bot that will take care of it
Regards
Alexander
@alexander.n.fedorov
alexander.n.fedorov
06 Jul 2018, 10:12
Dear Panagiotis,
I probably could set up a public list or Bots, so every bot on start will be added to the list, or more presisely it's label
Then I could check every member of the list, by doing that I will get a bot
Then for every bot I can calculate the profit and margin, and if neeed, close it
The other way would be to take the all bots with the same symbol and calculate the profit on all of them
@alexander.n.fedorov
PanagiotisCharalampous
06 Jul 2018, 10:16
Hi Alexander,
From what I understand you want to operate on open positons. So my suggestions are the following
- Distinguish the positions of each cBot using a different label.
- Use Select and Distinct functions to get collections of open symbols and running robots.
See some examples below
var robots = Positions.Select(x => x.Label).Distinct(); var symbols = Positions.Select(x => x.SymbolCode).Distinct();
Let me know if these suggestions help
Best Regards,
Panagiotis
@PanagiotisCharalampous
alexander.n.fedorov
06 Jul 2018, 10:21
I will have to study Disctinct and Select functions, but that is not a big deal.
Thatk you .
You are always professional
Regards'
@alexander.n.fedorov
alexander.n.fedorov
06 Jul 2018, 16:38
Would have been fine, but what if a robot did not open a position yet?
@alexander.n.fedorov
alexander.n.fedorov
06 Jul 2018, 16:40
From the practical point of view, if there no positions with the robot, means there is no margin used
That is fine.
But what if I want to stop the robots, even if they did not open a position?
@alexander.n.fedorov
PanagiotisCharalampous
06 Jul 2018, 16:44
Hi Alexander,
I assumed that you wanted to operate on open positions. What would you like to do to a robot that has no open positions? If it doesn't have a position open yet, then it does not have a P&L neither does it allocate any margin.
Best Regards,
Panagiotis
@PanagiotisCharalampous
alexander.n.fedorov
06 Jul 2018, 16:44
In any case, it is , let it be not complete, but some serious solution for the problem.
@alexander.n.fedorov
alexander.n.fedorov
06 Jul 2018, 16:46
Thank you very much, Panagiotis, best regards
@alexander.n.fedorov
PanagiotisCharalampous
06 Jul 2018, 16:59
Hi Alexander,
Simply controling a cBot from another cBot is not currently possible. You will need some more advanced solution which depends on the use case. We discussed this a bit here. You should develop a method of communication between cBots. For example, you could have a controler cBot that will raise flags to other cBots, when they need to shut down themselves. The flags could be set in a file, accessible by all cBots. However, each specific use case might have a different ideal solution.
@PanagiotisCharalampous
alexander.n.fedorov
06 Jul 2018, 17:16
But once it is possible to count the robots through distinct position label, may be it is posssible to attribute the label to var robot in robots?
@alexander.n.fedorov
PanagiotisCharalampous
06 Jul 2018, 17:21
Not really sure what you mean... If each robot has a distinct label, you will be able to filter and close positions of specific robots.
@PanagiotisCharalampous
alexander.n.fedorov
06 Jul 2018, 17:22
I just do not know how to find the label.
@alexander.n.fedorov
PanagiotisCharalampous
06 Jul 2018, 17:26
See below how you can find the positions with a specific label
Positions.FindAll("label");
@PanagiotisCharalampous
alexander.n.fedorov
06 Jul 2018, 17:38
I think I shoul do smth like this
"
foreach (var position in Positions)
{
var label = position.Label;
profit = 0;
foreach (var posit in Positions)
{
if (posit.Label == label)
{
profit=profit+posit.NetProfit;
}
}
if (profit > 0)
{
foreach (var posit2 in Positions)
{
if(posit2.Label==label)
ClosePosition(posit2);
}
}
}
"
Not the most elegant solution, but I think it will do the job
@alexander.n.fedorov
alexander.n.fedorov
06 Jul 2018, 18:02
It does the job, but not exactly what I wanted
Can you think of more elegant solution?
@alexander.n.fedorov
ap11
09 Jul 2018, 12:02
Hi Alexander,
It seems that you are trying to group positions by a label and get only profitable groups.
Here is the code that do that:
var groupingByLabel = Positions.GroupBy(p => p.Label); var profitableGroups = groupingByLabel.Where(g => g.Sum(p => p.NetProfit) > 0);
profitableGroups is an enumeration of groups. Each group is an enumeration of positions and it has a Key property that contains positions label.
Now you can close positions:
var positions = profitableGroups.SelectMany(g => g); foreach(var position in positions) { ClosePosition(position); }
Hope that helps.
Regards,
Andrey
@ap11
alexander.n.fedorov
09 Jul 2018, 13:53
Thanks, Panagiotis
It is much more elegant
Eventually I will send you a bot which I called "Protector" as it protects the whole portfolio from overprofiting(! that is true), and spending too much margin.
But, as always, your solution is much more elegant
Regards
Alexander
@alexander.n.fedorov
PanagiotisCharalampous
06 Jul 2018, 09:52
Hi Alexander,
Such information is not available at the moment via cAlgo.API. If you describe to us what you are up to, we might be able to propose a workaround.
Best Regards,
Panagiotis
@PanagiotisCharalampous