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 over

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

    EMA cross over

    Hi,

    I am new to ninja trader and now I want to make an indicator (or strategy) that indicates when the EMA10 crosses EMA5. I have made a strategy but that one does nothing. How can I procede? It would be best if it could change the color of a candle, but some kind of arrow would do as well.

    This is what I made and didn't work:
    namespace NinjaTrader.Strategy
    {
    /// <summary>
    /// This strategy puts a marker when the EMA 10 crosses the EMA 5
    /// </summary>
    [Description("This strategy puts a marker when the EMA 10 crosses the EMA 5")]
    public class TrendChange : Strategy
    {
    #region Variables
    // Wizard generated variables
    // User defined variables (add any user defined variables below)
    #endregion

    /// <summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    /// </summary>
    protected override void Initialize()
    {

    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (CrossAbove(EMA(10), EMA(5), 1))
    {
    DrawArrowDown("My down arrow" + CurrentBar, false, 0, 0, Color.Red);
    }

    // Condition set 2
    if (CrossBelow(EMA(10), EMA(5), 1))
    {
    DrawArrowUp("My up arrow" + CurrentBar, false, 0, 0, Color.Lime);
    }
    }

    #region Properties
    #endregion
    }
    }

    #2
    Originally posted by Marple View Post
    Code:
                         // Condition set 1
                if (CrossAbove(EMA(10), EMA(5), 1))
                {
                    DrawArrowDown("My down arrow" + CurrentBar, false, 0, [B]0[/B], Color.Red);
                }
    
                // Condition set 2
                if (CrossBelow(EMA(10), EMA(5), 1))
                {
                    DrawArrowUp("My up arrow" + CurrentBar, false, 0, [B]0[/B], Color.Lime);
                }
    The two bolded 0's above in your code tell the strategy to plot the arrows at a price of 0. You can change those to Close[0] or something to plot the arrows where you're more likely to see them.
    Code:
    DrawArrowDown("My down arrow" + CurrentBar, false, 0, [B]Close[0][/B], Color.Red);
    AustinNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Austin View Post
      The two bolded 0's above in your code tell the strategy to plot the arrows at a price of 0. You can change those to Close[0] or something to plot the arrows where you're more likely to see them.
      Code:
      DrawArrowDown("My down arrow" + CurrentBar, false, 0, [B]Close[0][/B], Color.Red);
      Thanks for this very fast response. Now it is working.

      BTW: Is it also possible to change the color of a candle in stead of drawing an arrow?

      Comment


        #4
        The simple answer is:

        if(CrossAbove(EMA(10), EMA(5), 1))
        BarColor = Color.Red;
        eDanny
        NinjaTrader Ecosystem Vendor - Integrity Traders

        Comment


          #5
          Yes, the property to change for candle color is BarColor. Here is the link for the help guide entry for BarColor.

          Code:
          // Sets the bar color to yellow 
          BarColor = Color.Yellow;
           // Sets the bar color to its default color as defined in the chart properties dialog 
          BarColor = Color.Empty;
          
          
          // sets bar color to green if the close is greater than the open
          if (Close[0] > Open[0])
              BarColor = Color.Green;
          AustinNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by GussJ, 03-04-2020, 03:11 PM
          11 responses
          3,221 views
          0 likes
          Last Post xiinteractive  
          Started by andrewtrades, Today, 04:57 PM
          1 response
          10 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
          9 views
          0 likes
          Last Post FAQtrader  
          Working...
          X