• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Positons Exits based on AccountPos

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

  • NinjaTrader_ChelseaB
    replied
    Hi everington_f,

    That would confirm that somewhere in the script, a bar more than 3 bars ago is being called. Always ensure that the index being called exists before calling that index.
    You can also use .ContainsValue() to check a value exists.

    For intra-bar granularity, add an addition series of 1 tick for each instrument type.
    AddDataSeries("ADS", Data.BarsPeriodType.Tick, 1);

    Then adjust the BarsInProgress indexes used in the conditions for the logic and conditions and for order submissions to be for the corresponding tick series.

    Leave a comment:


  • elliot5
    replied
    Adding tick bar series

    I have solved that barsloading error problem by just increasing the number from 3 to 50. How do we add granularity to the strategy that currently loads:

    else if (State == State.Configure)
    {
    AddDataSeries("ADS", Data.BarsPeriodType.Minute, 510);
    AddDataSeries("BAS", Data.BarsPeriodType.Minute, 510);
    AddDataSeries("BAYN", Data.BarsPeriodType.Minute, 510);
    AddDataSeries("BMW", Data.BarsPeriodType.Minute, 510);
    AddDataSeries("BEI", Data.BarsPeriodType.Minute, 510);
    AddDataSeries("CBK", Data.BarsPeriodType.Minute, 510);
    AddDataSeries("ALV", Data.BarsPeriodType.Minute, 510);
    AddDataSeries("DCX", Data.BarsPeriodType.Minute, 510);

    Regards and thx

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello everington_f,

    You should always check that an index exists before trying to use that index..

    For example if the furthest you look is 5 bars back, make sure there are 5 bars of historical data before calling 5 bars back.

    It appears something like this is going on in the script.

    Which line of code is causing the error?
    Perhaps 3 bars is not enough bars for what is being called back in the script?

    Leave a comment:


  • elliot5
    replied
    Having removed the Historical check, now the strategy cannot enable owing to an out of range error...I have a currentbars check in place already......

    // if(State == State.Historical)
    // return;

    for (int j = 0; j < CurrentBars.Length; j++)
    {
    if (CurrentBars[j] < 3)
    return;
    }

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello everington_f,

    By adding if (Historical) return; to the script, the script is no longer working historically, and will not resume any orders and cannot cancel any orders made previously.

    The strategy will always start as flat.

    If you want your strategy to resume properly, it must process the same orders historically that it does in realtime. This means it must backtest. For accuracy in historical data, you also need 1 tick intra-bar granularity.

    Please see the post that I have linked you at the beginning of this thread, which details this.
    http://ninjatrader.com/support/forum...117#post463117

    Leave a comment:


  • elliot5
    replied
    Yes I do have the check

    if(State == State.Historical)
    return;


    So the removal of this check should enable a restarted strategy to be in a strategy position equal to that if it had not be disabled?

    Regards and many thx

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello everington_f,

    Do you have if (Historical) return; at the beginning of OnBarUpdate in the script?

    If so, when restarting the script will not take a historical position at all and will always start flat.

    If you do not have this at the beginning of OnBarUpdate then your script is indeed running a backtest (historical) before running live data.

    All scripts when enabled process the available historical data as a backtest before running live data. This backtest is used to calculate a historical position, and historical trades, and attempt to match these to recorded trades in the database made at the same time and price and from the same strategy.

    If the historical trades do not match the real-time trades exactly, they will not be matched and will not be resumed.

    Try adding the SampleMACrossOver script to a chart and enable this. You will notice that the chart is full of trades even though the script has not been running in real time. These trades are theoretical backtest trades.
    Right-click that chart -> select Strategy Performance -> select the SampleMACrossOver. In this submenu you are able to view Historical performance (backtest), Real-time performance, or both Historical and Real-time performance.

    Below is a link to the help guide on differences between Real-Time and Backtest for NT8.
    http://ninjatrader.com/support/helpG...ime_vs_bac.htm

    Leave a comment:


  • elliot5
    replied
    No 1 tick series has been added to the array list. The strategy is not being backtested.. only run live. There were no exit orders placed before it was disabled. There were 7 positions... no open orders... then disabled. Then restarted.... what is required is the ability for the logic to exit those positions in certain conditions once re-enabled.

    if (BarsInProgress == i
    && PositionsAccount[i].MarketPosition == MarketPosition.Short
    && Closes[i][0] <= MIN(Closes[i],5)[0])

    {
    ExitShort(i,PositionsAccount[i].Quantity,"SwingShort"+i,"ExitShort"+i);
    }

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello everington_f,

    May I confirm that for each series added a 1 tick series of each of the series is added as well for historical 1 tick granularity?

    The 1-tick granularity is so that the script calculates the same historically as it does in real time (or as close as possible).

    Just to confirm, the script placed an exit order before it was disabled, however, upon re-enabling the position shows up as if that specific exit has not occurred, is this correct?

    Leave a comment:


  • elliot5
    replied
    The script was closed over the weekend, with 7 positions on friday close, and has not added or closed a position since the open this morning becuause the exit code is not working. It is run on an array of 30 stocks, ADD () on 510 minute bars... from the strategies tab. OnBarUpdate with OnPriceChange the GUI imput. Regards
    Last edited by elliot5; 08-29-2016, 10:34 AM.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello everington_f,

    Did the script calculate a new position from the time it was disabled to when it was re-enabled?

    May I confirm you have 1 tick granularity added to the script and the orders are being submitted to the 1 tick series?

    Leave a comment:


  • elliot5
    replied
    Thankyou Chelsea I already have the strategy set to Submit immediately - but again upon restart it appears that the ExitShort code will not detect the execution that had taken place before the computer restart......

    How can we code an exit to a pre-restart account position? See my code pls to appreciate the issue
    Last edited by elliot5; 08-29-2016, 08:46 AM.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hi everington_f,

    Those instructions were previously written for NinjaTrader 7.

    The Tools -> Strategies -> NinjaScript -> 'On starting a real-time strategy' option has been moved to the strategy parameters as 'Start behavior'.

    In NT8 Beta, right-click the chart -> select Strategies... (or right-click the Strategies tab of the Control Center and select New Strategy...)
    Select the strategy (in the chart Strategies window click the New button)
    In the parameters set Start behavior to Immediately submit (or Immediately submit, synchronize account).

    The information about needing intra-bar granularity is the same.

    Leave a comment:


  • elliot5
    replied
    Thankyou Chelsea - I do not see the option on my NT8:

    Click Tools -> Options... -> select the Strategies tab -> select the NinjaScript sub-tab
    Select the radio button option Immediately submit live working historical orders -> Click OK
    When starting a new instance of the strategy set the Sync account position parameter to True

    I am not sure that the thread post you mentioned helps me understand the issue better in terms of what I am trying to do with the mentioned code.

    Will ExitShort work on a restarted strategy?

    Regards
    Last edited by elliot5; 08-29-2016, 08:26 AM.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello everington_f,

    It is possible for NinjaTrader to resume a strategy as long as the market data produced by the market has not caused the strategy to calculate a new position.

    I've detailed this previously in another thread which I am linking below.
    http://ninjatrader.com/support/forum...117#post463117

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by mtamaku, Today, 06:54 PM
0 responses
7 views
0 likes
Last Post mtamaku
by mtamaku
 
Started by Lumbeezl, Today, 06:32 PM
0 responses
4 views
0 likes
Last Post Lumbeezl  
Started by ozziyhtomit, Today, 05:24 PM
0 responses
3 views
0 likes
Last Post ozziyhtomit  
Started by AnotherWorkingHomeless, Today, 08:45 AM
0 responses
20 views
0 likes
Last Post AnotherWorkingHomeless  
Started by RumHam, 07-02-2020, 12:14 PM
2 responses
37 views
0 likes
Last Post smtraderca  
Working...
X