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

Position.Quantity

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

    Position.Quantity

    When backtesting and using trade sizes of 200 shares. Using Postions[0].Quantity as I am below, is this calculating if less than 200 shares have been entered over the life of the backtest so far or is it just calculating if less than 200 shares are currently open?

    bool enterTrade = false;

    if (Positions[0].Quantity < 200)
    {
    enterTrade = true;
    }
    else
    {
    enterTrade = BarsSinceEntry(0, "", 0) > 2;
    }

    if(enterTrade)
    {
    //conditions
    }
    Last edited by zachj; 10-07-2013, 08:02 PM.

    #2
    zachj, the Position object will give you access to the current strategy market position, however you would monitor it for each OnBarUpdate() I suppose, so you would just iterate through the backtest bars by processing it there.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      What I'm trying to figure out is with the script I posted in initial post, when I have if (Positions[0].Quantity < 200) enterTrade otherwise BarsSinceEntry(0, "", 0) > 2; If i'm using 5min bars as primary(but BIP is on 1min) shouldn't this stop a trade from occuring 1minute later? The goal is to require 10min pass between trades. The trade data from SA below shows trades 1min apart. Is this a matter of OnExecution being required? That way it will update the data(200 shares traded) when trade is executed instead of 5min later after primary bar is closed.

      Instrument Entry price Exit price Entry time Exit time
      SCTY 39.73 38.54 6/5/2013 9:51 AM 6/5/2013 9:55 AM
      SCTY 39.7 38.51 6/5/2013 9:52 AM 6/5/2013 9:55 AM

      Note: I can't use (Performance.AllTrades.Count < 1) because I'm using multi instrument script.
      Last edited by zachj; 10-08-2013, 07:29 PM.

      Comment


        #4
        zachj, best would be bringing in the actual execution time and then ensure for any new signal seen on the 1 min that the current time would be higher than previous execution time + 10 for your signals. Generally your BarsSinceEntry will report based on the primary series for each instrument - from which BarsInProgress were you evaluating the first posted snippet? I would add in debug prints to exactly see which condition part leads to your unexpected entry.
        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by geddyisodin, Today, 05:20 AM
        2 responses
        16 views
        0 likes
        Last Post geddyisodin  
        Started by hazylizard, Today, 08:38 AM
        0 responses
        6 views
        0 likes
        Last Post hazylizard  
        Started by Max238, Today, 01:28 AM
        5 responses
        43 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by giulyko00, Yesterday, 12:03 PM
        3 responses
        13 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by habeebft, Today, 07:27 AM
        1 response
        16 views
        0 likes
        Last Post NinjaTrader_ChristopherS  
        Working...
        X