code error in calculations ??

Created at 12 Jul 2017, 17:19
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!
swingfish's avatar

swingfish

Joined 25.06.2016

code error in calculations ??
12 Jul 2017, 17:19


hopefully someone could help me ... 

 

this Algop is supposed to close all trades anddelete all orders 

once the target is reached.

but it was serval times the bot did close trades WAY too early .. with no appearent reason.

 

the function is startet OnTick

        private void closeWhenTarget(double target)
        {
            double profit = target;

            foreach (Position p in Positions)
                profit += p.NetProfit;

            // when profit is negative, we're done
            if (profit < target)
                return;

            // target is reached 
            foreach (Position p in Positions)
                ClosePosition(p);

            //  close all pending orders
            foreach (PendingOrder o in PendingOrders)
                CancelPendingOrder(o);


            // go sleep
            Stop();
        }

 


@swingfish
Replies

swingfish
13 Jul 2017, 00:47

never mind .. i figured it out . 

 

 double profit = target;

changed to 

 double profit = 0;

 

:)


@swingfish