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

getcurrentbidaskvol

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

    getcurrentbidaskvol

    Is there any way of getting a cumulative total of GetCurrentAskVolume() throughout a bar using OnBarUpdate? I'm experimenting with something, and when I use OnMarketData I get the error 'error calling 'calculateminmax.... unrenderable values'.

    Just wondering.
    Thanks.

    #2
    Hello imalil,

    You are simply printing the .Price or .Volume of the argument in OnMarketData to the output window and this is causing an error?

    Can you create an export of a simplified script with only that line of code in OnMarketData that is able to reproduce the error and share this?


    You can accumulate numbers to a variable. This would fall under general C# and would not be specific to NinjaScript.

    For example:
    private int myInt;

    in State.DataLoaded or State.Historical:
    myInt = 0;

    In OnBarUpdate:
    myint += GetCurrentAskVolume();

    Print(myInt);

    Below is a link to a 3rd party education site that demonstrates.
    Use increment, preincrement and decrement on ints. See benchmarks for these operations.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Sorry in advance for the stupid questions. I'll be more specific with my issue. I am able to accumulate the GetCurrentAskVolume(), that is not my problem. what I am trying to do is accumulate GetCurrentAskVolume() for the current bar, clear it out, then start fresh with a new bar.

      As I understand it, GetCurrentAskVolume() gives you current ask vol at current tick. When I zero out my variable for the next bar, then start accumulating, I appear to be getting GetCurrentAskVolume() for one tick. I want to capture all these tick ask volumes within a bar, add them up and get a value. I then want to clear it out for the next bar.

      So my question is: is it possible to accumulate GetCurrentAskVolume()s throughout a bar, get that value, then zero out for the next bar while in OnBarUpdate?

      Thank you.

      Comment


        #4
        Hello imalil,

        What do you have Calculate set to for the script?

        Is the script running tick for tick?

        Is this realtime only or both historical and real-time?

        Is TickReplay enabled?

        If Calculate is set to .OnEachTick, yes, you can accumulate GetCurrentAskVolume() to a variable then set the variable to 0 on the first tick of a new bar in OnBarUpdate.

        (I use a long as the variable type as the volume is returned as a long. Just one less step so I don't have to convert it to an int (which is smaller))

        Code:
        private long myLong;
        
        protected override void OnBarUpdate()
        {
        	if (IsFirstTickOfBar)
        		myLong = 0;
        
        	myLong += GetCurrentAskVolume();
        
        	Print(myInt);
        }

        You can accumulate volume to a variable in OnMarketData then set the variable to 0 when the bar closes in OnBarUpdate.

        Code:
        private long myLong;
        
        In State.DataLoaded or State.Historical:
        myLong = 0;
        
        protected override void OnBarUpdate()
        {
        	myLong = 0;
        }
        
        protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
        {
        	myLong += marketDataUpdate.Volume;
        }
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by rocketman7, Today, 02:12 AM
        5 responses
        23 views
        0 likes
        Last Post rocketman7  
        Started by trilliantrader, 04-18-2024, 08:16 AM
        7 responses
        28 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by samish18, 04-17-2024, 08:57 AM
        17 responses
        66 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by briansaul, Today, 05:31 AM
        1 response
        15 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by PaulMohn, Today, 03:49 AM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Working...
        X