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

I do not understand the OnBarUpdate - Help

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

    I do not understand the OnBarUpdate - Help

    Hi,
    I have this code

    Code:
            protected override void Initialize()
            {
                //SetStopLoss("", CalculationMode.Ticks, 10, false);
                CalculateOnBarClose = true;
    			
    			Add(PeriodType.Minute, 1);
    			
    			Add(SMA(200));
    			Add(EMA(9));
    			Add(EMA(26));
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                // Condition set LONG
                if (Close[0] > SMA(200)[0]
    				&& CrossAbove(EMA(9), EMA(26), 1))
                {
                    DrawArrowUp(CurrentBar.ToString(), true, 0, Low[0] - TickSize, Color.Green);
    				Print("LONG"+DateTime.Now);
                }
    
    			// Condition set SHORT
                else if  (Close[0] < SMA(200)[0]
    				&& CrossBelow(EMA(9), EMA(26), 1))
                {
    				DrawArrowDown(CurrentBar.ToString(), true, 0, High[0] + TickSize, Color.Red);
    				Print("SHORT"+DateTime.Now);
                }
            }
    If I get in real time with the activated strategy and the "Ouput Window" it is always showing "LONG" or "SHORT" and supposedly it should only do it when the crossing occurs.
    I do not know what I can be doing wrong!
    Thank you for help !!

    #2
    Hello benjaminrc78,

    Thank you for your note.

    If you modify your print statement to the following,

    Code:
    Print("SHORT"+Time[0].ToString());
    Which would be the time of the bar the cross occurred rather than the current time right now, does the output window look as you'd expect it?

    I look forward to your reply.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Thank you for help.
      I will try.
      I think that happend in "past mode" tomorrow try in real.
      If not work will post ;-)
      thanks.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by ETFVoyageur, Today, 07:55 PM
      0 responses
      4 views
      0 likes
      Last Post ETFVoyageur  
      Started by janio973, Today, 07:24 PM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by aligator, 01-06-2022, 12:14 PM
      4 responses
      242 views
      0 likes
      Last Post john_44573  
      Started by reynoldsn, Today, 05:56 PM
      0 responses
      12 views
      0 likes
      Last Post reynoldsn  
      Started by bortz, 11-06-2023, 08:04 AM
      51 responses
      1,996 views
      0 likes
      Last Post aligator  
      Working...
      X