Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnBarUpdate not call

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

    OnBarUpdate not call

    I'm want to print("Tom") to the script output. This is my code:
    Code:
            protected override void OnBarUpdate()
            {
                if (BarsInProgress != 0)
                    return;
    
    
                Print("Tom");
    
    
                if(!traded){
                    PlaceTrade("long",1);
                    traded=true;
                }
    
    
    
                //double limitPrice = Low[0] - TickSize * 5;
    
    
    
            }​

    But it is not printing when i load the strategy to chart. My Calculate = Calculate.OnPriceChange;

    I'm a pro algorithmic developer but new to ninja trader

    #2
    Check your Control Center Log tab - most likely the strategy is being taken offline by an exception in OnStateChange when it gets to Configure or DataLoaded.
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      Originally posted by QuantKey_Bruce View Post
      Check your Control Center Log tab - most likely the strategy is being taken offline by an exception in OnStateChange when it gets to Configure or DataLoaded.
      Okay, Im going to check it now, but it print on strategy analyzer only

      Comment


        #4
        If it happens only in strategy analyzer, I would be looking first for things like if you are referencing Bars.anything or Instrument.anything or ChartControl.anything in State.Configure. Those are not supported in State.Configure but they sort of coincidentally work on charts yet not on strategy analyzer. That doesn't mean that's the problem, but that's the sort of thing that is different in strategy analyzer than on a chart.
        Bruce DeVault
        QuantKey Trading Vendor Services
        NinjaTrader Ecosystem Vendor - QuantKey

        Comment


          #5
          Originally posted by QuantKey_Bruce View Post
          If it happens only in strategy analyzer, I would be looking first for things like if you are referencing Bars.anything or Instrument.anything or ChartControl.anything in State.Configure. Those are not supported in State.Configure but they sort of coincidentally work on charts yet not on strategy analyzer. That doesn't mean that's the problem, but that's the sort of thing that is different in strategy analyzer than on a chart.
          I have try and try but still not working. Please this is my code

          Code:
          #region Using declarations
          using System;
          using System.Collections.Generic;
          using System.ComponentModel;
          using System.ComponentModel.DataAnnotations;
          using System.Linq;
          using System.Text;
          using System.Threading.Tasks;
          using System.Windows;
          using System.Windows.Input;
          using System.Windows.Media;
          using System.Xml.Serialization;
          using NinjaTrader.Cbi;
          using NinjaTrader.Gui;
          using NinjaTrader.Gui.Chart;
          using NinjaTrader.Gui.SuperDom;
          using NinjaTrader.Gui.Tools;
          using NinjaTrader.Data;
          using NinjaTrader.NinjaScript;
          using NinjaTrader.Core.FloatingPoint;
          using NinjaTrader.NinjaScript.Indicators;
          using NinjaTrader.NinjaScript.DrawingTools;
          #endregion
          
          //This namespace holds Strategies in this folder and is required. Do not change it.
          namespace NinjaTrader.NinjaScript.Strategies
          {
              public class FluronixVixibotB : Strategy
              {
                  string OrderID = "www fluronix com";
                  private RSI rsiIndicator;
          
                  protected override void OnStateChange()
                  {
                      if (State == State.SetDefaults)
                      {
                          Description                                    = @"This is Buy only Vixibot. For more info visit fluronix.com";
                          Name                                        = "FluronixVixibotB";
                          Calculate                                    = Calculate.OnPriceChange;
                          EntriesPerDirection                            = 1;
                          EntryHandling                                = EntryHandling.AllEntries;
                          IsExitOnSessionCloseStrategy                = true;
                          ExitOnSessionCloseSeconds                    = 30;
                          IsFillLimitOnTouch                            = false;
                          MaximumBarsLookBack                            = MaximumBarsLookBack.TwoHundredFiftySix;
                          OrderFillResolution                            = OrderFillResolution.Standard;
                          Slippage                                    = 0;
                          StartBehavior                                = StartBehavior.WaitUntilFlat;
                          TimeInForce                                    = TimeInForce.Gtc;
                          TraceOrders                                    = false;
                          RealtimeErrorHandling                        = RealtimeErrorHandling.StopCancelClose;
                          StopTargetHandling                            = StopTargetHandling.PerEntryExecution;
                          BarsRequiredToTrade                            = 20;
                          // Disable this property for performance gains in Strategy Analyzer optimizations
                          // See the Help Guide for additional information
                          IsInstantiatedOnEachOptimizationIteration    = true;
                          BotID                    = 65342;
                          TradeQuantity            = 1;
                          QuantityMultiplier        = 1.6;
                          MinLevel                = 50;
                          TP                        = 40;
                          ____________________________                    = @"____________________________";
                          RSIP                    = 3;
                          RSIS                    = 1;
                          Stocs                    = 1;
                          OBlevel                    = 80;
                          OSlevel                    = 20;
                          VolatilityP                = 14;
                          VolatilityTimes            = 2;
                          Print("TOM1");
                      }
          
          
                      else if (State == State.Configure)
                      {
                          rsiIndicator = RSI(RSIP, RSIS);
                          AddChartIndicator(rsiIndicator);
          
                      }
          
                      //Displays text on chart indicating what account the strategy is applied to
                      //Draw.TextFixed(this, "tag1", "Strategy is applied to " + Account.Name, TextPosition.TopLeft);
          
                      else if (State == State.DataLoaded)
                          {
          
                              Print("JSOCK");
          
                          }
          
                  }
          
          
                  bool traded = false;
          
          
                  protected override void OnBarUpdate()
                  {
                      Print("TOM2");
          
                      if (BarsInProgress != 0)
                          return;
          
          
                      //Print(rsiIndicator[0]);
          
          
                      if(!traded){
                          PlaceTrade("long",1);
                          traded=true;
                      }
          
          
          
                      //double limitPrice = Low[0] - TickSize * 5;
          
          
          
                  }
          
          
          
          
                  //---------------------ORDER ENTRY------------------------------
                  bool PlaceTrade(string side, int volume, double TPprice=0){
                      if(side == "long"){
                          //place a buy position
                          EnterLong(volume,OrderID);
          
                          // set buylimit TP
                          ExitLongLimit(volume,TPprice);
                      }else {
                          //place a sell position
                          EnterShort(volume,OrderID);
          
                          // set selllimit TP
                          ExitShortLimit(volume, TPprice);
                      }
                      return true;
                  }
          
                  void RSI_Signal(){
          
                  }
          
                  #region Properties
                  [NinjaScriptProperty]
                  [Range(1, int.MaxValue)]
                  [Display(Name="BotID", Description="Bot unique identifyer number", Order=1, GroupName="Parameters")]
                  public int BotID
                  { get; set; }
          
                  [NinjaScriptProperty]
                  [Range(0.001, double.MaxValue)]
                  [Display(Name="TradeQuantity", Description="The trading Volume ", Order=2, GroupName="Parameters")]
                  public double TradeQuantity
                  { get; set; }
          
                  [NinjaScriptProperty]
                  [Range(1, double.MaxValue)]
                  [Display(Name="QuantityMultiplier", Description="The times to multiplier the quantity of the previous order", Order=3, GroupName="Parameters")]
                  public double QuantityMultiplier
                  { get; set; }
          
                  [NinjaScriptProperty]
                  [Range(1, int.MaxValue)]
                  [Display(Name="MinLevel", Order=4, GroupName="Parameters")]
                  public int MinLevel
                  { get; set; }
          
                  [NinjaScriptProperty]
                  [Range(40, int.MaxValue)]
                  [Display(Name="TP", Order=5, GroupName="Parameters")]
                  public int TP
                  { get; set; }
          
                  [NinjaScriptProperty]
                  [Display(Name="____________________________", Description="_", Order=6, GroupName="Parameters")]
                  public string ____________________________
                  { get; set; }
          
                  [NinjaScriptProperty]
                  [Range(1, int.MaxValue)]
                  [Display(Name="RSIP", Order=7, GroupName="Parameters")]
                  public int RSIP
                  { get; set; }
          
                  [NinjaScriptProperty]
                  [Range(1, int.MaxValue)]
                  [Display(Name="RSIS", Order=8, GroupName="Parameters")]
                  public int RSIS
                  { get; set; }
          
                  [NinjaScriptProperty]
                  [Range(1, int.MaxValue)]
                  [Display(Name="Stocs", Order=9, GroupName="Parameters")]
                  public int Stocs
                  { get; set; }
          
                  [NinjaScriptProperty]
                  [Range(1, int.MaxValue)]
                  [Display(Name="OBlevel", Order=10, GroupName="Parameters")]
                  public int OBlevel
                  { get; set; }
          
                  [NinjaScriptProperty]
                  [Range(1, int.MaxValue)]
                  [Display(Name="OSlevel", Order=11, GroupName="Parameters")]
                  public int OSlevel
                  { get; set; }
          
                  [NinjaScriptProperty]
                  [Range(1, int.MaxValue)]
                  [Display(Name="VolatilityP", Order=12, GroupName="Parameters")]
                  public int VolatilityP
                  { get; set; }
          
                  [NinjaScriptProperty]
                  [Range(1, int.MaxValue)]
                  [Display(Name="VolatilityTimes", Order=13, GroupName="Parameters")]
                  public int VolatilityTimes
                  { get; set; }
                  #endregion
          
              }
          }
          
          ​
          The only method that get called is the .OnStateChange()

          Comment


            #6
            tomtom555 You have to go into the strategy's properties on the chart and check the box Enabled.
            Bruce DeVault
            QuantKey Trading Vendor Services
            NinjaTrader Ecosystem Vendor - QuantKey

            Comment


              #7
              Originally posted by QuantKey_Bruce View Post
              tomtom555 You have to go into the strategy's properties on the chart and check the box Enabled.
              Okay lemme check

              Comment


                #8
                If you don't enable the strategy, you only get the print for SetDefaults because that's when it's loading the strategy list but is not the specific instance to run on the chart.
                Bruce DeVault
                QuantKey Trading Vendor Services
                NinjaTrader Ecosystem Vendor - QuantKey

                Comment


                  #9
                  Wow, it works now, Pardon me as a newbie who knowns nothing about Ninja trader
                  Last edited by tomtom555; 06-20-2023, 05:56 AM.

                  Comment


                    #10
                    Hello tomtom555,

                    Please also note that indicators cannot be called until State.DataLoaded.

                    The call to the RSI indicator and AddChartIndicator() will need to be moved to that state.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_ChelseaB View Post
                      Hello tomtom555,

                      Please also note that indicators cannot be called until State.DataLoaded.

                      The call to the RSI indicator and AddChartIndicator() will need to be moved to that state.
                      Thank you for the information

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      602 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      347 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by Mindset, 02-09-2026, 11:44 AM
                      0 responses
                      103 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                      0 responses
                      559 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      558 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X