Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Submit purchase and sales orders at the same time

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Submit purchase and sales orders at the same time

    Hello, I am building a strategy that allows me to send a buy and sell order at the same time in separate price levels controlled by an indicator, when one of the two is executed the other is canceled. If I assign shortEntry the value of DistancePrice1.UpperLine and longEntry the value DistancePrice1.LowerLine, the orders are sent perfectly, only that there the buy order is below the price and the sell order above the price, and I want the opposite that the buy order is above and the sell order below, if I change the entry prices when activating they are ignored and only execute sales at wrong levels.

    How can I fix it?​

    Code:
    protected override void OnBarUpdate()
            {        
                if (CurrentBar < BarsRequiredToTrade)
                    return;
                
                FiltroHorario = false;
                
                #region Filtro horario
                if ((Times[0][0].TimeOfDay >= HoraInicio.TimeOfDay) && (Times[0][0].TimeOfDay < HoraFin.TimeOfDay))
                    {
                        FiltroHorario = true;
                    }
                #endregion // filtro horario para tomar entradas
                
                if (Position.MarketPosition == MarketPosition.Flat && FiltroHorario)
                {
                    CancelOrder(shortEntry);
                    CancelOrder(longEntry);
                    insideS3R3 = false;
                    doitonce = true;
                    
                    if (DistancePrice1.LowerLine[0] > 0)
                    {
                        brac****COID    = Guid.NewGuid().ToString();
                        shortEntry         = SubmitOrderUnmanaged(0, OrderAction.SellShort, OrderType.StopMarket, OrderQuantity, DistancePrice1.LowerLine[0], 0, brac****COID , "Short limit entry");
                        longEntry         = SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.StopMarket, OrderQuantity, DistancePrice1.UpperLine[0], 0, brac****COID, "long limit entry");
                        insideS3R3 = true;
                    }    
                    
                    if (!insideS3R3 && doitonce)
                    {
                        if (CrossBelow(Close, DistancePrice1.LowerLine, 1) && shortEntry == null)
                        {
                            doitonce = false;
                            shortEntry = SubmitOrderUnmanaged(0, OrderAction.SellShort, OrderType.Market, OrderQuantity, 0, 0, "", "short Market entry");                
                            if (longEntry != null)
                                CancelOrder(longEntry);
                        }
                        
                        if (CrossAbove(Close, DistancePrice1.UpperLine, 1) && longEntry == null)
                        {
                            doitonce = false;
                            longEntry = SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.Market, OrderQuantity, 0, 0, "", "Long market entry");    
                            if (shortEntry != null)
                                CancelOrder(shortEntry);
                        }
                    }
                }            
            }​​

    #2
    Hello Geovanny Suaza,

    Are you sure that you are submitting the correct type of orders? You can use the chart trader to make the chart show the correct type of orders. After opening the chart trader you can right click on the chart above or below the current price to see which order types go on each side of the market.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    87 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    132 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    65 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    118 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    67 views
    0 likes
    Last Post PaulMohn  
    Working...
    X