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

No overload for bar method

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

    No overload for bar method

    I am looking for help and an explanation of what I am doing wrong here with my code. I have very little experience with coding and am attempting to learn ninjascript on my own so I apologize if this is a simple error. Below is my code and the error I am recieving. Thanks!

    No overload for method "barvolume" takes 0 arguments. CS1501

    Code:
    namespace NinjaTrader.NinjaScript.Indicators
    {
    	public class JBSwingbars : Indicator
    	{
    		SMA _volsma;
    		VOL _volume;
    		
    		protected override void OnStateChange()
    		{
    			if (State == State.SetDefaults)
    			{
    				Description									= @"Plots a dot at an area where HH/HL transitions to LH/LL.";
    				Name										= "JBSwingbars";
    				Calculate									= Calculate.OnBarClose;
    				IsOverlay									= false;
    				DisplayInDataBox							= true;
    				DrawOnPricePanel							= true;
    				DrawHorizontalGridLines						= false;
    				DrawVerticalGridLines						= false;
    				PaintPriceMarkers							= true;
    				ScaleJustification							= NinjaTrader.Gui.Chart.ScaleJustification.Right;
    				//Disable this property if your indicator requires custom values that cumulate with each new market data event. 
    				//See Help Guide for additional information.
    				IsSuspendedWhileInactive					= true;
    				AddPlot(new Stroke(Brushes.DodgerBlue, 2), PlotStyle.Dot, "Buy");
    				AddPlot(new Stroke(Brushes.Red, 2), PlotStyle.Dot, "Sell");
    				
    				int _currentplot;
    				int _lastplot;
    				
    			}
    			else if (State == State.Configure)
    			{
    				AddDataSeries(Data.BarsPeriodType.Day, 1);
    				_volume = VOL();
    				_volsma = SMA(_volume,576);     // SMA on volume for the past 2 days on 5min chart
    			}
    		}
    
    		protected override void OnBarUpdate()
    		{
    			//  Check to make sure there are enough bars on chart.
    			if (base.CurrentBar < 576)
    			{
    				return;
    			}
    			// If the volume is not greater than moving average during then do not trade.
    			if (barvolume() == false)
    			{
    				return;
    			}
    			//  If current bar shows sell signal plot a red dot.
    			if (_currentplot != _lastplot && _currentplot == -1)
    			{
    				// place code here to draw dot on chart.
    			}
    			//  If current bar shows a buy signal plot a blue dot.
    			if (_currentplot != _lastplot && _currentplot == 1)
    			{
    				// place code here to draw dot on chart.
    			}
    		}
    
    		#region methods
    		
    		bool barvolume(double _volume, double _volsma)  //If the volume is not above the SMA do not plot a dot.
    		{
    			get	{return _volume > _volsma;}
    		}
    
    		#endregion

    #2
    Originally posted by bauerjj10 View Post
    I am looking for help and an explanation of what I am doing wrong here with my code. I have very little experience with coding and am attempting to learn ninjascript on my own so I apologize if this is a simple error. Below is my code and the error I am recieving. Thanks!

    No overload for method "barvolume" takes 0 arguments. CS1501

    Code:
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public class JBSwingbars : Indicator
        {
            SMA _volsma;
            VOL _volume;
            
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @"Plots a dot at an area where HH/HL transitions to LH/LL.";
                    Name                                        = "JBSwingbars";
                    Calculate                                    = Calculate.OnBarClose;
                    IsOverlay                                    = false;
                    DisplayInDataBox                            = true;
                    DrawOnPricePanel                            = true;
                    DrawHorizontalGridLines                        = false;
                    DrawVerticalGridLines                        = false;
                    PaintPriceMarkers                            = true;
                    ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                    //Disable this property if your indicator requires custom values that cumulate with each new market data event. 
                    //See Help Guide for additional information.
                    IsSuspendedWhileInactive                    = true;
                    AddPlot(new Stroke(Brushes.DodgerBlue, 2), PlotStyle.Dot, "Buy");
                    AddPlot(new Stroke(Brushes.Red, 2), PlotStyle.Dot, "Sell");
                    
                    int _currentplot;
                    int _lastplot;
                    
                }
                else if (State == State.Configure)
                {
                    AddDataSeries(Data.BarsPeriodType.Day, 1);
                    _volume = VOL();
                    _volsma = SMA(_volume,576);     // SMA on volume for the past 2 days on 5min chart
                }
            }
    
            protected override void OnBarUpdate()
            {
                //  Check to make sure there are enough bars on chart.
                if (base.CurrentBar < 576)
                {
                    return;
                }
                // If the volume is not greater than moving average during then do not trade.
                if (barvolume() == false)
                {
                    return;
                }
                //  If current bar shows sell signal plot a red dot.
                if (_currentplot != _lastplot && _currentplot == -1)
                {
                    // place code here to draw dot on chart.
                }
                //  If current bar shows a buy signal plot a blue dot.
                if (_currentplot != _lastplot && _currentplot == 1)
                {
                    // place code here to draw dot on chart.
                }
            }
    
            #region methods
            
            bool barvolume(double _volume, double _volsma)  //If the volume is not above the SMA do not plot a dot.
            {
                get    {return _volume > _volsma;}
            }
    
            #endregion
    Your definition of the method requires 2 parameters. You are now trying to call the method with no parameters. The compiler is telling you that you cannot do that.

    Wherever you have barvolume(), change it to the correct call. Try: barvolume(_volume, _volsma)

    What I have written is in accordance with how you have written things. Your writing is not a good idea, as you are using the same variable names to define signatures as you are using to perform actions. It makes it confusing to know which is which.

    Comment


      #3
      Thanks for your help. Since I am very new to programming and only learning from youtube videos and what I can find in the ninjatrader forum and NT8 manual it has been a slow process.

      Could you help me understand the proper way to code this?

      Does this look better?

      if (barvolume(_volume,_volsma) == false)
      {
      return;
      }


      bool barvolume(double x, double y)
      {
      get {return x > y;}
      }

      Comment


        #4
        Hello bauerjj10,

        Yes, this would match the parameters for the call to the bool method.

        When using a bool method and always giving new input, the get (and set) no longer become necessary.

        Below I am including a publicly available link to a 3rd party educational site on bool methods and returns.
        Create methods and properties that return bools, testing for complex conditions.


        Also, below is a link to a forum post with helpful information about getting started with NinjaScript. Many of these resources in this post you have found.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          You might want to write your method as:
          Code:
          private bool barvolume(double x, double y)
          {
             return x > y;
          }

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by terofs, Today, 04:18 PM
          0 responses
          3 views
          0 likes
          Last Post terofs
          by terofs
           
          Started by nandhumca, Today, 03:41 PM
          0 responses
          4 views
          0 likes
          Last Post nandhumca  
          Started by The_Sec, Today, 03:37 PM
          0 responses
          3 views
          0 likes
          Last Post The_Sec
          by The_Sec
           
          Started by GwFutures1988, Today, 02:48 PM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Started by ScottWalsh, 04-16-2024, 04:29 PM
          6 responses
          33 views
          0 likes
          Last Post ScottWalsh  
          Working...
          X