total profit buy or sell

Created at 21 Apr 2015, 13:30
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!
TR

tradermatrix

Joined 24.07.2012

total profit buy or sell
21 Apr 2015, 13:30


hello
for a robot I use this method to cut my positions (a total gains):

 

   [Parameter(DefaultValue = 30)]
    public double totalgains { get; set; }

  var netProfit = 0.0;


            foreach (var openedPosition in Positions)
            {

                netProfit += openedPosition.NetProfit + openedPosition.Commissions;

            }

          if (Math.Abs(netProfit) >= totalgains)


                if (netProfit >= totalgains && totalgains != 0)
                {

                    foreach (var openedPosition in Positions)
                    {
                        ClosePosition(openedPosition);
                    }

/////////////////////////////////////////////////////////////////////

in this method it cut all the buy and sell positions.
I would like a method that separately cut a total buy and sell total.

  [Parameter(DefaultValue = 30)]
    public double totalBuy { get; set; }

  [Parameter(DefaultValue = 30)]
    public double totalSell { get; set; }

 

thank you for your help
cordially

 


@tradermatrix
Replies

mindbreaker
21 Apr 2015, 14:20

RE:

tradermatrix said:

hello
for a robot I use this method to cut my positions (a total gains):

 

   [Parameter(DefaultValue = 30)]
    public double totalgains { get; set; }

  var netProfit = 0.0;


            foreach (var openedPosition in Positions)
            {

                netProfit += openedPosition.NetProfit + openedPosition.Commissions;

            }

          if (Math.Abs(netProfit) >= totalgains)


                if (netProfit >= totalgains && totalgains != 0)
                {

                    foreach (var openedPosition in Positions)
                    {
                        ClosePosition(openedPosition);
                    }

/////////////////////////////////////////////////////////////////////

in this method it cut all the buy and sell positions.
I would like a method that separately cut a total buy and sell total.

  [Parameter(DefaultValue = 30)]
    public double totalBuy { get; set; }

  [Parameter(DefaultValue = 30)]
    public double totalSell { get; set; }

 

thank you for your help
cordially

 

Hi,

 

if(openedPosition.TradeType.Buy){

// todo with buy positions

}else{

// todo with sell positions

}

 

Bye.


@mindbreaker

tradermatrix
21 Apr 2015, 15:47

RE: RE:

mindbreaker said:

tradermatrix said:

hello
for a robot I use this method to cut my positions (a total gains):

 

   [Parameter(DefaultValue = 30)]
    public double totalgains { get; set; }

  var netProfit = 0.0;


            foreach (var openedPosition in Positions)
            {

                netProfit += openedPosition.NetProfit + openedPosition.Commissions;

            }

          if (Math.Abs(netProfit) >= totalgains)


                if (netProfit >= totalgains && totalgains != 0)
                {

                    foreach (var openedPosition in Positions)
                    {
                        ClosePosition(openedPosition);
                    }

/////////////////////////////////////////////////////////////////////

in this method it cut all the buy and sell positions.
I would like a method that separately cut a total buy and sell total.

  [Parameter(DefaultValue = 30)]
    public double totalBuy { get; set; }

  [Parameter(DefaultValue = 30)]
    public double totalSell { get; set; }

 

thank you for your help
cordially

 

Hi,

 

if(openedPosition.TradeType.Buy){

// todo with buy positions

}else{

// todo with sell positions

}

 

Bye.

thank you
You can develop your idea by using my example because malgres your explanation I have a hard time implementing it.
cordially.


@tradermatrix

mindbreaker
21 Apr 2015, 18:37

Look at this :

/forum/calgo-reference-samples/825

Bye.


@mindbreaker