Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Setting a % off Days High Condition in Market Analayzer

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

    Setting a % off Days High Condition in Market Analayzer

    Hi,

    I need to create a condition for MA so that stocks only show up near their highs and lows. I got almost all my MA conditions coded for the scan I need but having real troubles with this part. Mainly because I have no clue what the code wants or needs as far as a retrace more/less than. I need the code for the high/low of the regular session of trading stocks on the NASDAQ/NYSE.

    I want the code to set a condition so the stocks in the MA have to have retraced less then 25% or more then 75% from their highs on the day.

    I am hoping this part of the code is most of what I need?

    barsAgoHigh = HighestBar(High, Bars.BarsSinceSession -1);
    myDateTime = Time[barsAgoHigh];

    If this finds me the high of the day from open, how do I set that I want the price to be less then 25% away and more then 75% away from the high?

    Thanks for any help,
    R.T.

    #2
    RT, you can just use CurrentDayOHL to access the daily high made so far - http://www.ninjatrader-support.com/H...entDayOHL.html

    From this value you can calculate the % offset needed then to trigger your signals.

    Comment


      #3
      Thanks

      Hi,

      Thanks Bertrand...

      So Is this the only piece of the code I need to create the MA condition off of?

      double value = CurrentDayOHL().CurrentHigh[0];

      I need to use the current last price for the code as well correct? something like

      if LastPrice => .25 CurrentDayOHL().CurrentHigh[0];

      Plot0.Set(1);

      else

      Plot0.Set(0);

      any advice on if this is even close would be helpful
      Thanks, reed

      Comment


        #4
        You would need to give a run to check what you need and seek - however keep in mind this is the absolute retracement, if I understand you correctly you rather seek the stocks that have retraced for example 50% off their intraday high, so you want to calculate that off the DayHigh to Open difference.

        Comment


          #5
          Hi Bertrand,

          Thanks for the reply, I am in need of just the filter condition so that I only see stocks which are near their highs and lows. I am not looking for an exact figure such as "has to be 50%" from the HOD... Rather any stocks which are between 75% and 100% of their high of day. For some reason I get lost on how to code it (not that I know how to code).

          So I am looking for a "% Off High" which I can set to => 75% which will show any stocks in market analyzer which have not retraced more then 75% from the days high.

          Hope this makes sence and thanks for any help... Please let me know if the way I was going about it in this thread will work for what I need..

          RT

          Comment


            #6
            Close maybe?

            Here is what I tried, seems close but got to errors,

            Anyone who can see what is wrong I would appreciate any help...

            if (LastPrice => .25 (CurrentDayOHL).CurrentHigh[0])
            {
            Plot0.Set(1);
            }
             
            else
            {
            Plot0.Set(0);
            }

            I would also like to try to make the % variable changable within the indicator, so if I want to set it to >then 25% off high or > then 38% off high it can be done within the indicator...

            Thanks for any help,
            RT

            Comment


              #7
              Hello,


              I believe your on the right track you can do all of this with CurrentDayOHLC().CurrentHigh[0] and CurrentLow[0] and finding the range and then finding where at in this range is the 50% mark and then doing an if statment for if above this price then *Do what you need to do*.

              However as far as coding this for your we unfortunatley cannot do we can however answer any NS related questions you have, we have NinjaScript consultants also to help with coding.


              NinjaScript Consultants:


              Let me know if I can be of further assistance.
              BrettNinjaTrader Product Management

              Comment


                #8
                Hey

                Thanks for the reply Brett,

                Let me ask you this is the "LastPrice" that I use an accepted NT reference? I think that is where the problem is...

                Thanks,
                RT

                Comment


                  #9
                  RT,

                  "LastPrice" is not a recognized variable in NinjaScript. For the last price you would want to use Close[0].
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    This is very close, it seems to just not accept the * .25 , if anyone could tell me how to calculate a -25% from high for this I would greatly appreciate it... thanks!

                    if (Close[0] >= (CurrentDayOHL).CurrentHigh[0] * .25)
                    {
                    Plot0.Set(1);
                    }
                     
                    else
                    {
                    Plot0.Set(0);
                    }
                    }

                    Comment


                      #11
                      The lines below should compile well for you, CurrentDayOHL() is a method -

                      if (Close[0] >= (CurrentDayOHL().CurrentHigh[0] * .25))
                      {
                      Plot0.Set(1);
                      }
                       
                      else
                      {
                      Plot0.Set(0);
                      }

                      Comment


                        #12
                        Hi Bertrand,

                        Thanks so much, it looks perfect, but for some reason will not compile.. I created a new NT indicator with plot and cut and past the code, replacing the standard "Close[0] with the code you created but it will not compile for some reason.. I know this is usually for some simple reason but can't find it... It is giving me an ";" expected error and when I try to fiddle with it and add it it fails...

                        Thanks for the help and any advice I would be very grateful,
                        Reed

                        Comment


                          #13
                          Hello Reed,

                          The snippet posted should compile OK. Can you share your OnBarUpdate() section and we can take a look at what you have here?
                          Ryan M.NinjaTrader Customer Service

                          Comment


                            #14
                            Hey Ryan, long time no talk huh?

                            you know what, it did compile after retrying it... I believe he edited the post/code from yesterday...

                            ? though, would this code be figuring the % off high from the previous close rather then off the open? I believe it is... if so any idea to to make it see the % off high from the open rather then from the close?

                            Thanks for all the help,

                            Comment


                              #15
                              Close[0] would be the last price.

                              You can reference the current day opening price similar to current highs, with:
                              CurrentDayOHL().CurrentOpen[0]
                              Ryan M.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              601 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              347 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              103 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              559 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              558 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X