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

Can anyone help with HeikenAshi coding?

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

    Can anyone help with HeikenAshi coding?

    I want HeikenAshi turn green enter long
    HeikenAshi turn red enter short
    Thanks.

    #2
    Hello stockcik, and thank you for your question.

    There are a few ways to accomplish this. Probably the easiest is to create a new indicator that wraps the built-in HeikenAshi indicator and changes its plot colors. To accomplish this, you will first need to make a copy of your HeikenAshi indicator called HeikenAshiCopy, and change the word "private" to the word "public" in the copy.

    Code:
    [FONT=Courier New]        [B]private [/B]Color           barColorDown         = Color.Red;
            [B]private [/B]Color           barColorUp           = Color.Lime;
            [B]private [/B]Color           shadowColor          = Color.Black;[/FONT]
    When you are done, those should be

    Code:
    [FONT=Courier New]        [B]public [/B]Color           barColorDown         = Color.Red;
            [B]public [/B]Color           barColorUp           = Color.Lime;
            [B]public [/B]Color           shadowColor          = Color.Black;[/FONT]
    This will let you modify HeikenAshi's colors.

    Finally, let's make a new strategy. Let's call this "ColorHeiken". You can add this code in your variables and Initialize sections, respectively, to use your copy in your strategy.

    Code:
    [FONT=Courier New]#region Variables
    // Wizard generated variables
    // User defined variables (add any user defined variables below)
    private HeikenAshiCopy myHeikenAshi;
    Color origDown, origUp, origShadow, enterLongColor, enterShortColor;
    
    protected override void Initialize()
    {
        Add((myHeikenAshi = HeikenAshiCopy()));
        origDown = Color.DarkRed;
        origUp = Color.ForestGreen;
        origShadow = Color.Black;
        enterLongColor = Color.Red;
        enterShortColor = Color.Lime;
    
        CalculateOnBarClose = true;
    }[/FONT]
    Finally we can add this to your strategy's OnBarUpdate :

    Code:
    [FONT=Courier New]        protected override void OnBarUpdate()
            {
                switch(Position.MarketPosition)
                {
                    case MarketPosition.Long :
                        myHeikenAshi.barColorDown = enterLongColor;
                        myHeikenAshi.barColorUp   = enterLongColor;
                        break;
                    default :
                        myHeikenAshi.BarColorDown = origDown;
                        myHeikenAshi.BarColorUp   = origUp;
                        myHeikenAshi.shadowColor  = origShadow;
                        break;
                }
    
                // your strategy code here
            }[/FONT]
    You will want to extend this so that it works for a short position as well. I will leave that as an exercise to you.

    Please let us know if there are any other ways we can help.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Thanks Jessica, but I still can't make it since I am a real newbie in coding.
      is there a NinjaScript I can download?

      Comment


        #4
        Hello stockchik,

        You may want to try your luck in the file sharing section of the forums. I am providing a search link.

        Jessica P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Belfortbucks, Today, 09:29 PM
        0 responses
        6 views
        0 likes
        Last Post Belfortbucks  
        Started by zstheorist, Today, 07:52 PM
        0 responses
        7 views
        0 likes
        Last Post zstheorist  
        Started by pmachiraju, 11-01-2023, 04:46 AM
        8 responses
        151 views
        0 likes
        Last Post rehmans
        by rehmans
         
        Started by mattbsea, Today, 05:44 PM
        0 responses
        6 views
        0 likes
        Last Post mattbsea  
        Started by RideMe, 04-07-2024, 04:54 PM
        6 responses
        33 views
        0 likes
        Last Post RideMe
        by RideMe
         
        Working...
        X