Sum positions open
11 Oct 2014, 11:04
I need a variable that returns the sum of the open positions with a specific label. I do a example to be clear:
- positions open 1 => var nPos = 1
- positions open 2 => var nPos = 1 + 2 = 3
- positions open 3 => var nPos = 1 + 2 + 3 = 6
- positions open 4 => var nPos = 1 + 2 + 3 + 4 = 10
ecc.
How can I fix?
Replies
breakermind
11 Oct 2014, 12:25
RE: RE:
or
protected override void OnTick()
{
double nPos = 0;
double gPos = 0;
int count = 0;
int sum = 0;
var AllPositions = Positions;
foreach (var position in AllPositions)
{
if (position.Label == MyLabel)
{
nPos += position.NetProfit;
gPos += position.GrossProfit;
count++;
sum = sum + count;
}
}
Print("Net: " + nPos + " Gros: " + gPos + " Count: " + count + " sum: " + sum);
}
Bye.
@breakermind
breakermind
11 Oct 2014, 12:26
RE: RE: RE:
using cAlgo.API;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC)]
public class LabelsSample : Robot
{
[Parameter("Buy", DefaultValue = true)]
public bool TradeTypeBuy { get; set; }
[Parameter(DefaultValue = "label666")]
public string MyLabel { get; set; }
[Parameter(DefaultValue = 100000)]
public int Volume { get; set; }
[Parameter("Stop Loss (pips)", DefaultValue = 100)]
public int StopLoss { get; set; }
[Parameter("Take Profit (pips)", DefaultValue = 100)]
public int TakeProfit { get; set; }
[Parameter(DefaultValue = 15)]
public int MaxPositions { get; set; }
protected TradeType cBotTradeType
{
get { return TradeTypeBuy ? TradeType.Buy : TradeType.Sell; }
}
protected override void OnTick()
{
double nPos = 0;
double gPos = 0;
int count = 0;
int sum = 0;
var AllPositions = Positions;
foreach (var position in AllPositions)
{
if (position.Label == MyLabel)
{
nPos += position.NetProfit;
gPos += position.GrossProfit;
count++;
sum = sum + count;
}
}
Print("Net: " + nPos + " Gros: " + gPos + " Count: " + count + " sum: " + sum);
}
protected override void OnBar()
{
if (Positions.Count < MaxPositions)
{
ExecuteMarketOrder(cBotTradeType, Symbol, Volume, MyLabel, StopLoss, TakeProfit);
ExecuteMarketOrder(cBotTradeType, Symbol, Volume, "LabeFake", StopLoss, TakeProfit);
}
}
}
}
@breakermind
Forex19
11 Oct 2014, 13:21
RE: RE:
Hi, meantime thanks.
I had tried something like this as well but I've noticed that the var count and sum remain at the maximum value. Example:
If MaxPositions = 4
- positions open 1 => count = 1 , sum = 1
- positions open 2 => count = 2 , sum = 3
- positions open 3 => count = 3 , sum = 6
- positions open 4 => count = 4 , sum = 10
then
- positions open 1 => count = 4 , sum = 10
- positions open 2 => count = 4 , sum = 10
- positions open 3 => count = 4 , sum = 10
ecc, ecc.
Why?
breakermind said:
protected override void OnTick()
{
double nPos = 0;
double gPos = 0;
int count = 0;
int sum = 0;
var AllPositions = Positions;
foreach (var position in AllPositions)
{
if (position.Label == MyLabel)
{
nPos += position.NetProfit;
gPos += position.GrossProfit;
count++;
sum = sum + count;
}
}
Print("Net: " + nPos + " Gros: " + gPos + " Count: " + count + " sum: " + sum);
}
@Forex19
breakermind
11 Oct 2014, 14:00
RE: RE: RE:
using cAlgo.API;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC)]
public class LabelsSample : Robot
{
[Parameter("Buy", DefaultValue = true)]
public bool TradeTypeBuy { get; set; }
[Parameter(DefaultValue = "label666")]
public string MyLabel { get; set; }
[Parameter(DefaultValue = 100000)]
public int Volume { get; set; }
[Parameter("Stop Loss (pips)", DefaultValue = 100)]
public int StopLoss { get; set; }
[Parameter("Take Profit (pips)", DefaultValue = 100)]
public int TakeProfit { get; set; }
[Parameter(DefaultValue = 15)]
public int MaxPositions { get; set; }
public int sum = 0;
public int count = 0;
protected TradeType cBotTradeType
{
get { return TradeTypeBuy ? TradeType.Buy : TradeType.Sell; }
}
protected override void OnTick()
{
double nPos = 0;
double gPos = 0;
var AllPositions = Positions;
foreach (var position in AllPositions)
{
if (position.Label == MyLabel)
{
nPos += position.NetProfit;
gPos += position.GrossProfit;
if (count < 4)
{
count++;
sum = sum + count;
}
}
}
Print("Net: " + nPos + " Gros: " + gPos + " Count: " + count + " sum: " + sum);
}
protected override void OnBar()
{
if (Positions.Count < MaxPositions)
{
ExecuteMarketOrder(cBotTradeType, Symbol, Volume, MyLabel, StopLoss, TakeProfit);
ExecuteMarketOrder(cBotTradeType, Symbol, Volume, "LabeFake", StopLoss, TakeProfit);
}
}
}
}
maybe something like this
@breakermind
Forex19
11 Oct 2014, 14:22
RE: RE: RE: RE:
The problem is that var count and var sum don't reset when the positions are closed and then start again.
breakermind said:
:::::::::::::::: protected override void OnTick() { double nPos = 0; double gPos = 0; var AllPositions = Positions; foreach (var position in AllPositions) { if (position.Label == MyLabel) { nPos += position.NetProfit; gPos += position.GrossProfit; if (count < 4) { count++; sum = sum + count; } } } Print("Net: " + nPos + " Gros: " + gPos + " Count: " + count + " sum: " + sum); }
maybe something like this
@Forex19
breakermind
11 Oct 2014, 15:17
RE: RE: RE: RE: RE:
Forex19 said:
The problem is that var count and var sum don't reset when the positions are closed and then start again.
breakermind said:
:::::::::::::::: protected override void OnTick() { double nPos = 0; double gPos = 0; var AllPositions = Positions; foreach (var position in AllPositions) { if (position.Label == MyLabel) { nPos += position.NetProfit; gPos += position.GrossProfit; if (count < 4) { count++; sum = sum + count; } } } Print("Net: " + nPos + " Gros: " + gPos + " Count: " + count + " sum: " + sum); }
maybe something like this
this reset on each tick
protected override void OnTick()
{
double nPos = 0;
double gPos = 0;
int count = 0;
int sum = 0;
var AllPositions = Positions;
foreach (var position in AllPositions)
{
if (position.Label == MyLabel)
{
nPos += position.NetProfit;
gPos += position.GrossProfit;
count++;
sum = sum + count;
}
}
Print("Net: " + nPos + " Gros: " + gPos + " Count: " + count + " sum: " + sum);
}
btw.
pending order each 100 pip up or down(GBPJPY,GBPNZD,...) from week open price and wait, dont waste the time :] one order in right direction in week it is good pips profit :]
@breakermind
emeeder
15 Oct 2014, 02:49
Hi Breakermind.
Have you ever backtested your 100pip Up/Down pending order strategy?
Do you always take profit/ loss at Week close price?
I guess you only get losses at trend change hammer candles or shooting star candles.
breakermind
15 Oct 2014, 14:16
RE:
Hi,
I'm talking about manual trading. cbots its a waste of time, always something is not working on these platforms (the same result it is difficult to get in this same period, and this is just math).
Bye.
@breakermind

breakermind
11 Oct 2014, 12:21
RE:
Hi,
protected override void OnTick() { double nPos = 0; double gPos = 0; int count = 0; var AllPositions = Positions; foreach (var position in AllPositions) { if (position.Label == MyLabel) { nPos += position.NetProfit; gPos += position.GrossProfit; count++; } } Print("Net: " + nPos + " Gros: " + gPos + " Count: " + count); }Bye.
@breakermind