Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Control Panel Orders shows no Order when an Orders must have occurred?

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

    Control Panel Orders shows no Order when an Orders must have occurred?

    I have a test strategy which should just buy 100 lots and hold it.

    In the strategy analyser simulation it works as expected, but when I use try to paper trade it using "control centre"-> strategies, the Print() output that I do indicates that the 100 lots has indeed been bought and held, but the "orders", "executions" and "trades" tabs are empty. There is no record of the trade having occurred despite the Positions[] array clearly showing that there is a position.

    The code I am using is: [I have to make sure to run it in EUR or GBP with PeroidType and Period matching what is written in the program but that is by-the-by for now]
    Code:
    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Indicator;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Strategy;
    #endregion
    
    
    // aStrategy is a test strategy to be executed within the multi instrument framework.
    namespace NinjaTrader.Strategy
    {
        public class aStrategy : Strategy
        {
            #region Variables
            public static Strategy so;
            public static int [] positions; // for output of required positons
            #endregion
            public static void executeOnInitialize(Strategy so)
            {
                so.Print("Enter executeOnInitialize()");
                aStrategy.so = so;
                positions = new int[multiInstrumentTrader.nSyms];
                so.Print("Exit executeOnInitialize()");
            }
            public static void computeNewPositions()
            {
                so.Print("Enter computeNewPositions()");
                for(int i=0; i<multiInstrumentTrader.nSyms; i++) {
                    so.Print( "    " + multiInstrumentTrader.assetSymbols[i] + " return = " + multiInstrumentTrader.assetReturns[i] );
                    positions[i] = 100;
                }
                so.Print("Exit computeNewPositions()");
            }
               public static void executeOnDispose(Strategy so)
            {
            }
        }
    }
    
    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
        /// <summary>
        /// Multi instrument trading example/template
        /// </summary>
        [Description("Multi instrument trading example/template")]
        public class multiInstrumentTrader : Strategy
        {
            #region Variables
                #region userParameters
                    public static PeriodType periodType = PeriodType.Second;
                    public static int period = 10;
                    public static uint nSyms = 2; 
                    public static string[] assetSymbols = {"$EURUSD", "$GBPUSD"};
                #endregion userParameters
                     public double [] price = new double[nSyms];             // Sample price in USD    
                public static double [] assetReturns = new double[nSyms]; // current sample minus previous sample
                public static int [] positions = new int[nSyms];
                public static bool [] assetSampled = new bool[nSyms]; // 1 = this asset has been sample for this time stamp 
                public static int timeCounter;
                public enum positionSetting {Short=-1, Neutral, Long};    
            #endregion
    
            void adjustPositionTo(int i, int newPosition) {            
                Position current = Positions[i];
                Print("    Enter adustPosition() " + Time[0]);
                Print("        " +  Instruments[i].FullName + ", " + Instruments[BarsInProgress].FullName);
                Print("        " +  "Positions[" + i + "]=" + current);
                int side = 0;
                switch (current.MarketPosition)
                {
                    case MarketPosition.Short : { side = -1; break;}
                    case MarketPosition.Flat : { side = 0; break;}
                    case MarketPosition.Long : { side = 1; break;}
                }
                positionSetting currentSide = (positionSetting) side;
                int delta = newPosition - side*current.Quantity;
                Print("        currentSide=" + currentSide );
                Print("        delta=" + delta );
                positionSetting direction = positionSetting.Neutral;
                if (delta < 0) direction = positionSetting.Short;
                if (delta > 0) direction = positionSetting.Long;
                if (delta == 0) direction = positionSetting.Neutral;
                Print("        direction=" + direction );
                bool changingSides = current.Quantity < Math.Abs(delta);
                Print("        changingSides=" + changingSides );
                if( ((currentSide == positionSetting.Neutral) || (currentSide == positionSetting.Short)) 
                    && (direction == positionSetting.Short) ) 
                { 
                    Print("        A: EnterShort( " + Math.Abs(delta) + ") of " + Instruments[BarsInProgress].FullName + "  " + Instruments[i].FullName); 
                    EnterShort(Math.Abs(delta)); 
                }
                if( ((currentSide == positionSetting.Neutral) || (currentSide == positionSetting.Long))
                    && (direction == positionSetting.Long) ) 
                {  
                    Print("        B: EnterLong( " + Math.Abs(delta) + ") of " + Instruments[BarsInProgress].FullName + "  " + Instruments[i].FullName);
                    EnterLong( Math.Abs(delta)); 
                }
                 
        
                   if( (currentSide == positionSetting.Short) && (direction == positionSetting.Long) ) {
                    if ( Math.Abs(delta) > current.Quantity ) { 
                        Print("        C: ExitShort( " + current.Quantity + ") of " + Instruments[BarsInProgress].FullName + "  " + Instruments[i].FullName); 
                        ExitShort(current.Quantity );
                        Print("        D: EnterLong( " + (Math.Abs(delta) - current.Quantity)  + ") of " + Instruments[BarsInProgress].FullName + "  " + Instruments[i].FullName);
                        EnterLong(Math.Abs(delta) - current.Quantity );
                    } else {
                        Print("        E: ExitShort( " + Math.Abs(delta) + ") of " + Instruments[BarsInProgress].FullName + "  " + Instruments[i].FullName); 
                        ExitShort(Math.Abs(delta));
                    }
                }
                if( (currentSide == positionSetting.Long) && (direction == positionSetting.Short) ) {
                    if ( Math.Abs(delta) > current.Quantity ) {
                        Print("        F: ExitLong( " + current.Quantity + ") of " + Instruments[BarsInProgress].FullName + "  " + Instruments[i].FullName); 
                        ExitLong(current.Quantity ); 
                        Print("        G: EnterShort( " + (Math.Abs(delta) - current.Quantity) + ") of " + Instruments[BarsInProgress].FullName + "  " + Instruments[i].FullName);                     
                        EnterShort(Math.Abs(delta) - current.Quantity);
                    } else {
                        Print("        H: ExitLong( " + Math.Abs(delta) + ") of " + Instruments[BarsInProgress].FullName + "  " + Instruments[i].FullName);
                        ExitLong( Math.Abs(delta)); 
                    }
                }
                Print("    Exit adustPosition() ");
            }    
                    
            protected override void Initialize()
            {
                Print("Enter Initialize() " + Time[0]);
                CalculateOnBarClose = true;
                timeCounter = 0;
                for (int i=0;i<nSyms;i++) {
                    // only add the non-primary series
                    Print("Attempting to add symbol " + assetSymbols[i]);
                    Print("    primary is " +  Instruments[0].FullName);
                    if(0 != String.Compare(assetSymbols[i], Instruments[0].FullName)){
                        Add(assetSymbols[i], periodType, period);
                        Print("    added " + assetSymbols[i]);
                    }
                    else {
                        Print("    this is the primary series.");
                    }
                    assetSampled[i] = false; // mark as un sampled
                }
                
                // INSERT INITIALISATION CALLS OF YOUR STRATEGIES HERE////
                aStrategy.executeOnInitialize(this);
                Print("    Exit Initialize() ");
            }
    
            protected override void OnBarUpdate()
            {
                Print(" ");
                Print("Enter OnBarUpdate() " + Time[0]);
                Print("    " + Instruments[BarsInProgress].FullName); 
                assetSampled[BarsInProgress] = true; // mark this instrument as sampled
                double price0; double price1;
                if ( Bars.CurrentBar > 0 ) {
                    price0 = Closes[BarsInProgress][0];
                    price1 = Closes[BarsInProgress][1];
                } else {
                    price0 = 1;
                    price1 = 1;
                }
                assetReturns[BarsInProgress] = price0 - price1;
                
                // have we now sampled all assets for this time stamp?
                bool allSampled = true;
                for(int i=0;i<nSyms;i++) allSampled = allSampled && assetSampled[i];
                // If so then run forward one time step
                if(allSampled   ) {
                    aStrategy.computeNewPositions();                        // call on the strategy to update it's positions[]
                    aStrategy.positions.CopyTo(positions,0);                // copy the strategies positions[]
                    for(int i=0;i<nSyms;i++){ assetSampled[i] = false; }     // mark all assets as unsampled
                }
                            
                // call this every time, it will only alter positions when positions[] has changed (i.e. if allsampled)
                adjustPositionTo(BarsInProgress, positions[BarsInProgress]); 
                Print("Exit OnBarUpdate() ");
                timeCounter = timeCounter + 1;
            }
        
            #region Properties
            #endregion
        }
    }
    <continued...>
    Last edited by mtthwbrnd; 02-10-2010, 09:22 AM.

    #2
    <... continued>

    The output is:
    Attempting to add symbol $AUDUSD
    primary is $GBPUSD
    added $AUDUSD
    Attempting to add symbol $EURUSD
    primary is $GBPUSD
    added $EURUSD
    Attempting to add symbol $GBPUSD
    primary is $GBPUSD
    this is the primary series.
    Attempting to add symbol $NZDUSD
    primary is $GBPUSD
    added $NZDUSD
    Enter Initialize() 01/01/0001 00:00:00
    Attempting to add symbol $EURUSD
    primary is $GBPUSD
    added $EURUSD
    Attempting to add symbol $GBPUSD
    primary is $GBPUSD
    this is the primary series.
    Enter executeOnInitialize()
    Exit executeOnInitialize()
    Exit Initialize()
    Attempting to add symbol $AUDUSD
    primary is $GBPUSD
    added $AUDUSD
    Attempting to add symbol $EURUSD
    primary is $GBPUSD
    added $EURUSD
    Attempting to add symbol $GBPUSD
    primary is $GBPUSD
    this is the primary series.
    Attempting to add symbol $NZDUSD
    primary is $GBPUSD
    added $NZDUSD
    Enter Initialize() 01/01/0001 00:00:00
    Attempting to add symbol $EURUSD
    primary is $GBPUSD
    added $EURUSD
    Attempting to add symbol $GBPUSD
    primary is $GBPUSD
    this is the primary series.
    Enter executeOnInitialize()
    Exit executeOnInitialize()
    Exit Initialize()
    Enter Initialize() 01/01/0001 00:00:00
    Attempting to add symbol $EURUSD
    primary is $EURUSD
    this is the primary series.
    Attempting to add symbol $GBPUSD
    primary is $EURUSD
    added $GBPUSD
    Enter executeOnInitialize()
    Exit executeOnInitialize()
    Exit Initialize()

    Enter OnBarUpdate() 07/02/2010 21:05:20
    $EURUSD
    Enter adustPosition() 07/02/2010 21:05:20
    $EURUSD, $EURUSD
    Positions[0]=Instrument='$EURUSD' Account='Sim101' Avg price=0 Quantity=0 Market position=Flat
    currentSide=Neutral
    delta=0
    direction=Neutral
    changingSides=False
    Exit adustPosition()
    Exit OnBarUpdate()

    Enter OnBarUpdate() 07/02/2010 21:05:20
    $GBPUSD
    Enter computeNewPositions()
    $EURUSD return = 0
    $GBPUSD return = 0
    Exit computeNewPositions()
    Enter adustPosition() 07/02/2010 21:05:20
    $GBPUSD, $GBPUSD
    Positions[1]=Instrument='$GBPUSD' Account='Sim101' Avg price=0 Quantity=0 Market position=Flat
    currentSide=Neutral
    delta=100
    direction=Long
    changingSides=True
    B: EnterLong( 100) of $GBPUSD $GBPUSD
    Exit adustPosition()
    Exit OnBarUpdate()

    Enter OnBarUpdate() 07/02/2010 21:07:40
    $GBPUSD
    Enter adustPosition() 07/02/2010 21:07:40
    $GBPUSD, $GBPUSD
    Positions[1]=Instrument='$GBPUSD' Account='Sim101' Avg price=1.5639 Quantity=100 Market position=Long
    currentSide=Long
    delta=0
    direction=Neutral
    changingSides=False
    Exit adustPosition()
    Exit OnBarUpdate()

    Enter OnBarUpdate() 07/02/2010 21:11:40
    $GBPUSD
    Enter adustPosition() 07/02/2010 21:11:40
    $GBPUSD, $GBPUSD
    Positions[1]=Instrument='$GBPUSD' Account='Sim101' Avg price=1.5639 Quantity=100 Market position=Long
    currentSide=Long
    delta=0
    direction=Neutral
    changingSides=False
    Exit adustPosition()
    Exit OnBarUpdate()

    ...
    Note that Positions[] indicates that there is a position, but why is there no Order, Trade or Execution entry? I.e. how/when was the position established?


    The line "B: EnterLong( 100) of $GBPUSD $GBPUSD" indicates that orders were entered:
    Enter adustPosition() 07/02/2010 21:05:20
    $GBPUSD, $GBPUSD
    Positions[1]=Instrument='$GBPUSD' Account='Sim101' Avg price=0 Quantity=0 Market position=Flat
    currentSide=Neutral
    delta=100
    direction=Long
    changingSides=True
    B: EnterLong( 100) of $GBPUSD $GBPUSD
    Exit adustPosition()
    Exit OnBarUpdate()
    Lines like:
    Positions[1]=Instrument='$GBPUSD' Account='Sim101' Avg price=1.5639 Quantity=100 Market position=Long
    indicate that an order must have occurred. Why does it not show up in the Control Centre -> Orders tab?

    Thanks,
    Matthew.
    Last edited by mtthwbrnd; 02-10-2010, 09:23 AM.

    Comment


      #3
      mtthwbrnd,

      Depending on your settings in Tools>Options>Strategies>NinjaScript strategies, will determine when trades will be "live" trades. You are likely still looking at a virtual trade.

      If you have WaitUntilFlat, all trades your strategy does is a virtual trade till your strategy reaches a strategy position of flat. If you have ImmediatelySubmit, then any new orders submitted by the strategy should show up on the orders tab, etc.
      Josh P.NinjaTrader Customer Service

      Comment


        #4
        I have just tried it with both setting and get the same result :-(.

        Comment


          #5
          Please be sure that you do not have any filtering set for the Control Center grid.

          Suggest you take a step back and try with SampleMACrossOver first to see the expected behavior.
          Josh P.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Waxavi, 04-19-2024, 02:10 AM
          3 responses
          41 views
          0 likes
          Last Post gaz0001
          by gaz0001
           
          Started by Max238, Today, 01:28 AM
          2 responses
          26 views
          0 likes
          Last Post NinjaTrader_ChristopherJ  
          Started by Shansen, 08-30-2019, 10:18 PM
          25 responses
          949 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by JonesJoker, 04-22-2024, 12:23 PM
          8 responses
          42 views
          0 likes
          Last Post JonesJoker  
          Started by timko, Today, 06:45 AM
          0 responses
          7 views
          0 likes
          Last Post timko
          by timko
           
          Working...
          X