Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

unable to change order

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

    unable to change order

    Click image for larger version

Name:	error.jpg
Views:	326
Size:	25.8 KB
ID:	1286612 I have created an EMA bounce strategy, with parabolic SL, however I find myself with the problem that I leave evidence in the image, consulting the forums I see that it is possible for very short SLs, however I lengthen the value of these and it continues to give me the same problem

    #2
    I add the code used



    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class ReboteParabolico : Strategy
    {
    private EMA EMA1;
    private HMA HMA1;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "ReboteParabolico";
    Calculate = Calculate.OnPriceChange;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 600;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.High;
    OrderFillResolutionType = BarsPeriodType.Minute;
    OrderFillResolutionValue = 1;
    Slippage = 0;
    StartBehavior = StartBehavior.WaitUntilFlat;
    TimeInForce = TimeInForce.Day;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 20;
    // Disable this property for performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = true;
    Inicio = DateTime.Parse("01:25", System.Globalization.CultureInfo.InvariantCulture) ;
    Fin = DateTime.Parse("16:00", System.Globalization.CultureInfo.InvariantCulture) ;
    EmaP = 50;
    HmaP = 50;
    Trailing = 80;
    }
    else if (State == State.Configure)
    {
    }
    else if (State == State.DataLoaded)
    {
    EMA1 = EMA(Close, Convert.ToInt32(EmaP));
    HMA1 = HMA(Close, Convert.ToInt32(HmaP));
    EMA1.Plots[0].Brush = Brushes.BurlyWood;
    HMA1.Plots[0].Brush = Brushes.Goldenrod;
    AddChartIndicator(EMA1);
    AddChartIndicator(HMA1);
    SetParabolicStop(CalculationMode.Ticks, Trailing);
    }
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1)
    return;

    // Set 1
    if (
    // InicioFin
    ((Times[0][0].TimeOfDay > Inicio.TimeOfDay)
    && (Times[0][0].TimeOfDay < Fin.TimeOfDay))
    && (Position.MarketPosition == MarketPosition.Flat)
    // Condition group 1
    && ((BarsSinceExitExecution(0, "", 0) == -1)
    || (BarsSinceExitExecution(0, "", 0) > 1))
    && (Close[1] > EMA1[1])
    && (Low[0] <= EMA1[0])
    && (HMA1[0] > EMA1[0])
    && (Open[0] > EMA1[0]))
    {
    Draw.ArrowUp(this, Convert.ToString(Close[0]), false, 0, (Low[0] - 5) , Brushes.DodgerBlue);
    BarBrush = Brushes.DodgerBlue;
    EnterLong(Convert.ToInt32(DefaultQuantity), "");
    }

    // Set 2
    if (
    // InicioFin
    ((Times[0][0].TimeOfDay > Inicio.TimeOfDay)
    && (Times[0][0].TimeOfDay < Fin.TimeOfDay))
    && (Position.MarketPosition == MarketPosition.Flat)
    // Condition group 1
    && ((BarsSinceExitExecution(0, "", 0) == -1)
    || (BarsSinceExitExecution(0, "", 0) > 1))
    && (Close[1] < EMA1[1])
    && (High[0] >= EMA1[0])
    && (HMA1[0] < EMA1[0])
    && (Open[0] < EMA1[0]))
    {
    Draw.ArrowDown(this, Convert.ToString(Close[0]), false, 1, (High[0] + 5) , Brushes.OrangeRed);
    BarBrush = Brushes.OrangeRed;
    EnterShort(Convert.ToInt32(DefaultQuantity), "");
    }

    }​

    Comment


      #3
      Hello Marioroa,

      Thanks for your notes.

      This error message indicates that you are changing an order to the wrong side of the market.

      Prints should be added to the script to understand exactly how your logic in the script is behaving. Add prints to the script that print out the logic being used to place orders and print out the order object in OnOrderUpdate() to see how the orders are evaluating and being placed. Also, enable TraceOrders to better understand how the orders are behaving.

      Below is a link to a forum post that demonstrates how to use prints to understand behavior.


      OnOrderUpdate(): https://ninjatrader.com/support/helpGuides/nt8/onorderupdate.htm​

      If this is due to market volatility then there isn't really a way to 100% avoid this occurring, as in volatile markets the market could move so far and fast that this would occur.

      Something you could consider is using GetCurrentBid() and GetCurrentAsk() to offset orders so that they are more likely to land on the correct side of the market.

      See these help guide pages for more information.
      GetCurrentBid(): https://ninjatrader.com/support/help...currentbid.htm
      GetCurrentAsk(): https://ninjatrader.com/support/help...currentask.htm

      You could also consider using RealtimeErrorHandling.IgnoreAllErrors to trap order errors in OnOrderUpdate by checking error == ErrorCode.UnableToChangeOrder.

      Please note that setting this property value to IgnoreAllErrors can have serious adverse affects on a running strategy unless you have programmed your own order rejection handling in the OnOrderUpdate() method. To do this you could trap the rejected order by checking if the OrderState is Rejected within OnOrderUpdate() followed by defining your own order rejection handling behavior for the rejected order.

      Please see the example in the help guide link below that demonstrates using RealtimeErrorHandling and trapping a rejected order in OnOrderUpdate().

      RealtimeErrorHandling — https://ninjatrader.com/es/support/h...orhandling.htm

      If you are backtesting the strategy in the Strategy Analyzer, you should also keep in mind that there is no intrabar granularity available. You could add intrabar granularity to the script by adding a 1-Tick data series to the script, submit orders to the 1-Tick secondary series, and enable Tick Replay.

      Please review the help guide document on the differences on real-time vs backtest (historical).


      ​See more information about granularity here: http://ninjatrader.com/support/forum...297#post491297
      <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

      Comment


        #4
        Gracias por todas tus observaciones y aportes. voy a probar y te dire los resultados. gracias

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        23 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        120 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        63 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        41 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        45 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X