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 ETFVoyageur, Today, 04:00 PM
        0 responses
        5 views
        0 likes
        Last Post ETFVoyageur  
        Started by AaronKTradingForum, Today, 03:44 PM
        1 response
        6 views
        0 likes
        Last Post AaronKTradingForum  
        Started by Felix Reichert, 04-26-2024, 02:12 PM
        11 responses
        76 views
        0 likes
        Last Post Felix Reichert  
        Started by junkone, 04-28-2024, 02:19 PM
        7 responses
        82 views
        1 like
        Last Post junkone
        by junkone
         
        Started by pechtri, 06-22-2023, 02:31 AM
        11 responses
        136 views
        0 likes
        Last Post Nyman
        by Nyman
         
        Working...
        X