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

Trend Bar Painting

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

    Trend Bar Painting

    First of all, a big THANK YOU to Chelsea at Ninjatrader for all the links provided to get this started.

    This is my 1st Ninja script here and I need some help. I used script from ColoredScalpBar8 and replaced its indicator logic with current one.

    The idea is simple. I want to paint the bars with the same color as long as they stay in the same trend. The trend is defined as below:

    double close0 = Close[0];
    double SMA1 = SMA(Close, 6)[1];
    double ATR1 = ATR(6)[1];

    if (close0 > (SMA1 - atrPercent*ATR1))
    {BarBrush = UpBrush;}
    else
    {BarBrush = DownBrush;}

    But it did not compile well and I attached screenshot here. I could not figure out why "UpBrush" and "DownBrush" were declared fine in ColoredScalpBar8 but not in my script.

    Would really appreciate some help. Since there are compiling errors, I don't know how to export the script. Hence the screenshot only.
    Attached Files

    #2
    Hello zhawenx,

    Thank you for your post.

    I can't see in the screenshot provided where you've initialized any of these variables. Could you copy and paste the entirety of the code you currently have into your reply?

    Thanks in advance;I look forward to assisting you further.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Here it is.
      Attached Files

      Comment


        #4
        Hello zhawenx,

        Thank you for your reply.

        The code provided is not the code shown in your screenshot. Can you just select all the code in that window and copy it, then paste it into your reply?

        However, from what I am seeing you are not initializing your variables before you try to use them. Do you have something like this in your code before OnStateChange()?

        Code:
        public class wzTrend : Indicator
        {
        //initialize the variables we will be using
        private Brush UpBrush;
        private Brush DownBrush;
        private double atrPercent;
        
        protected override void OnStateChange()
        {
        //code continues
        Thanks in advance; I look forward to assisting you further.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Thanks Kate. That's exactly where the problem was. eDanny has pointed this out and is helping me with another issue. Will post the script once it's done.

          Comment


            #6
            The working version is posted here:

            I created this new topic on purpose rather than continue in my previous topic so people can access the zip file right here in 1st post. Forum moderators can delete the other one if you deem that is better for the community. Never did any coding, this is my first Ninja script and it started just two days ago. No credit on my


            Will also be available in User App Share.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by llanqui, Today, 11:10 AM
            0 responses
            4 views
            0 likes
            Last Post llanqui
            by llanqui
             
            Started by llanqui, Today, 10:29 AM
            0 responses
            5 views
            0 likes
            Last Post llanqui
            by llanqui
             
            Started by llanqui, Today, 08:32 AM
            1 response
            13 views
            0 likes
            Last Post llanqui
            by llanqui
             
            Started by lollers, Yesterday, 03:26 AM
            1 response
            54 views
            0 likes
            Last Post lollers
            by lollers
             
            Started by Salahinho99, 05-05-2024, 04:13 AM
            7 responses
            63 views
            0 likes
            Last Post Salahinho99  
            Working...
            X