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 add up open positions weird

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

  • NinjaTrader_ChelseaB
    replied
    Hello johnnybegoode,

    The Strategies tab is showing a strategy position not an account position.

    This means you have either run the strategy once before or you have enabled it and there are historical orders.

    You can code the script to not evaluate historically with if (State == State.Historical) return; and then remove the instances of the strategy and add a new instance.

    Leave a comment:


  • johnnybegoode
    replied
    I reset and cleared the history of 2 Simulated FXCM accounts, but there are still POSITION and UNREALIZED under the strategy tab that I could not get rid of.
    I'd even tried deleting the whole DB folder.
    Attached Files
    Last edited by johnnybegoode; 03-21-2019, 12:32 AM.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello johnnybegoode,

    What is the issue you are trying correct?

    You are expecting the very large positions with the extremely large number of entry orders right?
    The logic of the script is allowing for many new entries in the same direction.

    The inquiry is why is the 'EXIT LONG EURUSD (ProfitTarget)' appearing early in the orders display, is this correct?

    The exit amount appears correct, but all of the entry orders that make up the position are missing, is this correct?

    And to confirm, using the script I have provided, the exit appearing to early occurred on your end?

    At what time and date, and on what instrument did you start the playback?
    At what time and date did the early exit appear?

    Leave a comment:


  • johnnybegoode
    replied
    Thanks for the video!
    I was expecting and looking for what you got in the video.

    I renamed mine as OLD and import your script and it did the weirdly huge "Entry/Exit" positions on my NT8 too.
    It is not the script.

    Then I use other Dates on Market Replay that I had not run the strategy on before
    and it works like in the video for a while.

    However, the problem returns after some testing and coding.
    Removing and Re-downloading Market Replay does not help.

    Deleting NinjaTrader.sdf does not help.

    I'm using version 8.0.17.2 64-bit.
    I had tried repairing but the problem persists.

    The weird position size also sometimes does mysteriously appear under the position of the strategy tab.
    (See photo)

    Then again, I have another strategy that is running in a real-time simulation (forward testing) that is getting weirdly huge positions.
    using Position.Quantity. on another PC and NT8 (8.0.17.0)

    Is there a way to clean caches caused by strategy testing if there are any?
    Attached Files
    Last edited by johnnybegoode; 03-07-2019, 12:00 AM.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello johnnybegoode,

    The behavior that I experienced was not the same as what is showing in the screenshot you have provided.

    As this text of the code was provided instead of an exported script, I copied the code into a new script and tested.

    Below is a link to a video of a test of this code.
    https://drive.google.com/file/d/141h...w?usp=drivesdk

    I'm showing that there are many entries that lead to a large position and then the EXIT LONG EURUSD (ProfitTarget) exits that large position.

    Was the start behavior of this script changed to adopt account position in the strategy parameters when adding an instance of the strategy?

    Attached is an export of the script I tested.

    Using this export are you getting different behavior than what I have shown in the video?



    As a tip, To export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
    1. Click Tools -> Export -> NinjaScript...
    2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
    3. Click the 'Export' button
    4. Enter a unique name for the file in the value for 'File name:'
    5. Choose a save location -> click Save
    6. Click OK to clear the export location message
    By default your exported file will be in the following location:
    • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
    Below is a link to the help guide on Exporting NinjaScripts.
    http://ninjatrader.com/support/helpG...-us/export.htm
    Attached Files

    Leave a comment:


  • Position.Quantity add up open positions weird

    "Position.Quantity" add up open positions weird.

    How did Position.Quantity get 18,490,000? Image attached.
    when I only have 2 positions 10,000 + 10,000 = 20,000
    when I EXIT LONG EURUSD (ProfitTarget).


    Code:
    //This namespace holds Strategies in this folder and is required. Do not change it. 
    namespace NinjaTrader.NinjaScript.Strategies
    {
        public class LastEntryPrice : Strategy
        {
            private Order entryOrder;
    
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @"Enter the description for your new custom Strategy here.";
                    Name                                        = "LastEntryPrice";
                    Calculate                                    = Calculate.OnEachTick;
                    EntriesPerDirection                            = 999999999;
                    EntryHandling                                = EntryHandling.AllEntries;
                    IsExitOnSessionCloseStrategy                = false;
                    ExitOnSessionCloseSeconds                    = 30;
                    IsFillLimitOnTouch                            = false;
                    MaximumBarsLookBack                            = MaximumBarsLookBack.TwoHundredFiftySix;
                    OrderFillResolution                            = OrderFillResolution.Standard;
                    Slippage                                    = 9999999999;
                    StartBehavior                                = StartBehavior.ImmediatelySubmit;
                    TimeInForce                                    = TimeInForce.Gtc;
                    TraceOrders                                    = false;
                    RealtimeErrorHandling                        = RealtimeErrorHandling.StopCancelClose;
                    StopTargetHandling                            = StopTargetHandling.PerEntryExecution;
                    BarsRequiredToTrade                            = 0;
                    // Disable this property for performance gains in Strategy Analyzer optimizations
                    // See the Help Guide for additional information
                    IsInstantiatedOnEachOptimizationIteration    = true;            
                }
    
                else if (State == State.Configure)
                {
    
                }
    
                else if (State == State.DataLoaded)
                {        
    
                }
    
            }
    
            protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
    {    
        if (order.Name == "EnterLong")
          entryOrder = order;
    }        
    
            protected override void OnBarUpdate()
            {        
                int Quantity = 10000;
                double Profit = 
                    (
                    PositionAccount.GetUnrealizedProfitLoss(PerformanceUnit.Currency, Close[0])
                    );
                Account a = Account.All.First(t => t.Name == "Playback101"); // Account Display Name
                double Balance = a.Get(AccountItem.CashValue, Currency.UsDollar);
                double ProfitTarget = Balance*0.005;
    
                 // Set 1
                if (
                    (Open[0]-Low[0] >= 0.00003)
                    )
                {
                    EnterLong(Quantity,"EnterLong");
                }
    
                double lastentryprice = 0;
                if (entryOrder != null && entryOrder.OrderState == OrderState.Filled)
                lastentryprice = entryOrder.AverageFillPrice;    
                Print(lastentryprice);    
    
                if (
                    (lastentryprice >=  Open[0])
                    && (PositionAccount.Quantity >= 1)
                    && (BarsInProgress == 0)
                    )
                {
                      EnterLong(0,Quantity,"EURUSD1");    
                }    
    
                if     (
                    Profit>= ProfitTarget
                    )                             
                {                        
                    ExitLong(0,Position.Quantity,"EXIT LONG EURUSD (ProfitTarget)","");
                }
    
    
            }                
        }
    }
    Attached Files

Latest Posts

Collapse

Topics Statistics Last Post
Started by Pattontje, Yesterday, 02:10 PM
2 responses
14 views
0 likes
Last Post Pattontje  
Started by flybuzz, 04-21-2024, 04:07 PM
17 responses
229 views
0 likes
Last Post TradingLoss  
Started by agclub, 04-21-2024, 08:57 PM
3 responses
17 views
0 likes
Last Post TradingLoss  
Started by TradingLoss, 04-21-2024, 04:32 PM
4 responses
44 views
2 likes
Last Post TradingLoss  
Started by cre8able, 04-17-2024, 04:16 PM
6 responses
56 views
0 likes
Last Post cre8able  
Working...
X