Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Volume[0] > Volume[-1] help and clarification

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

    Volume[0] > Volume[-1] help and clarification

    Hello Ninjatrader team,

    I am just wondering if I have, Volume[0] > Volume[-1] enter long and exit next bar. will this work on Ninjatrader 7 in live account? when I click strategy -> historical results I do see results from the past. However, when I try this on the live account no trades are taken. Furthermore, when I click refresh chart[ on live account] new signals appear that before never executed. Finally, when I go under logs I see no error. Any advice is appreciated.

    Thank you
    Last edited by wallsteetking; 08-11-2016, 04:54 PM. Reason: help and clarification

    #2
    Hello,

    Thank you for your note.

    You are using a negative index on the barsAgo for Volume with Volume[1], which references the bar ahead of the current bar processing. The reason this works historically and why upon reloading the chart or NinjaScript is because these values exist, but in real time Volume[-1] is in the future, 1 bar.

    Additionally you may also wish to add (CurrentBar < 1 ) return; to your code. The statement (CurrentBar < 1 ) checks to make sure there is at least 1 bar of data before continuing and should be added to the top of OnBarUpdate(). Bars process from left to right, if there is no prior bar data, you'll get an error.

    The code should look like,

    if (CurrentBar < 1 ) return ;

    if (Volume[ 1] > Volume[0])
    {
    EnterLong(DefaultQuantity, "");
    }

    // Condition set 2
    if (BarsSinceEntry() >= 1)
    {
    ExitLong( "", "" );
    }

    CurrentBar section of our helpguide:



    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Hello AlanP,

      would the original code work if it was done on a daily time frame? Or would ninjatrader updated the strategy and recalculate script every time a new bar(day) comes.

      Furthermore, if I understand this correctly when I have this as the code if (Volume[ 0] > Volume[-1]) it first looks into the future and then goes back and takes the trade? Am i understanding this correct?

      Finally, is there a way to make the original code that I showed work correctly but written like I did? (see example script)

      if (CurrentBar < 1 ) return ;

      if (Volume[ 0] > Volume[-1])
      {
      EnterLong(DefaultQuantity, "");
      }

      // Condition set 2
      if (BarsSinceEntry() >= 1)
      {
      ExitLong( "", "" );
      }

      Comment


        #4
        Hello Wallsteetking,

        The code would not work on a daily time frame as Volume[-1] would not exist yet.

        Yes, Volume[-1] would look into the future then go back 1 bar and make the trade.

        You would not be able to reference a [-1] index value in a live environment because its trying to evaluate a piece of information which does not exist. To get (Volume[0] > Volume[-1]) to work correctly, you should shift the index values over 1 spot so that all required information is available at the time the trade is placed, thus your statement becomes (Volume[ 1] > Volume[0]).

        The code should look like,

        if (CurrentBar < 1 ) return ;

        if (Volume[ 1] > Volume[0])
        {
        EnterLong(DefaultQuantity, "");
        }

        // Condition set 2
        if (BarsSinceEntry() >= 1)
        {
        ExitLong( "", "" );
        }
        Alan P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by poplagelu, Today, 05:00 AM
        0 responses
        3 views
        0 likes
        Last Post poplagelu  
        Started by fx.practic, 10-15-2013, 12:53 AM
        5 responses
        5,407 views
        0 likes
        Last Post Bidder
        by Bidder
         
        Started by Shai Samuel, 07-02-2022, 02:46 PM
        4 responses
        98 views
        0 likes
        Last Post Bidder
        by Bidder
         
        Started by DJ888, Yesterday, 10:57 PM
        0 responses
        8 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by MacDad, 02-25-2024, 11:48 PM
        7 responses
        160 views
        0 likes
        Last Post loganjarosz123  
        Working...
        X