on position closed problem

Created at 06 Jul 2016, 21:45
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!
RC

rcc25

Joined 04.01.2013

on position closed problem
06 Jul 2016, 21:45


Hi All

I need some help I made robot and works great but it makes only one cycle

I found that my code in section: on position closed its wrong

I want to perform 3 tasks on position closed:

 

1 close all positions

2 cancel all pending orders

3 execute market order(same as on start section) if positions count < 1 (this part doesn`t work at all or robot goes in loop contantly opening and closing positions every tick)

 

 

check my code please and advice:

 

private void OnPositionsClosed(PositionClosedEventArgs args)
        {

            foreach (var position in Positions)
            {
                ClosePosition(position);
            }
            foreach (var order in PendingOrders)
            {
                CancelPendingOrder(order);
            }
            if (Positions.Count < 1)
            {
                ExecuteOrder(InitialVolume, GetRandomTradeType());
            }



        }

  thx 

 

Raf


@rcc25
Replies

... Deleted by UFO ...

rcc25
07 Jul 2016, 12:50

on position closed problem

Thx for your help Lucian

I checked your idea but it doesn`t work as it should - robot logic is changed makes to many orders

I also checked onBar function but its the same results

I think async execution may help but I am trader not programmer no idea how to use it

 

I managed to move order execution to other cbot and it works perfect

however i cant back test two robots in same time  to adjust settings

if any one has other ideas please help

THX


@rcc25