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

EMA Cross Indicator

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

    EMA Cross Indicator

    Hi all,

    I'm very new to this and can't seem to get my head wrapped around the coding for this. I'm looking to make an indicator that would overlay on the price chart and highlight bars that cross over and under an 8 EMA line based on the closing price.

    I'm thinking that the logic would look something like this:

    If CLOSE(1) => 8EMA(1) and CLOSE(0) < 8EMA(0) then put the indicator over the current price

    and

    if CLOSE(1) =< 8EMA(1) and CLOSE(0) > 8EMA(0) then put the other indicator over the current price

    However, after going through the NT help and tutorials, I'm still a bit lost as to how to code this. Any help, guidance, direction pointing, etc is MUCH appreciated.

    Thanks!

    #2
    Hello,

    I'll be happy to point you in the right direction. Firstly, can you tell me a bit more about exactly what you are looking to draw on the chart? Are you looking to draw some kind of marker (like a dot or diamond) on the bar at which the condition occurs, or perhaps to change the color of the bar in question, or something else?

    In terms of the syntax for the conditions, what you are looking for can be written as such:

    Code:
    if(Close[1] >= EMA(8)[1] && Close[0] <= EMA(8)[0]
                {
                    do something...    
                }
                
    if(Close[1] <= EMA(8)[1] && Close[0] > EMA(8)[0]
                {
                    do something...    
                }
    You can find more information about basic C# syntax at the link below:



    I look forward to your reply.
    Dave I.NinjaTrader Product Management

    Comment


      #3
      Thanks NT_Dave!

      You are correct. I'm looking for an over the bar indicator. I was thinking a green up arrow for an upwards cross and a red down arrow for a downwards cross.

      Comment


        #4
        In that case, you can use the DrawArrowUp() and DrawArrowDown() methods to draw arrows above or below the candle at the point at which the condition evaluates to True.

        One quick thing to note -- you will need to specify a unique name in the constructor for these methods, so that the older arrows do not get replaced and redrawn. To do this, you can add CurrentBar to a string to ensure that each name is unique. There is an example of this in the help guide page for DrawArrowDown below:

        DrawArrowDown(): http://www.ninjatrader.com/support/h...warrowdown.htm

        DrawArrowUp(): http://www.ninjatrader.com/support/h...rawarrowup.htm

        Please let me know if I can assist further.
        Dave I.NinjaTrader Product Management

        Comment


          #5
          OK...wondering what I'm doing wrong at this point. I can get the code to compile, however, there is nothing drawn on the chart when I apply the indicator. I've pasted the code below.

          Help...please!

          protected override void Initialize()
          {
          Overlay = true;
          }

          /// <summary>
          /// Called on each bar update event (incoming tick)
          /// </summary>
          protected override void OnBarUpdate()
          {
          // Use this method for calculating your indicator values. Assign a value to each
          // plot below by replacing 'Close[0]' with your own formula.

          if(Close[1] <= EMA(8)[1] && Close[0] > EMA(8)[0])
          {
          DrawArrowUp(CurrentBar.ToString(), true, 0, High[0] + TickSize, Color.LimeGreen);
          }
          }

          Comment


            #6
            Originally posted by lilzenbca View Post
            OK...wondering what I'm doing wrong at this point. I can get the code to compile, however, there is nothing drawn on the chart when I apply the indicator. I've pasted the code below.

            Help...please!

            protected override void Initialize()
            {
            Overlay = true;
            }

            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
            // Use this method for calculating your indicator values. Assign a value to each
            // plot below by replacing 'Close[0]' with your own formula.

            if(Close[1] <= EMA(8)[1] && Close[0] > EMA(8)[0])
            {
            DrawArrowUp(CurrentBar.ToString(), true, 0, High[0] + TickSize, Color.LimeGreen);
            }
            }
            Look in your log and you should see an error about an index being out of bounds or invalid.

            You need to escape your first bar, as it does not exist when the code first runs. Try the suggestion in this thread (and numerous others in the forum).

            ref: http://www.ninjatrader.com/support/f...41212#poststop

            Generally speaking, the log should be your first place to look when an indicator compiles properly but does not draw on the chart as expected. There will usually be some indication of the cause in there.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by futtrader, 04-21-2024, 01:50 AM
            4 responses
            41 views
            0 likes
            Last Post futtrader  
            Started by Option Whisperer, Today, 09:55 AM
            1 response
            11 views
            0 likes
            Last Post bltdavid  
            Started by port119, Today, 02:43 PM
            0 responses
            7 views
            0 likes
            Last Post port119
            by port119
             
            Started by Philippe56140, Today, 02:35 PM
            0 responses
            7 views
            0 likes
            Last Post Philippe56140  
            Started by 00nevest, Today, 02:27 PM
            0 responses
            7 views
            0 likes
            Last Post 00nevest  
            Working...
            X