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

CalculateOnBarClose = false for different periodtype

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

    CalculateOnBarClose = false for different periodtype

    Hi, I need the following indicator, which ist calculated on PeriodType.Week, run on an Dayly chart. This works ok now, but dont know how to get it work for CalculateOnBarClose = false for the weekly calculation.
    Somebody can help please?

    Code:
          protected override void Initialize()
            {
                Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Linie"));
                Add(PeriodType.Week, 1);
    			CalculateOnBarClose = false;
    			Overlay				= false;
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
     		   if (CurrentBar < 155) return;
    	
    	               
    			double mom1 = Momentum(Closes[1],28)[0];
    		double smamom = SMA(Momentum(Closes[1],28),28)[0];
    		if (mom1 > smamom)
    				
    			Linie.Set(1);
    		else if (mom1 < smamom)
    				Linie.Set(-1);
    		else Linie.Set(0);
    
            }

    #2
    Can you specify exactly what part is not working? Does it not plot at all?

    Are there any error messages on screen or the Log tab of the Control Center when you test this?
    MatthewNinjaTrader Product Management

    Comment


      #3
      Everything works ok, no errors. The problem is that I want to calculate the indicator onbarclose = false and it only works on a weekly chart. If I chose a dayly chart the indicator is calculated always on the last weekly close (as it would be calculated onbarclose=true on a weekly chart) and not onbarclose = false. How can I solve this?

      Comment


        #4
        I'm very sorry, but I'm not following. When I run your code, I get prints between -1 and 1 and this works regardless of the COBC option I am using.

        Can you give me a specific example of what is not working when you have this set to false?
        MatthewNinjaTrader Product Management

        Comment


          #5
          Originally posted by NinjaTrader_Matthew View Post
          I'm very sorry, but I'm not following. When I run your code, I get prints between -1 and 1 and this works regardless of the COBC option I am using.

          Can you give me a specific example of what is not working when you have this set to false?
          Thanks a lot for your answer! I will try to explain this better.
          My problem is that when I run this indicator on a dayly chart it is always takes last friday close (=the last weekly close) for calculation. I need this indicator to be recalculated on every market movement along the week.
          Coffee KC 05-13 dayly chart was an example last week.On last thursday the indicator was still giving a "1" (it was taking friday close the week before for calculation). If calculated onbarclose= false it should have already given a "-1". Now, after last fridays close it shows the correct -1 for last week.
          Thank you again!

          Comment


            #6
            Hello valent197,

            Thank you for your response.

            From my tests the Linie is not plotting the value until it reaches Friday. So for Thursday March 14th the value was the same as the previous Friday (March 8th), but then on Firday March 15th it corrected itself.

            This is because the close of the Weekly bar is Friday, so on your daily chart the value is not plotted until that Friday for the week.

            Please let me know if I may be of further assistance.

            Comment


              #7
              Originally posted by NinjaTrader_PatrickH View Post
              Hello valent197,

              Thank you for your response.

              From my tests the Linie is not plotting the value until it reaches Friday. So for Thursday March 14th the value was the same as the previous Friday (March 8th), but then on Firday March 15th it corrected itself.

              This is because the close of the Weekly bar is Friday, so on your daily chart the value is not plotted until that Friday for the week.

              Please let me know if I may be of further assistance.
              Hello Patrick,
              Yes, as you described is exactly my problem.
              Isn't there a posibility to recalute the Indicator from monday to thursday with the actual price of the dayly bar?
              Thank you!

              Comment


                #8
                Hello valent197,

                Thank you for your response.
                Isn't there a possibility to recalculate the Indicator from Monday to Thursday with the actual price of the daily bar?
                As we are plotting a value of 1, 0, or -1 calculated from a Weekly bar yet plotted on a Daily bar you are seeing the value plotted on Friday as that is the close of the Weekly bar.

                This is expected and there would not be a way around this.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by cmtjoancolmenero, Yesterday, 03:58 PM
                2 responses
                19 views
                0 likes
                Last Post cmtjoancolmenero  
                Started by Stanfillirenfro, 04-22-2024, 09:19 AM
                8 responses
                58 views
                0 likes
                Last Post Stanfillirenfro  
                Started by olisav57, Yesterday, 07:39 PM
                1 response
                9 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by cocoescala, 10-12-2018, 11:02 PM
                7 responses
                941 views
                0 likes
                Last Post Jquiroz1975  
                Started by oviejo, Today, 12:28 AM
                1 response
                11 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Working...
                X