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

Locking in HIGH & LOW values in the First Hour

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

    Locking in HIGH & LOW values in the First Hour

    Hi - I searched but didn't see a solution, could you help?
    I successfully draw HIGH and LOW lines during the 1st hour of trading, but I desire to make Fib lines, etc. based on the information. However, the DataSeries is somehow modified after the 1st hour. Here is the code...why is it losing values?

    // count the bars during the first hour
    if ((ToTime(Time[0]) >= 093000) && (ToTime(Time[0]) <= 103100)) {
    if(FirstTickOfBar) {
    yFirstHourBarCount.Set(yFirstHourBarCount[1] + 1); }
    }
    // calculate the High and Low; Draw lines
    if ((ToTime(Time[0]) >= 093000) && (ToTime(Time[0]) <= 103100)) {
    int iBarCount = (int)yFirstHourBarCount[0];
    double mHigh = MAX(High,iBarCount)[0];
    double mLow = MIN(Low,iBarCount)[0];
    yHigh1Hour.Set(mHigh);
    yLow1Hour.Set(mLow);
    DrawHorizontalLine("firstHourHigh",…); //Works OK
    DrawHorizontalLine("firstHourLow",…); // Works OK
    }
    There are 3 DataSeries here: "yFirstHourBarCount", "yHigh1Hour", and "yLow1Hour." in particular, I think it is a problem with losing the bar count value.
    Thanks in advance for your help!

    #2
    Julie, the values are not lost but you're essentially not setting them with values outside those marked ours, so there would be no values found. If you'd like to persist them just set the dataseries outside those hours with the previous series values so you can refer to them later on in the day as well for your calcs.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thanks Bertrand,
      But I seem to be missing something here (again) – I tried but it doesn’t work.
      In today’s trading there were 20 tick bars in the first hour. I transferred the value in my “yHigh1Hour” DataSeries to my “yHighHold” DataSeries, and successfully held the proper value during the first 20 bars only, but immediately thereafter the value was Zero. To test what is happening, I have a print statement: Print(yHighHold[0]) which shows ZERO after the first 20 bars.
      The code I used was placed outside and below the “if(ToTime)” statement – the exact code I used was:

      yHighHold.Set(yHigh1Hour[0]);

      Still stumped, . . . Thanks,
      Jules

      Comment


        #4
        Julie, you cannot refer to index value 0 here in this call -

        yHighHold.Set(yHigh1Hour[0]);

        As this would just be the current bar for which you don't have a value set then, I would refer to index [1] here to store the last set value of the previous bars then in your 'hold' series to persist.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Originally posted by JulieC View Post
          Thanks Bertrand,
          But I seem to be missing something here (again) – I tried but it doesn’t work.
          In today’s trading there were 20 tick bars in the first hour. I transferred the value in my “yHigh1Hour” DataSeries to my “yHighHold” DataSeries, and successfully held the proper value during the first 20 bars only, but immediately thereafter the value was Zero. To test what is happening, I have a print statement: Print(yHighHold[0]) which shows ZERO after the first 20 bars.
          The code I used was placed outside and below the “if(ToTime)” statement – the exact code I used was:

          yHighHold.Set(yHigh1Hour[0]);

          Still stumped, . . . Thanks,
          Jules
          Hardly necessary. All that you have to do is move these lines outside the time filter block.
          Code:
          [FONT=Courier New]yHigh1Hour.Set(mHigh);[/FONT]
          [FONT=Courier New][COLOR=black]yLow1Hour.Set(mLow); [/COLOR][/FONT]
          [FONT=Courier New]DrawHorizontalLine([COLOR=maroon]"firstHourHigh"[/COLOR][/FONT][COLOR=black][FONT=Courier New],…); //Works OK [/FONT][/COLOR]
          [COLOR=black][FONT=Courier New]DrawHorizontalLine([/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"firstHourLow"[/FONT][/COLOR][COLOR=black][FONT=Courier New],[/FONT][/COLOR][COLOR=blue][FONT=Courier New]…)[/FONT][/COLOR][COLOR=black][FONT=Courier New]; // Works OK [/FONT][/COLOR]

          Comment


            #6
            Thank you!
            I finally got it (i'm slow, took hours to figure it out).

            Koganam, there must be an easier way, as you suggest, but when I moved the code lines outside the time filter block, the error message was "mHigh does not exist."

            Eventually I was able to get Bertrand's recommendation to work . . . it was a case of exactly WHEN to capture and set the value.

            Thanks again,
            Jules

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by DJ888, 04-16-2024, 06:09 PM
            4 responses
            12 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by terofs, Today, 04:18 PM
            0 responses
            9 views
            0 likes
            Last Post terofs
            by terofs
             
            Started by nandhumca, Today, 03:41 PM
            0 responses
            7 views
            0 likes
            Last Post nandhumca  
            Started by The_Sec, Today, 03:37 PM
            0 responses
            3 views
            0 likes
            Last Post The_Sec
            by The_Sec
             
            Started by GwFutures1988, Today, 02:48 PM
            1 response
            9 views
            0 likes
            Last Post NinjaTrader_Clayton  
            Working...
            X