StopLoss in EUR from manuel opened positions
StopLoss in EUR from manuel opened positions
19 Oct 2018, 18:35
Hi there .... I struggle getting the SL sum in EUR of all open positions.
I want to summarize all SL losses in EUR, to watch my maximum possible loss over all.
By using the function: Positions[i].StopLoss ... I get the price level of the SL each position, but I dont have a clue
how much it means in EUR. As far as I can see, there is even no function to figure out the SL pips of a position.
In the graph, if I hover the SL line, I can see the loss in EUR, I would like to have exaclty this amount summarized over all open positions in my bot / indicator.
Any ideas?
Replies
michael.kolb
20 Oct 2018, 21:05
( Updated at: 21 Dec 2023, 09:20 )
Hi freemangreat, thanks a lot for your example. I copied it and checked, but unfortunately it doesn't give the desired result.
Thing is, with manual opened positions, and arranged SL limites according to chart technik, I need to figure out the SL in pips.
In the code example, the pips are neccessary to be typed in:
[Parameter(DefaultValue = 10)]
public int StoplossLevel { get; set; }
If I would know the SL in pips, it would be easy to calculate the loss by (PositionOpenPrice - StoplossLevel * Symbol.PipSize)
But in this case, I need to figure out what the SL in pips are..... and I can't find a function. Hmm.
@michael.kolb
freemangreat
20 Oct 2018, 22:23
What?)) See line of code #41. And specify any price StopLoss price.
If you have difficulty in programming such elementary things, perhaps you better order or buy ready-made code.
@freemangreat
michael.kolb
21 Oct 2018, 20:37
RE:
Hi. I didn't want to type in the SL in pips into the indicator input field. Means it would be neccessary to adjust the input value everytime I move the SL line by hand.
The difficulty was to figure it out automatically, and summarize it over all open positions ... but I found the solution ... easier than I thougt ...
double maxLoss = 0.0;
for (int i = 0; i < Positions.Count; i++)
{
var lossPIPS = (double)(Positions[i].StopLoss - Positions[i].EntryPrice) * (1 / MarketData.GetSymbol(Positions[i].SymbolCode).PipSize);
var lossEUR = (double)(lossPIPS * MarketData.GetSymbol(Positions[i].SymbolCode).PipValue * Positions[i].VolumeInUnits);
maxLoss = maxLoss + lossEUR;
}
ChartObjects.DrawText("loss", "Current max. Loss over all: " + Math.Round(maxVerlust, 2), StaticPosition.TopCenter, Colors.Red);
Thanks for the help and replying to my request.
@michael.kolb
freemangreat
21 Oct 2018, 21:46
I have given a universal code for calculate profit / loss of position for any currency pair to ---> any currency (not only to the account currency).
Calculate in the account currency is certainly easier.
In your code, you do not use the side of trade (Buy/Sell).
@freemangreat
freemangreat
20 Oct 2018, 17:49
@freemangreat