Announcement

Collapse
No announcement yet.

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.

    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.

        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 Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            670 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            379 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            111 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            575 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            582 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X