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

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.



    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.


    And Bars.IsFirstBarOfSession.


    A public link to Microsoft documentation on DateTime.DayOfWeek.


    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 gravdigaz6, Today, 11:40 PM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by MarianApalaghiei, Today, 10:49 PM
      3 responses
      10 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by XXtrader, Today, 11:30 PM
      0 responses
      4 views
      0 likes
      Last Post XXtrader  
      Started by love2code2trade, Yesterday, 01:45 PM
      4 responses
      28 views
      0 likes
      Last Post love2code2trade  
      Started by funk10101, Today, 09:43 PM
      0 responses
      9 views
      0 likes
      Last Post funk10101  
      Working...
      X