• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Test new High / Low after Monday

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

    Test new High / Low after Monday

    Hello all,

    I am struggling for many hours to find a way to test for a new Low / High as a week progresses.

    I have a simple code (see below) and I need to test on all remaining days of week (i.e Tue, Wed, Thu, Fri) if higher high or lower low was created in the market. If yes I would like to use that High / Low in my doubles instead of the value they take on Monday. If now I want the doubles to keep values from Monday.

    I have read many threads but came to no result.

    Any idea on how I could proceed will be much appreciaed.

    My code:
    protected override void OnBarUpdate()
    {
    double WavgHigh = Low[0]*(1.022);
    double WavgHigh1dev = Low[0]*(1.032);
    double WavgHigh2dev = Low[0]*(1.042);
    double WavgLow = High[0]*(1-0.022);
    double WavgLow1dev = High[0]*(1-0.032);
    double WavgLow2dev = High[0]*(1-0.042);

    {
    if (Time[0].DayOfWeek == DayOfWeek.Monday)
    {
    DrawText("W avg. high" + CurrentBar, false, "W avg. High", 0, WavgHigh, 0, Color.Black, new Font("Arial", 8), StringAlignment.Center, Color.Blue, Color.Transparent, 0);
    DrawText("W avg. high 1 dev", false, "W avg. High 1dev", 0, WavgHigh1dev, 0, Color.Black, new Font("Arial", 8), StringAlignment.Center, Color.Blue, Color.Transparent, 0);
    DrawText("W avg. high 2 dev", false, "W avg. High 2dev", 0, WavgHigh2dev, 0, Color.Black, new Font("Arial", 8), StringAlignment.Center, Color.Blue, Color.Transparent, 0);
    DrawText("W avg. low", false, "W avg. Low", 0, WavgLow, 0, Color.Black, new Font("Arial", 8), StringAlignment.Center, Color.Blue, Color.Transparent, 0);
    DrawText("W avg. low 1 dev", false, "W avg. Low 1dev", 0, WavgLow1dev, 0, Color.Black, new Font("Arial", 8), StringAlignment.Center, Color.Blue, Color.Transparent, 0);
    DrawText("W avg. low 2 dev", false, "W avg. Low 2dev", 0, WavgLow2dev, 0, Color.Black, new Font("Arial", 8), StringAlignment.Center, Color.Blue, Color.Transparent, 0);
    }

    else
    {
    }
    }
    }

    #2
    Hello kadan,

    I would like to clarify what you are wanting to achieve.

    You are wanting to store the the highest high each time a new high is made and reset this on a specific day of the week, is this correct?

    Your variables will need to be declared in the scope of the class (outside of OnBarUpdate()).
    You can use Math.Max() and Math.Min() to assign the variable either itself or a new value whichever is higher/lower.

    Below is a public link to Microsoft documentation on the C# Math methods.
    https://docs.microsoft.com/en-us/dot...ramework-4.7.2
    https://docs.microsoft.com/en-us/dot...ramework-4.7.2

    To reset the variables, this can be done by comparing the day of the week using the Time[0] DateTIme object on the first bar of a session.

    Below is a public link to the help guide on Time.
    https://ninjatrader.com/support/help...eries_time.htm

    And Bars.IsFirstBarOfSession.
    https://ninjatrader.com/support/help...rofsession.htm

    A public link to Microsoft documentation on DateTime.DayOfWeek.
    https://docs.microsoft.com/en-us/dot...ramework-4.7.2

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea,

      This was what I have been missing "Your variables will need to be declared in the scope of the class (outside of OnBarUpdate())." :-)

      I worked out what I wanted.

      Thank you

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Revan, Yesterday, 11:53 PM
      4 responses
      21 views
      0 likes
      Last Post NinjaTrader_Jim  
      Started by Vincere, Today, 03:32 AM
      1 response
      3 views
      0 likes
      Last Post NinjaTrader_ChrisSch  
      Started by hir04068, Today, 04:26 AM
      0 responses
      5 views
      0 likes
      Last Post hir04068  
      Started by Thomas79, Today, 03:22 AM
      0 responses
      3 views
      0 likes
      Last Post Thomas79  
      Started by pjsmith, Today, 12:50 AM
      1 response
      5 views
      0 likes
      Last Post NinjaTrader_ChrisSch  
      Working...
      X