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

interested in collaboration with other users to refine some code.

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

    #31



    people with nt,



    the text files with the nt output are in the zip file i uploaded in the previous post as an attachment, and on this post as well.


    the pullback entry reported on 20-03-2020 at 14:02 ended up in a loss of $388 usd, when the stop loss order in the strategy should keep the maximum loss at $42 usd.


    and other entries end up in losses far larger than what the stop loss should keep them to. in this particular case there are only 7 trades with very large losses, but with other strategies i have there are a very high number of such losses above what the stop loss orders should keep them to.


    i'm trying to define a maximum risk for the initial entry, and if there is an attractive pullback, to add an additional contract, but always keeping the monetary value at risk the same. obviously, if the stop loss orders are not working, then this completely defeats this idea.






    Attached Files

    Comment


      #32
      Hello rtwave,

      I'm seeing in the output that the order pustlopuen01 may be getting ignored. (Ignored order TraceOrder messages appear after the first violation and tend not to show for subsequent violations)

      05/03/2021 17:00:00 Strategy 'onorderupdatetests001/-1': Entered internal SubmitOrderManaged() method at 05/03/2021 17:00:00: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=2196.9 SignalName='pustlopuen01' FromEntrySignal='lopuen01'
      05/03/2021 17:00:00 Strategy 'onorderupdatetests001/-1': Ignored SubmitOrderManaged() method at 05/03/2021 17:00:00: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=2196.9 SignalName='pustlopuen01' FromEntrySignal='lopuen01' Reason='Invalid order price, please see log tab'

      This order was ignored once, which implies that it is may be ignored many times, and may have been ignored at on 20-03-2020 at 14:00 as the order is never accepted and does not become working.

      20/03/2020 14:00:00 Strategy 'onorderupdatetests001/-1': Entered internal SubmitOrderManaged() method at 20/03/2020 14:00:00: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=1037.4 SignalName='pustlopuen01' FromEntrySignal='lopuen01'
      20/03/2020 17:00:00 Strategy 'onorderupdatetests001/-1: Cancelled pending exit order, since associated position is closed, orderId='NT-00049-25680' account='Backtest' name='pustlopuen01' orderState=Working instrument='M2K 09-21' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=1037.4 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2020-03-20 14:00:00' gtd='2099-12-01' statementDate='2021-09-12'

      Is pustlopuen01 being submitted from OnExecution() when the entry lopuen01 fills, or is this being submitted in OnBarUpdate()?
      (It looks like the stop is being submitted one hour later, which would imply Calculate is OnBarClose and the order is being submitted from OnBarUpdate())

      Are you confirming that the sell stop price is at least 1 tick less than GetCurrentBid() at the time the stop is submitted?
      Chelsea B.NinjaTrader Customer Service

      Comment


        #33



        NinjaTrader_ChelseaB, people with nt,



        thanks a lot.


        this information you have posted is fantastic. i can't believe that it has only taken me since the middle of march and then the last 45 days to achieve all this progress. jaja.


        anyway, all joking aside, it is possible that the problem for my pullback strategies is the structure i have been using:


        - ordinary entries and exits are generated by large bars (10 minute bars) on a bar in progress = 0 subsection of onbarupdate.

        - in the other bar in progress = 1 subsection of onbarupdate, (and on a secondary data series of 1 minute bars) i have the logic to identify pullbacks (ticks higher or lower from averageprice) as well as time conditions of when to trade, liquidate and restore positions.

        - on the onorderandexecutionupdate sections i have just orders and executions.



        the notation i use should be self explanatory, lopuen01 is long pullback entry, pustlopuen01 is pullback stop loss long pullback entry.


        ordinary entries and exits are dictated by large bars in a bar in progress = 0 subsection of onbarupdate and their order objects should associate stop loss orders with every entry on the order and execution methods. pullback entries are generated in a 1 minute bars series and they should also include stop loss orders for every pullback entry.


        if i knew of any better structures to use i would definitely use them.


        this disparity between data intervals and series can easily be the cause for stop loss orders failing every time a second entry is generated. pullback entries do work just as intended, but these entries will cause all stop loss orders to somehow stop working.



        and also, the entire purpose of these strategies is that once a pullback entry is generated, the stop loss orders for all entries (the entire position) should be set at the same level and all the contracts managed in parallel. the objective is to add one additional contract while keeping the total risk for the position the same.


        it seemed to me that i could just redefine the stop loss order for the initial - ordinary entry in the execution method at the same time i was defining the stop loss for the pullback entry but that was not working either so i have disabled that one line as things were even worse when using that code.


        else if (execution.Order.OrderState == OrderState.Filled && shpuenorsufi == execution.Order.Filled && marketPosition == MarketPosition.Short)
        {
        shpuenstor = ExitShortStopMarket(0, true, execution.Order.Filled, execution.Order.AverageFillPrice + ( Costlonuti * TickSize ), "pustshpuen01", "shpuen01");
        // shorenstor = ExitShortStopMarket(0, true, execution.Order.Filled, execution.Order.AverageFillPrice + ( Costlonuti * TickSize ), "pustshoren01", "shoren01");
        }



        from this information that nt support has provided, i will now try to think of ways to place the logic for pullbacks inside the same bar in progress = 0 subsection of onbarupdate. if i manage to make this modification i will report whether the performance of my strategies improves.



        very well, thanks, regards.

        Comment


          #34
          Hello rtwave,

          The TraceOrders and prints output can really tell us a lot, and where to look for issues or mechanisms.

          Below are links to some examples that submit protective exit orders in OnExecution().
          https://ninjatrader.com/support/foru...269#post802269

          One other note, if this is historical data, intra-bar granularity of 1 tick would also be necessary for order fill accuracy and intra-bar fills.
          https://ninjatrader.com/support/foru...377#post773377
          Chelsea B.NinjaTrader Customer Service

          Comment


            #35



            people with nt,



            i have been thinking about these strategies.


            trying to have the logic to monitor pullbacks and generate pullback entries on the larger bar section will not work. 1 minute intervals are reasonable if one wants to generate a secondary entry when the profit loss for an initial entry is between 80 and 200 ticks against this entry. however, 10 minute bars or larger could fail frequently if price is made to trade inside this interval and then out of it.



            i have taken a look at all the samples nt makes available but the same logic used to illustrate those samples does not work in this strategy.


            in post 0023 in this thread, i have proven that exit orders will work fine for two entries if they happen at the same time. i have done several tests and in most cases, exit orders work without problem for two entries. if i disable the pullback entry, exit stop loss orders work flawlessly, if i have two simultaneous entries, exit stop loss orders will also work flawlessly.


            however, in these strategies i haven't been able to get to work, i try to make the secondary entry dependent on the profit - loss of the initial entry and this seems to cause the platform or the backtesting - optimizing engine to malfunction. i attach once again the latest version of the strategy that does not work for the people with nt to take a look at. i have been using the same samples nt makes available and the only change of relevance is to have a secondary entry that depends on the profit - loss of an initial entry, it is this that will cause stop loss exit orders to be ignored.


            and the information that the people with nt were able to obtain for the logs i uploaded previously does not make sense. the platform generates an entry and a stop loss order at 17:00 hours, by which time the session is over. and even if the session being over was the cause for all the multiple entries that are left without stop loss orders, the other pullback strategies i have been working on do have time limitations to stop generating entries minutes before the end of the session and to liquidate all positions around 16:43 every day and these malfunctions are even more frequent on those strategies. i have provided the code that does not work as well as log files which capture the errors.


            to me, the only possible explanation would be some kind of platform malfunction, i can't think of any other possibility.



            very well, thanks, regards.
            Attached Files

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Ousher, Yesterday, 11:12 PM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by You4Life, Yesterday, 08:20 PM
            1 response
            5 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by focus333, Yesterday, 05:56 PM
            3 responses
            15 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by itsthefriz, Yesterday, 04:19 PM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_ShawnB  
            Started by johnMoss, Yesterday, 04:06 PM
            0 responses
            8 views
            0 likes
            Last Post johnMoss  
            Working...
            X