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 rocketman7, Today, 02:12 AM
      1 response
      15 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by briansaul, Today, 05:31 AM
      1 response
      12 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by PaulMohn, Today, 03:49 AM
      1 response
      12 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by frslvr, 04-11-2024, 07:26 AM
      6 responses
      106 views
      1 like
      Last Post NinjaTrader_BrandonH  
      Started by trilliantrader, 04-18-2024, 08:16 AM
      6 responses
      26 views
      0 likes
      Last Post trilliantrader  
      Working...
      X