how can to close all position in the same of two symbols please i want close in the same if simbol1 take a profit i want that simbol2 close in the same I

Created at 29 Feb 2024, 09: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!
VI

vinc.lomiglio

Joined 19.06.2018

how can to close all position in the same of two symbols please i want close in the same if simbol1 take a profit i want that simbol2 close in the same I
29 Feb 2024, 09:13


//ENTRATE_LONG
                    if ((FastResultL >= 0) 
                        var q = Symbol.QuantityToVolumeInUnits(quantity);

                        var q_2 = Symbol.QuantityToVolumeInUnits(quantity_2);
                     

                        tradeOperation = ExecuteMarketOrderAsync(TradeType.Buy, Symbol1, q, etichettaOperazioni_simbolo1 , StopLoss_Long, TakeProfit_Long);
                        
                        tradeOperation = ExecuteMarketOrderAsync(TradeType.Sell, Symbol2, q_2, etichettaOperazioni_simbolo2, StopLoss_Short, TakeProfit_Short);
                        
                        Print("ORDINI long short INVIATI");
                        //Print("Positions Count:" + Positions.Count); 
                        //tradeOperation = ExecuteMarketOrderAsync(TradeType.Sell, Symbol2, q_2, etichettaOperazioni);
                        
                        tradeType = 1;
                        openedPositions++;
                        nOp++;
                        //Print("Position  LONG is opened");
                    }


@vinc.lomiglio
Replies

firemyst
05 Mar 2024, 03:00 ( Updated at: 05 Mar 2024, 06:44 )

foreach (Position p in Positions)
{
    if (p.SymbolName == "whatever symbol you want to close")
        ClosePosition(p);
}

@firemyst