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

SMA with Bid/ask Volume

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

    SMA with Bid/ask Volume

    I would like to create a new SMA with the Bidvoulme and the askvolume.
    First I have to create a dataserie that is:
    [(Askvolume(0) + Askvolume(1) + Askvolume(2) + Askvolume(3) + Askvolume(4)) - (Bidvolume(0) + Bidvolume(1) + Bidvolume(2) + Bidvolume(3) + Bidvolume(4))] / [(Askvolume(0) + Askvolume(1) + Askvolume(2) + Askvolume(3) + Askvolume(4)) + (Bidvolume(0) + Bidvolume(1) + Bidvolume(2) + Bidvolume(3) + Bidvolume(4))]

    What do I need to ad to the SMA code for developing this indicator? Thank you
    The SMA code is:

    //
    // Copyright (C) 2006, NinjaTrader LLC <www.ninjatrader.com>.
    // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
    //

    #region Using declarations
    using System;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.ComponentModel;
    using System.Xml.Serialization;
    using NinjaTrader.Data;
    using NinjaTrader.Gui.Chart;
    #endregion

    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
    /// <summary>
    /// The SMA (Simple Moving Average) is an indicator that shows the average value of a security's price over a period of time.
    /// </summary>
    [Description("The SMA (Simple Moving Average) is an indicator that shows the average value of a security's price over a period of time.")]
    public class SMA : Indicator
    {
    #region Variables
    private int period = 14;
    #endregion

    /// <summary>
    /// This method is used to configure the indicator and is called once before any bar data is loaded.
    /// </summary>
    protected override void Initialize()
    {
    Add(new Plot(Color.Orange, "SMA"));

    Overlay = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick).
    /// </summary>
    protected override void OnBarUpdate()
    {
    if (CurrentBar == 0)
    Value.Set(Input[0]);
    else
    {
    double last = Value[1] * Math.Min(CurrentBar, Period);

    if (CurrentBar >= Period)
    Value.Set((last + Input[0] - Input[Period]) / Math.Min(CurrentBar, Period));
    else
    Value.Set((last + Input[0]) / (Math.Min(CurrentBar, Period) + 1));
    }
    }

    #region Properties
    /// <summary>
    /// </summary>
    [Description("Numbers of bars used for calculations")]
    [GridCategory("Parameters")]
    public int Period
    {
    get { return period; }
    set { period = Math.Max(1, value); }
    }
    #endregion
    }
    }

    #2
    alovi, are you looking to average the bid / ask volume from multiple series?

    The SMA method will accept a custom data series as input as well:

    double value = SMA(yourCustomDataSeries, 20)[0];

    BertrandNinjaTrader Customer Service

    Comment


      #3
      I want to average the Bid/ask volume in single series, by example eminiSP500, but the data that I want to average is not a single data (close, open,...), is a customdataserie that I have to create it first and I don´t know exactly how to create it.

      Comment


        #4
        alovi, for working with custom DataSeries objects, please see this introductory sample first - http://www.ninjatrader.com/support/f...ead.php?t=7299

        You first want to record your GetCurrentBid / Ask Volume double value into a series object and then pass this series as input to your SMA indicator / method.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          I read the introductory sample but I didn´t find a real sample for using it as reference.
          żHow I create a dataserie with the last five bidvolume by example?
          Thank you

          Comment


            #6
            You can't access historical bid / ask data with those commands, you would need to store the data in the data series in realtime as you move forward and then you could calculate your average.



            With myDataSeries defined in your Initialize(), you would use the .Set command to fill it with values.

            myDataSeries.Set(GetCurrentAskVolume());

            To access historical bid / ask data a MultiSeries script is needed and above all your broker / feed would need to support this backfill data:

            BertrandNinjaTrader Customer Service

            Comment


              #7
              Then how I define myDataSeries first for later using the .set comand?
              My data provider is Zen Fire

              Comment


                #8
                Please have a look at the 2 links I posted, one to the reference sample on DataSeries and then other from our helpguide explaing the details.

                Code:
                #region Variables
                private DataSeries myDataSeries; // Define a DataSeries variable
                #endregion 
                
                // Create a DataSeries object and assign it to the variable
                protected override void Initialize() 
                {
                
                     myDataSeries = new DataSeries(this);
                }
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  Then is right this code?

                  #region Variables
                  private DataSeries BidVolume;
                  private DataSeries AskVolume;
                  privateint period = 20;
                  privateint smooth = 3;
                  #endregion
                  ///<summary>
                  protectedoverridevoid Initialize()
                  {
                  Add(
                  new Plot(Color.Green, "Bid/askVolume"));

                  BidVolume = new DataSeries(this);
                  AskVolume =
                  new DataSeries(this);
                  }
                  protectedoverridevoid OnBarUpdate()
                  {
                  if (CurrentBar == 0)
                  {
                  BidVolume.Set(
                  0);
                  AskVolume.Set(
                  0);
                  return;
                  }
                  down.Set(BidVolume(0) + BidVolume(1) + BidVolume(2) + BidVolume(3) BidVolume(4)
                  );
                  up.Set(AskVolume(0) + AskVolume(1) + AskVolume(2) + AskVolume(3) AskVolume(4
                  ));

                  Comment


                    #10
                    Hi alovi, this will not work, as there's no place in the code where actually store the GetCurrentAsk BidVolume into your dataseries to average it later. Also: if you would like to refer to an element of the dataseries object you would do so by indexing with [x] brackets.
                    BertrandNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Tburg1073, Today, 08:36 AM
                    0 responses
                    5 views
                    0 likes
                    Last Post Tburg1073  
                    Started by alexstox, 10-16-2018, 03:29 PM
                    10 responses
                    333 views
                    0 likes
                    Last Post Tburg1073  
                    Started by smartromain, 03-13-2024, 01:42 AM
                    6 responses
                    98 views
                    0 likes
                    Last Post smartromain  
                    Started by Jonker, 04-27-2024, 01:19 PM
                    4 responses
                    29 views
                    0 likes
                    Last Post Jonker
                    by Jonker
                     
                    Started by Yasharandom, Today, 07:45 AM
                    0 responses
                    5 views
                    0 likes
                    Last Post Yasharandom  
                    Working...
                    X