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

"Price is equal to/smaller/larger than"

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

    "Price is equal to/smaller/larger than"

    Seems I can't see the forest for the trees this morning ...

    How do I code "price is equal to an MA"?

    Close == SMA(20).

    and "price is between two MAs"?

    Close < SMA(20) && Close > SMA(50)

    "Close" does not do it. What does?

    Anyone can help me to get out of my jumbled state of mind please?

    sandman
    Attached Files

    #2
    Hello sandman,

    Thanks for your post.

    I think the forest is missing the bar index which means which bar are you comparing (usually, but not always, it is the current bar [0])

    if (Close[0] == SMA(20)[0])
    Is the close price equal to the 20 period SMA. Note that this is likely to be a rare event as you are asking a computer to compare very specific values that likely will never be precisely the same. You might be best to make a comparison of the close price to SMA(20)[0] + 1 *TickSize or SMA(20)[0] - 1 * TickSize. Depends on how precise you need to be.


    if ((Close[0] > SMA(20)[0] && Close[0] < SMA(50)[0]) || (Close[0] < SMA(20)[0] && Close[0] > SMA(50)[0])
    This is checking to see if the close price of the current bar is between the SMA20 and the SMA50 when the SMA20 is below the SMA50 OR if the close price is between the SMA20 and the SMA50 when the SMA20 is above the SMA50. You may not want to have both sets in one but put this together in case you did.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Paul,

      I was finally able to get back to this piece of coding. Despite your input I haven't been able to make it work. Price hits an SMA 20 and is then supposed to draw a Dot. No dots no matter what I tried so far. Does the draw method not work in this case? Here is what I am using:

      protected override void OnBarUpdate()
      {

      if (CurrentBars[0] < BarsRequired)
      return;

      if (CurrentBar < 1)
      return;

      // Condition =========================

      if (Close[0] == SMA(20)[0] + 3 *TickSize)

      {
      DrawDot("My dot up" + CurrentBar, false, 0, Low[0], Color.Red);
      }
      }

      sandman

      Comment


        #4
        Hello Sandman,

        Thanks for your reply.

        The condition is pretty specific so I would not expect to see a lot of dots. Also, the dots may not be obvious as they may be hidden by the bars themselves.

        I've recreated your code and applied it to the ES 09-16 1 minute bars, add a 20 period SMA for visual reference. At first I also thought there were no dots but on closer inspection I found a few partially hidden by the bars.

        I then modified your code and had it draw two separate dots, one was with the condition of the Close[0] == SMA(20)[0] (red dots) and the other with the condition Close[0] == SMA(20)[0] + 3 * TickSize (Blue dots). In the chart I observed many red dots and a few blue dots. To help see the dots I offset the dot drawing location from Low[0] to Low[0] - 3 * TickSize.

        Please see the attached picture for reference.
        Attached Files
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Thanks Paul, I'll give it another go with your suggestion. Question: Would all the dots show up historically or only now and then?

          sandman

          Comment


            #6
            Hello Sandman,

            Thanks for your reply.

            With your DrawDot tag name of "My dot up" + CurrentBar you will see every dot produced both historically and live.
            Paul H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by andrewtrades, Today, 04:57 PM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by chbruno, Today, 04:10 PM
            0 responses
            6 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