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 gentlebenthebear, Today, 01:30 AM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by Aviram Y, Today, 05:29 AM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by cls71, Today, 04:45 AM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by TradeForge, Today, 02:09 AM
      1 response
      22 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by elirion, Today, 01:36 AM
      2 responses
      14 views
      0 likes
      Last Post elirion
      by elirion
       
      Working...
      X