Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stategy not entering an Active State

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

    Stategy not entering an Active State

    Hello,

    I have been backtesting a custom strategy which has been working fine in the strategy analyzer. Now that I'm trying to enable the strategy in Market Replay it is not activating and therefore not executing trades. I have added some print statements to try and determine where the issue is.

    As it relates to the OnStateChange section of the script; it sets the defaults and then configures the strategy and successfully enters the state of DataLoaded but it never prints that it entered the Active state as requested.

    As for the OnBarUpdate section; the first thing I have in the script is a request to print the current bar. It does do that even though it never prints that it entered an active state.
    Once the script gets here it just continues to print the current bar and never enters any trades.

    There are no errors in the logs and the last thing it logs is that it is "Enabling Ninjascript strategy (STRATEGY NAME)".

    Prior to this I was getting incorrect responses related to Minimum bars for trading and trading times. Print statements showed that it was determining there weren't enough bars to trade even though it showed the requirement to be 50 and the current bar greater than 50. Similarly for the time window it stated that it was not within the trading time window while it was. I removed those from the script to see if I could get it to work and the results I described above began.

    Any help would be appreciated. I'm sure I'm doing something wrong as seems to be the case for most of the posts I have read here but I can't seem to find one related to this specifically.

    Thanks!

    #2
    Hello jrhoopes,

    Active state is not intended for chart based scripts, that is generally meant for items that do not process series. strategies and indicators go from DataLoaded to Historical to Realtime.

    Comment


      #3
      Thanks Jesse,

      So that clears that up for me. But now I'm still confused as to why the strategy doesn't enter into any trades when the entry signal requirements have been satisfied.

      Comment


        #4
        Hello jrhoopes,

        That depends on your conditions. You can make sure its processing by putting prints in OnBarUpdate and also outputting the values used in your conditions. You can then use the output to see why its doing what it is. In addition to the values you will need to print the bar time to know what print is associated with each bar.

        Comment


          #5
          Hi Jesse,

          I have already implemented prints for each onbarupdate which is why I know that the conditions for entry are being met but the trade is not being entered. I also have a print statement entered after my entry requirements but that print statement is not being generated. The only line between the onbarupdate prints and the entry portion of the script is the entryprice line. I'm wondering if this is where the issue is.

          double entryPrice = Position.AveragePrice;

          // Long Entry Signal
          if​ (ENTRY REQUIREMENTS LISTED HERE)

          Do you see anything wrong with the way I'm asking it to obtain the entry price prior to the entry signal requirements?

          Comment


            #6
            Hello jrhoopes,

            If the print for the entry is not being generated that means that part of the code was not called. That would mean the condition where that print is was false.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Yesterday, 05:17 AM
            0 responses
            58 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            133 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
            45 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            50 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X