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.
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by rubiijonson, Today, 01:02 AM
    0 responses
    4 views
    0 likes
    Last Post rubiijonson  
    Started by fkronloff, Today, 12:25 AM
    0 responses
    3 views
    0 likes
    Last Post fkronloff  
    Started by Zadomani, Yesterday, 11:39 PM
    0 responses
    11 views
    0 likes
    Last Post Zadomani  
    Started by ToNovy, 01-27-2025, 11:22 PM
    20 responses
    197 views
    0 likes
    Last Post ToNovy
    by ToNovy
     
    Started by hypercube, 03-07-2025, 12:22 AM
    2 responses
    38 views
    0 likes
    Last Post hypercube  
    Working...
    X