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 NullPointStrategies, Today, 05:17 AM
    0 responses
    50 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    126 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    69 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    42 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X