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

IsFirstBarOfSession Question - runs twice?

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

    IsFirstBarOfSession Question - runs twice?

    Good morning,

    I have written an empirical scan into a strategy which tracks what happens after a specific bar pattern and calculates a percentage probability of the likely outcome based on the historical data loaded. I want to reset the count every day, but keep the previous day's counts for use in the calculations. I have tried to do this by creating multiple series to house the counts. During debugging I have noticed the IsFirstBarOfSession script I have written appears to process twice, but I could be missing something. On the second process the number previously sent to the prior day series switches to zero. Here is the script in question:

    Code:
    if (Bars.IsFirstBarOfSession)
                {
                    priordaydeuptracker[0] = deuptracker[1];
                    priordaydedowntracker[0] = dedowntracker[1];
                    priordaydetotaltracker[0] = detotaltracker[1];    
                    Print("Eggs = " + priordaydeuptracker[0]);
                    longtradefilter = false;
                    shorttradefilter = false;
                    trailingstoppriceseries[0] = stoplosss;
                    losslimitbool = false;
                    gainlimitbool = false;
                    currentPnL = 0.00;
                    risklimitbool = false;
                    deupcount = 0;
                    dedowncount = 0;
                    deuptracker[0] = 0;
                    dedowntracker[0] = 0;
                    detotaltracker[0] = 0;
                    decounter = 0;
                    Print("Bacon = " + priordaydeuptracker[0]);
                }
    else
                {
                    priordaydeuptracker[0] = priordaydeuptracker[1];
                    priordaydedowntracker[0] = priordaydedowntracker[1];
                    priordaydetotaltracker[0] = priordaydetotaltracker[1];
                }
    The variables deupcount, dedowncount, and decounter house the counts which are injected into series. I have arranged these in a sequence I would expect should perform the order of operations correctly, but when I run the strategy in Strategy Analyzer and check the Bacon and Eggs prints (so named for ease of finding them in the Output screen) I find that after the priorday trackers are assigned, a second assignment occurs after the other variables and series have been reset to zero. The output screen shows this print:

    Eggs = 4
    Bacon = 4
    Eggs = 0
    Bacon = 0

    There are no other assignments to the priorday series anywhere in the strategy, and there are no other bacon and eggs prints, either. I am not sure why this code is running twice like this and undoing itself. Any input on this is appreciated.

    Cheers.
    Last edited by liquid150; 02-10-2020, 07:36 AM.

    #2
    Hello liquid150,

    Thank you for the post.

    From the given code nothing sticks out as to what may be the cause, the only item which may cause this would be using a multi series script. Is that applicable here?

    I would otherwise need more details surrounding the test, would it be possible to extract the condition you have made and print and place that in a new empty indicator for testing? that could help to isolate the specific requirements to see this which will also help to understand why that's happening.

    You could try adding the BarsInProgress to your print or CurrentBar to see if anything else can be found:

    Code:
    Print(BarsInProgress + " " + CurrentBar + " " + "Bacon = " + priordaydeuptracker[0]);

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello liquid150,

      Thank you for the post.

      From the given code nothing sticks out as to what may be the cause, the only item which may cause this would be using a multi series script. Is that applicable here?

      I would otherwise need more details surrounding the test, would it be possible to extract the condition you have made and print and place that in a new empty indicator for testing? that could help to isolate the specific requirements to see this which will also help to understand why that's happening.

      You could try adding the BarsInProgress to your print or CurrentBar to see if anything else can be found:

      Code:
      Print(BarsInProgress + " " + CurrentBar + " " + "Bacon = " + priordaydeuptracker[0]);

      I look forward to being of further assistance.
      Thanks for the reply Jesse,

      Yes! This is a multiple data series script. I am also loading Daily and Weekly data. I must have assumed NT "knew" daily and weekly bars wouldn't handle IsFirstBarOfSession.

      Thanks for this information! I've moved this section of my code to reside within BarsInProgress == 0. It seems to be working as expected, now! I will reply to this thread if there are any additional problems with this issue.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by andrewtrades, Today, 04:57 PM
      1 response
      5 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by chbruno, Today, 04:10 PM
      0 responses
      5 views
      0 likes
      Last Post chbruno
      by chbruno
       
      Started by josh18955, 03-25-2023, 11:16 AM
      6 responses
      436 views
      0 likes
      Last Post Delerium  
      Started by FAQtrader, Today, 03:35 PM
      0 responses
      7 views
      0 likes
      Last Post FAQtrader  
      Started by rocketman7, Today, 09:41 AM
      5 responses
      19 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Working...
      X