Asynchronously move SL and TP or close trades

Created at 22 Feb 2024, 11:08
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!
CT

ctid4921325

Joined 18.11.2023

Asynchronously move SL and TP or close trades
22 Feb 2024, 11:08


Hi there,

For my own trading, I layer/build/scale in with very small, but many trades to build an overall position, and then move stops to secure trades.  At the moment I can only workout how to iterate over these trades 1 at a time, and execute the move one position at a time', something like:


 

      private void MoveStopLosses(IEnumerable<Position> positions, double newPrice)
       {
           Debug("Entered move stoploss");
           foreach (var position in positions)
           {
               position.ModifyStopLossPrice(newPrice);
           }
        }

 

This some times takes several seconds across a batch of 20 or50 postions, by which stage the advantage is gone and a healthy win becomes a loss.

 

Is there something conceptually like:

 


        private void MoveStopLosses(IEnumerable<Position> positions, double newPrice)
        {
            Debug("Entered move stoploss");
            foreach (var position in positions)
            {
                position.AsyncModifyStopLossPrice(newPrice);

            }

        }

Or, spawning a way to spawn a thread of each modification so the queue of modifications isn't so deep and serial in nature.   Or perhaps  a way to submit a batch to the server ? or some thing else to acheive the same end?

Thanks


@ctid4921325
Replies

PanagiotisCharalampous
23 Feb 2024, 06:49

Hi there

ModifyPositionAsync should do the job

Best regards,

Panagiotis


@PanagiotisCharalampous

ctid4921325
23 Feb 2024, 11:27 ( Updated at: 24 Feb 2024, 07:36 )

RE: Asynchronously move SL and TP or close trades

PanagiotisCharalampous said: 

Hi there

ModifyPositionAsync should do the job

Best regards,

Panagiotis

Thank you Panagiotis,  That seems to do the trick.


@ctid4921325