Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Error on Order Submissions - Strategy with 3 Entries

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

    Error on Order Submissions - Strategy with 3 Entries

    Hello Ninjatrader Team,

    I am having problems with the Strategy Limit orders submission... The thing is that I want to make 3 Entries with different names:


    Code:
    if ((Pattern) //Bullish Pattern
                    && (Position.MarketPosition == MarketPosition.Flat)
                        && (UseTimeRange ? Time[1].TimeOfDay >= Start.TimeOfDay : true) //Trade is taking place within specified time
                        && (UseTimeRange ? Time[1].TimeOfDay <= End.TimeOfDay : true) //Trade is taking place within specified time
                            && (UseTradeCount ? currentCount < MaxTradeCount : true)
                                && (UseTimeRange ? dailyPnL > -DailyLossLimit : true) //Loss remains 'above' limit
                                && (UseTimeRange ? dailyPnL < DailyProfitLimit : true) //Profit remains 'below' limit
                    
                                    ///You will be able to enter 'short' after Profit/Stop from a long position. This just prevents entering right away in the same direction
                                    && (BarsSinceExitExecution("MyStopLong1") > 1 || BarsSinceExitExecution("MyStopLong1") == -1) //Needs 1 candle to enter Long again after being stopped from a long position.
                                    && (BarsSinceExitExecution("MyTargetLong1") > 1 || BarsSinceExitExecution("MyTargetLong1") == -1) //Needs 1 candle to enter Long again after hitting profit target from a long position.                
                    )
                {
                    
                    if (ActiveTrade_1)
                        {
                        EnterLong(Convert.ToInt32(PositionSize1), "MyEntryLong1");
                        }
                        
                    if (ActiveTrade_2)
                        {
                        EnterLong(Convert.ToInt32(PositionSize2), "MyEntryLong2");
                        }
                
                    if (ActiveTrade_3)
                        {
                        EnterLong(Convert.ToInt32(PositionSize3), "MyEntryLong3");
                        }​

    Then I code the Stop and Profits in OnMarketData:


    Code:
    protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
    {
    if (marketDataUpdate.MarketDataType == MarketDataType.Last)
    {
    
    
    if (Position.MarketPosition == MarketPosition.Long && myFreeTradeLong == true)
    
    {
    
    if (ProfitTarget)
    
    {
    
    if (ActiveTrade_1)
    {
    ExitLongLimit(0, true, Convert.ToInt32(PositionSize1), (Position.AveragePrice + (Target1 * TickSize)) , "MyTargetLong1", "MyEntryLong1");
    }
    
    if (ActiveTrade_2)
    {
    ExitLongLimit(0, true, Convert.ToInt32(PositionSize2), (Position.AveragePrice + (Target2 * TickSize)) , "MyTargetLong2", "MyEntryLong2");
    }
    
    if (ActiveTrade_3)
    {
    ExitLongLimit(0, true, Convert.ToInt32(PositionSize3), (Position.AveragePrice + (Target3 * TickSize)) , "MyTargetLong3", "MyEntryLong3");
    }
    
    Print(Convert.ToString(Times[0][0]) + " MyTargetLong SET" + " 1");
    }
    
    if (StopLoss)
    
    {
    
    if (ActiveTrade_1)
    {
    ExitLongStopMarket(0, true, Convert.ToInt32(PositionSize1), InitialStopLong, "MyStopLong1", "MyEntryLong1");
    }
    if (ActiveTrade_2)
    {
    ExitLongStopMarket(0, true, Convert.ToInt32(PositionSize2), InitialStopLong, "MyStopLong2", "MyEntryLong2");
    }
    if (ActiveTrade_3)
    {
    ExitLongStopMarket(0, true, Convert.ToInt32(PositionSize3), InitialStopLong, "MyStopLong3", "MyEntryLong3");
    }
    Print(Convert.ToString(Times[0][0]) + " MyStopLong SET" + " 2");
    }​

    Also I have my Breakeven and the Trailing Stop:

    Code:
    if(
    (Position.MarketPosition == MarketPosition.Long) //Has to be in a long position
    && (marketDataUpdate.Price >= BreakevenTargetPriceStore) //Price hits our breakeven trigger
    && (myFreeBELong == true) //BE bool is true -> Once its false, you can move your stop freely
    )
    {
    
    if (ActiveTrade_1)
    {
    ExitLongStopMarket(0, true, Convert.ToInt32(PositionSize1), (Position.AveragePrice + (BreakevenOffset * TickSize)) , "MyStopLong1", "MyEntryLong1");
    }
    
    if (ActiveTrade_2)
    {
    ExitLongStopMarket(0, true, Convert.ToInt32(PositionSize2), (Position.AveragePrice + (BreakevenOffset * TickSize)) , "MyStopLong2", "MyEntryLong2");
    }
    
    if (ActiveTrade_3)
    {
    ExitLongStopMarket(0, true, Convert.ToInt32(PositionSize3), (Position.AveragePrice + (BreakevenOffset * TickSize)) , "MyStopLong3", "MyEntryLong3");
    }
    
    
    
    
    
    
    
    
    if ((Position.MarketPosition == MarketPosition.Long)
                    && (myFreeTrail == true) //Bool needs to be true (Gets Reset with IsFirstTickOfBar to allow trail to occur on each new candle)
                    && (marketDataUpdate.Price >= AtrTargetPriceStore)
                    && (AtrStopSet > Position.AveragePrice)
                    && (AtrBool == false))
                    
                    {
                    AtrBool = true;
                    ProfitStopSet = true;
                    }
                
                if ((Position.MarketPosition == MarketPosition.Long)
                    && (IsFirstTickOfBar == true))
                    
                    {
                    AtrCurrentPrice = (ATR1[0] * AtrMultiply) ;
                    //Print(Convert.ToString(Times[0][0]) + " ATR Current Price:  " + Convert.ToString(AtrCurrentPrice) + "   7");
                    }
                
                if ((Position.MarketPosition == MarketPosition.Long)
                    && ((marketDataUpdate.Price - (AtrCurrentPrice))  > AtrStopSet)
                    && ((marketDataUpdate.Price - (AtrCurrentPrice))  < GetCurrentBid(0))
                    && ((marketDataUpdate.Price - (AtrCurrentPrice))  < GetCurrentAsk(0)))
                    
                    {
                        if (UseATRTrailing)
                            {
                            AtrStopSet = (Close[0] - (AtrCurrentPrice)) ;
                            //Print(Convert.ToString(Times[0][0]) + " ATR Stop SET: " + Convert.ToString(AtrStopSet) + "   8");
                            }        
                                
                    }
                
                if ((Position.MarketPosition == MarketPosition.Long)
                    && (AtrBool == true)
                    // Condition group 1
                    && (Low[1] > Low[2]) //Ensure the trail will only move up if the new candles low is higher.    
                    && ((ProfitStopSet == true)
                    || (IsFirstTickOfBar == true)))
                    
                    {
                        
                    if (ActiveTrade_1)
                        {    
                        ExitLongStopMarket(0, true, Convert.ToInt32(PositionSize1), AtrStopSet, "MyStopLong1", "MyEntryLong1");    
                        }
                        
                    if (ActiveTrade_2)
                        {    
                        ExitLongStopMarket(0, true, Convert.ToInt32(PositionSize2), AtrStopSet, "MyStopLong2", "MyEntryLong2");
                        }
                        
                    if (ActiveTrade_3)
                        {    
                        ExitLongStopMarket(0, true, Convert.ToInt32(PositionSize3), AtrStopSet, "MyStopLong3", "MyEntryLong3");
                        }​

    It works Perfect with the breakeven and the Trailing when you want to trade with 1 Entry, but when I want to use my 3 Entries, the strategy does Only Submits 1 Stop and 1 Profit Target... that makes the 2 remaining Entries keep going forever...

    See Image, it Only Submits 1 Stop and 1 Profit Target:

    Click image for larger version

Name:	image.png
Views:	126
Size:	74.8 KB
ID:	1298992

    Then when the Break Even activates, the strategy submits the 3 stop loss I wanted at the beginning too... when the profit target is reached then the trailing stop is activated with the remainig 2 entries:

    Click image for larger version

Name:	image.png
Views:	47
Size:	61.5 KB
ID:	1298993

    I have prints and TraceOrders = True so I can see what is happening in the order submissions, as you can see I get the error "SignalName does not have a matching FromEntrySignal to exit" but here you can see also that these orders have been previously Submitted.....

    WHY IS THAT I DO NOT SEE THEM IN THE CHART????





    ​Regarding this I have following questions:

    1 - Why does it submit the 3 Targets and Stops but then ignored?

    2 - Should I make ONLY 1 EntryLong with 3 contracts and then make the Profit and stop orders from this Entry? Why I cant make 3 separate Entries and work with each one as I tried?

    3 - How can I fix this ? Please explain the error detailed so this can help other users to understand what is happening.


    Please take into Account that:

    I am using OnEachTick Calculations because one of my Filters is the Volume (VOL).

    With the Sim101 works everything perfect but with the DEMO (LIVE) account is where I get this errors.

    Signal Names are Okey, can be that the name is "MyTargetLong1" and not @"MyTargetLong1"?? I tried to change that, it keeps working with these errors.




    Thanks a lot for your help, I would apreciate if anyone could help me to solve this.


    Trading Nasdaq


    Attached Files

    #2
    Here the Ninja Output with the Entry Submissions:



    Click image for larger version

Name:	image.png
Views:	39
Size:	145.5 KB
ID:	1298999

    Comment


      #3
      Hello tradingnasdaqprueba,

      Thank you for your post.

      "SignalName does not have a matching FromEntrySignal to exit"

      This happens if you use a FromEntrySignal for an order that does not match the SignalName of any working orders. You would need to go through your strategy and make sure that you use the correct FromEntrySignal for the appropriate SignalName of your Entry order. I don't see from the code you posted what the signal name are for your entry orders.


      If the expected trade(s) are not appearing, this would indicate that the condition to place the order is not evaluating as true and the order is not being submitted, or the order is being ignored for other reasons, or the order is being cancelled.

      To understand why the script is behaving as it is, such as placing orders or not placing orders when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

      In the strategy add prints (outside of any conditions) that print the date time of the bar and all values compared in every condition that places an order.

      The prints should include the time of the bar and should print all values from all variables and all hard coded values in all conditions that must evaluate as true for this action to be triggered. It is very important to include a text label for each value and for each comparison operator in the print to understand what is being compared in the condition sets.

      Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

      It is also helpful to set TraceOrders to true in State.Configure as well as print the order object in OnOrderUpdate().

      TraceOrders will output to the NinjaScript Output window a message when orders are being submitted, ignored, cancelled, or rejected.
      Printing the order object in OnOrderUpdate() will allow you to track the progression of the order from submitted, to working, to filled, cancelled, or rejected.

      These tools will let you know what happens to the order.

      TraceOrders - https://ninjatrader.com/support/help...raceorders.htm
      OnOrderUpdate() - https://ninjatrader.com/support/help...rderupdate.htm

      I am happy to assist you with analyzing the output from the output window.

      Run or backtest the script and when the output from the output window appears save this by right-clicking the output window and selecting Save As... -> give the output file a name and save -> then attach the output text file to your reply.

      Below is a link to a forum post that demonstrates using informative prints to understand behavior and includes a link to a video recorded using the Strategy Builder to add prints.


      Please let me know if I may further assist with analyzing the output or if you need any assistance creating a print or enabling TraceOrders.​
      Gaby V.NinjaTrader Customer Service

      Comment


        #4
        Hello Gaby,

        Definetly is not the code, and also not the Order names... I have prints everywhere and as you can see I activated the TraceOrders.

        Here is something beyond all that... Is very strange because I made some minimal changes and started working properly on real time... then changed from OnPriceChange to OnEachTick and was not working properly again...

        Can this be ninjatrader? Should I download the Strategy and try to upload again and see if it works?


        Here the order names:

        if (ActiveTrade_1)
        {
        EnterLong(Convert.ToInt32(PositionSize1), "MyEntryLong1");
        }

        if (ActiveTrade_2)
        {
        EnterLong(Convert.ToInt32(PositionSize2), "MyEntryLong2");
        }

        if (ActiveTrade_3)
        {
        EnterLong(Convert.ToInt32(PositionSize3), "MyEntryLong3");
        }​


        if (ActiveTrade_1)
        {
        ExitLongLimit(0, true, Convert.ToInt32(PositionSize1), (Position.AveragePrice + (Target1 * TickSize)) , "MyTargetLong1", "MyEntryLong1");
        }

        if (ActiveTrade_2)
        {
        ExitLongLimit(0, true, Convert.ToInt32(PositionSize2), (Position.AveragePrice + (Target2 * TickSize)) , "MyTargetLong2", "MyEntryLong2");
        }

        if (ActiveTrade_3)
        {
        ExitLongLimit(0, true, Convert.ToInt32(PositionSize3), (Position.AveragePrice + (Target3 * TickSize)) , "MyTargetLong3", "MyEntryLong3");
        }​


        if (ActiveTrade_1)
        {
        ExitLongStopMarket(0, true, Convert.ToInt32(PositionSize1), (Position.AveragePrice + (BreakevenOffset * TickSize)) , "MyStopLong1", "MyEntryLong1");
        }

        if (ActiveTrade_2)
        {
        ExitLongStopMarket(0, true, Convert.ToInt32(PositionSize2), (Position.AveragePrice + (BreakevenOffset * TickSize)) , "MyStopLong2", "MyEntryLong2");
        }

        if (ActiveTrade_3)
        {
        ExitLongStopMarket(0, true, Convert.ToInt32(PositionSize3), (Position.AveragePrice + (BreakevenOffset * TickSize)) , "MyStopLong3", "MyEntryLong3");
        }



        THANKS!!!

        Comment


          #5
          Hello,

          Thank you for your response.

          I am not seeing any prints in your script code nor the provided output. The prints should include the time of the bar and should print all values from all variables and all hard coded values in all conditions that must evaluate as true for this action to be triggered, this information is not included in your script nor the output.

          The screenshot you provided of the output also has a portion cut off. It's possible that your script is trying to submit the exit orders before the associated entry order is submitted, so the signal names are "not matching".

          Changing the Calculate setting can definitely drastically effect your strategy. You need to code your strategy with the Calculate setting in mind since this affects how often OnBarUpdate() is called.



          You will need to provide the output from both the prints and TraceOrders so we can see what is happening at the date/time stamps you are seeing the unexpected behavior.

          Please let us know if you have any assistance creating prints or enabling TraceOrders.
          Gaby V.NinjaTrader Customer Service

          Comment


            #6
            Hello Gaby,

            I tried it for 2 week, believe me I tried... but I don't know where the problem is... so I will Explain what I am doing so maybe you find something I am doing wrong:

            I use Volume as a filter so I calculate OnEachTick and also have 3 different entries with 3 profits at different levels, which can be activated and deactivated to configure everything as you wish.

            The thing is, it seemed like everything was working fine until I noticed in real-time that the stop and profit orders weren't being submitted or some yes but 2 not... so I took a closer look tracing the orders and I got the problem that "SignalName does not have a matching FromEntrySignal to exit", but they have...

            It is so strange... because in Backtesting and Sim works everything fine... Can be the volatility of the Market? I don't know how to solve this...

            I dont know how to fix this, I have been with this for 2 weeks trying everything but I can't figure it out... I will attached some images so you can see better what I am talking about... If you could help me with this I would very appreciated!!! Thanks!

            Attached you can find all the code.


            PLAYBACK: As you can see everything works fine...

            Click image for larger version  Name:	image.png Views:	0 Size:	60.4 KB ID:	1301492Click image for larger version  Name:	image.png Views:	0 Size:	71.6 KB ID:	1301493




            REAL-TIME: Lots of errors come out in the Output where I trace the orders...

            Click image for larger version  Name:	image.png Views:	0 Size:	74.8 KB ID:	1301494
            Click image for larger version  Name:	image.png Views:	0 Size:	254.9 KB ID:	1301495
            Last edited by tradingnasdaqprueba; 04-29-2024, 03:53 PM.

            Comment


              #7
              Hello,

              Thank you for your response.

              Can you please provide the full output text file instead of a screenshot? Right-click within the output window > Save As to save the the output text file.

              Additionally, your output does not show any information from print statements. In the strategy add prints (outside of any conditions) that print the date time of the bar and all values compared in every condition that places an order.

              The prints should include the time of the bar and should print all values from all variables and all hard coded values in all conditions that must evaluate as true for this action to be triggered. It is very important to include a text label for each value and for each comparison operator in the print to understand what is being compared in the condition sets.

              If you need assistance creating a print, please let me know. ​


              Based on the output provided, it seems like MyEntryShort2 was never submitted, so no exit order could be attached to the non-existent entry order. The full output text file and the prints will help determine why this entry was never submitted.
              Gaby V.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by PrTester, 12-29-2008, 05:27 PM
              131 responses
              96,700 views
              0 likes
              Last Post diegomezhur  
              Started by knowmad, 05-07-2024, 03:52 AM
              6 responses
              62 views
              0 likes
              Last Post knowmad
              by knowmad
               
              Started by xepher101, 05-10-2024, 12:19 PM
              9 responses
              115 views
              0 likes
              Last Post jeronymite  
              Started by tkaboris, Today, 07:53 PM
              0 responses
              4 views
              0 likes
              Last Post tkaboris  
              Started by JGriff5646, Yesterday, 05:47 PM
              2 responses
              23 views
              0 likes
              Last Post JGriff5646  
              Working...
              X