Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

place at the same time as a strategy. EnterShortStopMarkEnterLongStopMark

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

    place at the same time as a strategy. EnterShortStopMarkEnterLongStopMark




    Hello, how could I solve it, it doesn't let me place an EnterShortStopMarket and an EnterLongStopMarket in a channel in case it breaks either of the two. how should I do it?

    This is the error


    An Enter() method to submit an entry order at '04/05/2024 08:30:00' has been ignored. Please search on the term 'Internal Order Handling Rules that Reduce Unwanted Positions' in the Help Guide for detailed explanation.


    //if (currentPrice > rectangleHigh)
    //{
    double buyStopPrice = rectangleHigh + 30 * TickSize;
    EnterLongStopMarket(0, true, 20, buyStopPrice, "");
    // SetStopLoss(CalculationMode.Price, rectangleLow);
    //}

    // Verificar si el precio rompe el rectángulo hacia abajo
    //if (currentPrice < rectangleLow)
    //{
    double sellStopPrice = rectangleLow - 30 * TickSize;
    EnterShortStopMarket(0, true, 20, sellStopPrice, "");
    SetStopLoss(CalculationMode.Price, rectangleLow);

    //}

    #2
    hi tks

    but none are active, I attach an image (I did it manually) of what I want to do but by code.
    create a buystopmarket above the price
    and a sellstopmarket below the price,
    and activate the one you touch first​

    Comment


      #3


      I am trying to apply the example.
      ERROR:
      4/05/2024 1:37:23 p. m. Default Strategy 'PushBot': Error on calling 'OnBarUpdate' method on bar 8610: Strategy 'PushBot/293945063': 'SubmitOrderUnmanaged' method can't be called on managed strategies.


      Code:
        if (State == State.SetDefaults)
                  {​
      
                   // other variables​
                      IsUnmanaged = true;
                      Print("IsUnmanaged: " + IsUnmanaged);
      
                  }​
      I created these two methods

      Code:
      protected override void OnOrderUpdate(Cbi.Order order, double limitPrice, double stopPrice,
                  int quantity, int filled, double averageFillPrice,
                  Cbi.OrderState orderState, DateTime time, Cbi.ErrorCode error, string comment)
              {
                  AssignOrderToVariable(ref order);
      
                  if ((longStopEntry != null && longStopEntry.OrderState == OrderState.Cancelled && shortStopEntry != null && shortStopEntry.OrderState == OrderState.Cancelled) || (order.Name == "Exit on session close" && order.OrderState == OrderState.Filled))
                  {
                      longStopEntry    = null;
                      shortStopEntry    = null;
                  }
              }
              
              private void AssignOrderToVariable(ref Order order)
              {
      
                  if (order.Name == "longStopEntry" && longStopEntry != order)
                      longStopEntry = order;
      
                  if (order.Name == "shortStopEntry" && shortStopEntry != order)
                      shortStopEntry = order;
              }
              ​
      I call him on the onbarupdate

      Code:
       if (currentBarTime.Date == CustomDate &&
                      currentBarTime.Hour == StartHour &&
                      currentBarTime.Minute == StartMinute &&
                      currentBarTime.Second == 0 &&
                      !rectangleValuesSet)
              {
                  // Calcular los precios del canal
                  double currentPrice = Closes[0][0];
                  rectangleHigh = currentPrice + ChannelOffset * TickSize;
                  rectangleLow = currentPrice - ChannelOffset * TickSize;
                  rectangleValuesSet = true; // Indicar que los valores del rectángulo han sido establecidos
      
                  // Dibujar el rectángulo con relleno amarillo
                  Draw.Rectangle(this, "ChannelRectangle", Time[1], rectangleHigh, Time[0], rectangleLow, Brushes.Yellow);
      
                  // Calcular precios de órdenes
                  double buyStopPrice = rectangleHigh + PriceOffset * TickSize;
                  double sellStopPrice = rectangleLow - PriceOffset * TickSize;
      
                  
                  if (longStopEntry == null && shortStopEntry == null)
                  {
      
                      ocoString        = string.Format("unmanagedentryoco{0}", DateTime.Now.ToString("hhmmssffff"));
                      longStopEntry    = SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.StopMarket, 1, 0, (High[0] + 200 * TickSize), ocoString, "longStopEntry");
                      shortStopEntry    = SubmitOrderUnmanaged(0, OrderAction.SellShort, OrderType.StopMarket, 1, 0, (Low[0] - 200 * TickSize), ocoString, "shortStopEntry");
                  }
              
                  SetTrailStop(CalculationMode.Ticks, Trailing);
      
                  if (Position.MarketPosition == MarketPosition.Short)
                  {
                      entryPrice = Close[0];
                  }
                  
              }​

      Comment


        #4
        Hello leojimenezp,

        Did you remove the strategy and re apply it after compiling with IsUnmanaged = true; ?

        Any changes to OnStateChange require that you remove the strategy instance and re apply it to see that change reflected.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        54 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        131 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        73 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        44 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        49 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X