Replies

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

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