How to make break-even price between buy & sell.

Created at 13 Jul 2015, 20:43
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
SA

SaifBD

Joined 05.01.2014

How to make break-even price between buy & sell.
13 Jul 2015, 20:43


I can make break even price only for buy and only for sell. Here's my code. But I can't make break even price between buy & sell together. Please help me. How can I make this?

        private double pnt_12(TradeType TrdTp)
        {
            double Result = 0;
            double AveragePrice = 0;
            long Count = 0;
            for (int i = Positions.Count - 1; i >= 0; i--)
            {
                position = Positions[i];
                if (position.Label == Label && position.SymbolCode == Symbol.Code)
                {
                    if (position.TradeType == TrdTp)
                    {
                        AveragePrice += position.EntryPrice * position.Volume;
                        Count += position.Volume;
                    }
                }
            }
            if (AveragePrice > 0 && Count > 0)
                Result = Math.Round(AveragePrice / Count, Symbol.Digits);
            return Result;
        }

 


@SaifBD
Replies

Spotware
14 Jul 2015, 10:34

Dear Trader,

We do not provide coding assistance services. We more than glad to assist you with specific questions about cAlgo.API. You also can contact one of our Partners or post a job in Development Jobs section for further coding assistance.


@Spotware

aysos75
14 Jul 2015, 21:41

RE:

SaifBD said:

I can make break even price only for buy and only for sell. Here's my code. But I can't make break even price between buy & sell together. Please help me. How can I make this?

        private double pnt_12(TradeType TrdTp)
        {
            double Result = 0;
            double AveragePrice = 0;
            long Count = 0;
            for (int i = Positions.Count - 1; i >= 0; i--)
            {
                position = Positions[i];
                if (position.Label == Label && position.SymbolCode == Symbol.Code)
                {
                    if (position.TradeType == TrdTp)
                    {
                        AveragePrice += position.EntryPrice * position.Volume;
                        Count += position.Volume;
                    }
                }
            }
            if (AveragePrice > 0 && Count > 0)
                Result = Math.Round(AveragePrice / Count, Symbol.Digits);
            return Result;
        }

 

This code

pnt_12(TradeType TrdTp)

calculate the average price oppositions of type TrdTp. What is the correspondance to Break Even ?


@aysos75