Number of positions open at a time
Number of positions open at a time
24 Feb 2016, 16:21
Hi,
what command is there to use, to tell robot I want to have a number of maximum x positions open at one time for an account and for s
Also what happens when I use this command, while there have already been executing more than x positions. Would they be closed?
Thanks.
Regards.
Replies
davidbtosh
10 Mar 2016, 14:22
Here is a quick example of how you might do this. You need to put the cAlgo API ExecuteMarketOrder() method in a "wrapper"
You then only ever call the wrapper method. Here is my implementation of a wrapper method for this
private const string botName = "MyBotName"; //these could be parameters
private const int positionsLimit = 3;
private TradeResult ExecuteMarketOrderLimited(TradeType tt, long vol, double? slPips, double? tpPips)
{
TradeResult result = null;
try
{
List<Position> posList = Positions.FindAll(botName).ToList();
Position pos = null;
if (posList.Count < positionsLimit)
{
result = ExecuteMarketOrder(tt, Symbol, vol, botName, slPips, tpPips);
if (result.IsSuccessful)
{
pos = result.Position;
Print("Position entry price is {0}", pos.EntryPrice);
}
else
{
Print("Execution unsuccessful.");
}
}
else
{
Print("Set position limit of {0} reached. Execution unsuccesful.", positionsLimit);
}
}
catch (Exception e)
{
//handle error
//log
//exit
Print("Error: {0}", e.Message);
}
return result;
}
@davidbtosh
davidbtosh
10 Mar 2016, 14:24
RE:
This looks better
private const string botName = "MyBotName"; //these could be parameters private const int positionsLimit = 3; private TradeResult ExecuteMarketOrderLimited(TradeType tt, long vol, double? slPips, double? tpPips) { TradeResult result = null; try { List posList = Positions.FindAll(botName).ToList(); Position pos = null; if (posList.Count < positionsLimit) { result = ExecuteMarketOrder(tt, Symbol, vol, botName, slPips, tpPips); if (result.IsSuccessful) { pos = result.Position; Print("Position entry price is {0}", pos.EntryPrice); } else { Print("Execution unsuccessful."); } } else { Print("Set position limit of {0} reached. Execution unsuccesful.", positionsLimit); } } catch (Exception e) { //handle error //log //exit Print("Error: {0}", e.Message); } return result; }
@davidbtosh
1007601
28 Mar 2016, 13:58
RE:
croucrou said:
Thanks for your reply. I regret it is not possible to do within just one line.
I try to have a "bool" condition that matches the conditions for entry...
ie.
if (c1 & c2 & c3 & c4 ... & c6)
{
do that thing!
}
; so one of the "bool" conditions could be
bool c5 = positions.Count < 100;
So that would mean all the conditions need to be met, ONE of them being the positions.count is less than your value; in this case I said 100.
I'm never sure if it looks clumsier in script or not; its functional for me...
GH
@1007601
Waxy
29 Feb 2016, 20:05
Hello,
You should try:
@Waxy