Larger profits than expected with "OverAllPips", can't work out why?!?!

Created at 23 Feb 2015, 20:13
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!
97

9718853

Joined 14.10.2014

Larger profits than expected with "OverAllPips", can't work out why?!?!
23 Feb 2015, 20:13


Hi all,

 

I'm using the code below in a Robot that involves hedging... It calculates the total profit for all open positions and if that number is greater than (or equal to) my public parameter of 'OverAllPipsTP' the robot closes all open position and takes profit...

However, when my OverAllPipsTP parameter is met, the profits are often much greater than the parameter amount... Why?

EG: Set parameter to close all positions at 2500. Actual gain greater than 20,000 

double overallPips = 0;

            foreach (var position in Positions)
            {
                overallPips += position.Pips;

            }

            if (overallPips >= OverAllPipsTP)
            {
                Print("OVERALL PIP TOTAL = " + overallPips);

                foreach (var Position in Positions)
                {
                    Print("Closing All Positions. Num positions: " + Positions.Count);
                    ClosePosition(Position);         
                }
            }
        }
    }
}

 


@9718853
Replies

9718853
07 Mar 2015, 23:06 ( Updated at: 21 Dec 2023, 09:20 )

And now it actually posts a loss!!!

Now the same code is actually closing at a loss!!! How is this possible??

If the code only closes positions when the overall pip count is +2500 how on earth are the results below even possible?

 

 

 


@9718853

9718853
07 Mar 2015, 23:33 ( Updated at: 21 Dec 2023, 09:20 )

The results log states that the OverAllPipTP (take profit) level was met at 2501.7 so closed all positions at a loss of -48805 ?

 

 


@9718853

9718853
09 Mar 2015, 14:32

Fixed it, all good... : )


@9718853