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 f.saeidi, Today, 05:56 AM
        2 responses
        8 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by Pattontje, Yesterday, 02:10 PM
        2 responses
        36 views
        0 likes
        Last Post Pattontje  
        Started by xiinteractive, 04-09-2024, 08:08 AM
        7 responses
        27 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by Skifree, Today, 03:41 AM
        2 responses
        8 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by trimpy, Today, 04:38 AM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X