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

Error Message: Failed to cal method..

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

    Error Message: Failed to cal method..

    Guys

    could anybody indicate why i get the following message (see attached) in my script:

    1.
    "Failed to Call ...."
    I suspect it might have to do with a missing DataSeries I should report in the Initialize() method, but I am unable to figure it out;

    2.
    "An entry() method..Please search on the term Internal Order Handling.."
    I suspect I am doing something wrong when placing my stop-loss, maybe because using ExitLongStop rather than Set() but this is what is advised in the tutorial, please could you help me solve this?

    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.Strategy;
    #endregion
     
    namespace NinjaTrader.Strategy
    {
    [Description("")]
    public class PPPP : Strategy
    {
        #region Variables
    	
    	private IOrder entryOrderLong = null;
    	private IOrder stopOrderLong = null;
    	private IOrder entryOrderShort = null;
    	private IOrder stopOrderShort = null;
    	private double  stopLoss = 0;
    	private double  AccBalNew = 0;
    	private double  AccountSize = 100000;
    	private double  Riskf = 1;
    	private double	Psize = 0;
    	private double priorTradesCumProfit = 0;
    	private double slippage = 3;
    
    	
        #endregion
    
    	protected override void Initialize()
    	{
    		CalculateOnBarClose = true;
    		ExitOnClose = false;
    	}
    
    	protected override void OnBarUpdate()
    	{ 
    		
    			#region Long Stop-Loss Adj
    		
    		//ADJUST STOP LOSS
    		if (Position.MarketPosition == MarketPosition.Long && stopOrderLong != null)
    			{	
    				if(Close[0] < Close[1] && Low[0] < Low[1])
    				{
    					stopOrderLong = ExitLongStop(0, true, stopOrderLong.Quantity, Low[0]-slippage*TickSize, "New Stop-Loss", "Long");
    				}
    			}		
    	
    		#endregion
    			
    		#region Short Stop-Loss Adj
    		
    		//ADJUST STOP LOSS
    		if (Position.MarketPosition == MarketPosition.Short && stopOrderShort != null)
    			{	
    				if(Close[0] > Close[1] && High[0] > High[1])
    				{
    					stopOrderShort = ExitShortStop(0, true, stopOrderShort.Quantity, High[0]+slippage*TickSize, "New Stop-Loss", "Short");
    				}
    			}
    
    			
    		#endregion			
    		
    		#region Long Entry
    			
    		
    		if (Position.MarketPosition == MarketPosition.Flat && entryOrderLong ==null)
    			{
    				if(Close[0] >MAX(High,5)[1])
    					{
    						stopLoss = High[0] - Low[0] + slippage * 2 * TickSize;
    						PositionSize();
    						entryOrderLong = EnterLongStop(0, false, (int)Psize, High[0]+slippage*TickSize,"Long");	
    					}
    			}
    		
    		#endregion	
    			
    		#region Short Entry
    		
    		
    		if(Position.MarketPosition == MarketPosition.Flat && entryOrderShort ==null)
    			{
    				if(Close[0] < MIN(Low,5)[1])
    				{
    					stopLoss = High[0] - Low[0] + slippage * 2 * TickSize;
    					PositionSize();
    					entryOrderShort = EnterShortStop(0, false, (int)Psize, Low[0]-slippage*TickSize,"Short");
    				}
    			}
    		
    		#endregion
    	}	
    	
    	protected override void OnOrderUpdate(IOrder order)
    	{
    		#region Reset Long Entry
    		
    		if (entryOrderLong != null && entryOrderLong == order)
    		{
    			if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
    			{
    				entryOrderLong = null;
    			}
    		}
    		
    		#endregion
    
    		#region Reset Short Entry
    		
    		if (entryOrderShort != null && entryOrderShort == order)
    		{
    			if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
    			{
    				entryOrderShort = null;
    			}
    		}
    		
    		#endregion
    	}
    	        
    	protected override void OnExecution(IExecution execution)
    	{		
    		#region Long Stop-Loss & Partial Fill Reset
    		
    		if (entryOrderLong != null && entryOrderLong == execution.Order)
    		{
    			if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
    			{
    				stopOrderLong = ExitLongStop(0, true, execution.Order.Filled, Low[0]-slippage*TickSize, "Stop-Loss", "Long");
    			}
    				
    			if (execution.Order.OrderState != OrderState.PartFilled)
    			{
    				entryOrderLong 	= null;
    			}
    		}
    		
    		#endregion
    						
    		#region Reset Long Stop-Loss & Target Profit
    		
    		if ((stopOrderLong != null && stopOrderLong == execution.Order))
    		{
    			if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled)
    			{
    				stopOrderLong = null;
    			}
    		}
    		
    		#endregion
    		
    		#region Short Stop-Loss & Partial Fill Reset
    		
    		if (entryOrderShort != null && entryOrderShort == execution.Order)
    		{
    			if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
    			{
    				stopOrderShort = ExitShortStop(0, true, execution.Order.Filled, High[0]+slippage*TickSize, "Stop-Loss", "Short");
    			}
    				
    			if (execution.Order.OrderState != OrderState.PartFilled)
    			{
    				entryOrderShort = null;
    			}
    		}
    		
    		#endregion
    						
    		#region Reset Short Stop-Loss & Target Profit
    		
    		if ((stopOrderShort != null && stopOrderShort == execution.Order) )
    		{
    			if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled)
    			{
    				stopOrderShort = null;
    			}
    		}	
    		
    		#endregion
    	}
    
    		#region PositionSizeFunction
    			//POSITION SIZING ONLY FOR DIRECT RATES	
    			void PositionSize()
    
    				{
    					priorTradesCumProfit = (double)Performance.AllTrades.TradesPerformance.Currency.CumProfit;
    					AccBalNew = AccountSize + priorTradesCumProfit;
    					Psize = Math.Round(AccBalNew * Riskf / 100 / stopLoss); 
    					//For fixed amount stopLoss to be defined as variable e.i. 50 pips = 50, then use formula: Psize = Math.Round(AccBalNew * Riskf / 100 / (stopLoss) / TickSize);
    					
    					Print("");
    					Print("New Account Balance: "+AccBalNew);
    					Print("Time: "+Time[0]);
    					Print("CumProfit: "+priorTradesCumProfit);
    					Print("Position Size: "+Psize);
    				}
    				
    		#endregion
    							
    		#region Properties
    							
    		[Description("Account Balance (US$)")]
    		[Category("Parameters")]
    		[Gui.Design.DisplayNameAttribute("\t\t\t\tAccount Balance (USD)")]
    		public double AccBal
    				{
    					get { return AccountSize; }
    					set { AccountSize = Math.Max(0, value); }
    				}              
    		
    		[Description("Risk Factor (%)")]
    		[Category("Parameters")]
    		[Gui.Design.DisplayNameAttribute("\t\t\tRisk Factor (%)")]
    		public double RiskF
    				{
    					get { return Riskf; }
    					set { Riskf = Math.Max(0, value); }
    				}              
    
    		[Description("Slippage(Pips)")]
    		[Category("Parameters")]
    		[Gui.Design.DisplayNameAttribute("\t\t\t\tSlippage(Pips)")]
    		public double Slippage
    				{
    					get { return slippage; }
    					set { slippage = Math.Max(0, value); }
    				}  				
    		#endregion
    	}
    }
    Attached Files
    Last edited by sburtt; 07-25-2013, 05:18 PM.

    #2
    sburtt, the first issue is not related to the script you posted. It's for the AAATest, you want to refer to this script's Initialize().

    Issue with the ignored orders is due to the Internal order handling rules that you are hitting, having a stop loss order working with liveUntilCancelled and then attempting to issue a new order that would take you in the opposite direction, this will not work unless you cancelled the working order first.

    The full managed mode order rules are explained here in the bottom section -

    BertrandNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Bertrand View Post
      Issue with the ignored orders is due to the Internal order handling rules that you are hitting, having a stop loss order working with liveUntilCancelled and then attempting to issue a new order that would take you in the opposite direction, this will not work unless you cancelled the working order first.

      The full managed mode order rules are explained here in the bottom section -

      http://www.ninjatrader.com/support/h...ghtsub=managed
      Bertrand, this strategy only exits a trade via stoploss and only initiates a trade if market position is flat.

      correct me if wrong, the problem (but I am not sure) is that I am trying to adjust the original stop-loss to a new level without previously cancelling the original stoploss, could that be the case? If yes, how could I fix it?

      Comment


        #4
        No, the updating of the order would not be the issue - if you used the same signal name (you differentiate between stop loss and new stop loss - would suggest removing that and just update the order).

        You see this as you would have a resting stop lying around with your script (as it's submitted with liveUntilCancelled set) - this will trigger the message then.

        Would suggest further debugging with the TraceOrders option to find which exact event sequence is causing it, so you can issue the needed CancelOrder() call in your script.

        BertrandNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Bertrand View Post
          No, the updating of the order would not be the issue - if you used the same signal name (you differentiate between stop loss and new stop loss - would suggest removing that and just update the order).

          You see this as you would have a resting stop lying around with your script (as it's submitted with liveUntilCancelled set) - this will trigger the message then.

          Would suggest further debugging with the TraceOrders option to find which exact event sequence is causing it, so you can issue the needed CancelOrder() call in your script.

          http://www.ninjatrader.com/support/f...ead.php?t=3627
          ok I will try this asap and revert if needed, thanks

          Comment


            #6
            Originally posted by NinjaTrader_Bertrand View Post
            No, the updating of the order would not be the issue - if you used the same signal name (you differentiate between stop loss and new stop loss - would suggest removing that and just update the order).

            You see this as you would have a resting stop lying around with your script (as it's submitted with liveUntilCancelled set) - this will trigger the message then.

            Would suggest further debugging with the TraceOrders option to find which exact event sequence is causing it, so you can issue the needed CancelOrder() call in your script.

            http://www.ninjatrader.com/support/f...ead.php?t=3627
            Bertrand, attached is the strategy and the output.txt, as you can see the error persists, I tried looking into it, but I am no expert and don't understand what could be creating this issue, I would appreciate if you could look into this and let me know what you think. I owe you a beer after this..
            Attached Files

            Comment


              #7
              I tried running the script on my end and didn't see any problematic errors.

              Only ignored order I see is
              7/26/2013 10:00:00 AM Ignore order amendment: Action=BuyToCover OrderType=Stop Quantity=399159 LimitPrice=0 StopPrice=1.5371 SignalName=New Stop-Loss' FromEntrySignal='Short' Reason='Order already has this stop price/limit price/quantity'

              This was triggered because the order change didn't change anything.

              Could you give me the timeframe you ran this on?
              LanceNinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_Lance View Post
                I tried running the script on my end and didn't see any problematic errors.

                Only ignored order I see is
                7/26/2013 10:00:00 AM Ignore order amendment: Action=BuyToCover OrderType=Stop Quantity=399159 LimitPrice=0 StopPrice=1.5371 SignalName=New Stop-Loss' FromEntrySignal='Short' Reason='Order already has this stop price/limit price/quantity'

                This was triggered because the order change didn't change anything.

                Could you give me the timeframe you ran this on?
                the output.txt file below is a strategy running on a daily timeframe, bu the issue happens on any timeframe, there are no problematic errors, but every now and then I get something like this (see below) but running through the script I can't figure out why, any idea?

                Code:
                New Account Balance: 104091.8968
                Time: 28/06/2012 22:00:00
                CumProfit: 4091.89680000002
                Position Size: 71788
                28/06/2012 22:00:00 Entered internal PlaceOrder() method at 28/06/2012 22:00:00: BarsInProgress=0 Action=SellShort OrderType=Stop Quantity=71,788 LimitPrice=0 StopPrice=1.5481 SignalName='Short' FromEntrySignal=''
                
                New Account Balance: 104091.8968
                Time: 29/06/2012 22:00:00
                CumProfit: 4091.89680000002
                Position Size: 48869
                29/06/2012 22:00:00 Entered internal PlaceOrder() method at 29/06/2012 22:00:00: BarsInProgress=0 Action=Buy OrderType=Stop Quantity=48,869 LimitPrice=0 StopPrice=1.5716 SignalName='Long' FromEntrySignal=''
                [B]29/06/2012 22:00:00 Ignored PlaceOrder() method at 29/06/2012 22:00:00: Action=Buy OrderType=Stop Quantity=48,869 LimitPrice=0 StopPrice=1.5716 SignalName=Long' FromEntrySignal='' Reason='An Enter() method to submit an entry order has been ignored. Please search on the term 'Internal Order Handling Rules' in the Help Guide for detailed explanation.'[/B]
                [B]**NT** An Enter() method to submit an entry order at '29/06/2012 22:00:00' has been ignored. Please search on the term 'Internal Order Handling Rules' in the Help Guide for detailed explanation.[/B]
                29/06/2012 22:00:00 Cancelled expired order: BarsInProgress=0: Order='NT-00025/Backtest' Name='Short' State=Working Instrument='$GBPUSD' Action=SellShort Limit price=0 Stop price=1.5481 Quantity=71,788 Strategy='PPPP' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='12f3ac74856d49dc8055fd97d63756f1' Gtd='01/12/2099 00:00:00'
                
                New Account Balance: 104091.8968
                Time: 06/07/2012 22:00:00
                CumProfit: 4091.89680000002
                Position Size: 108429
                06/07/2012 22:00:00 Entered internal PlaceOrder() method at 06/07/2012 22:00:00: BarsInProgress=0 Action=SellShort OrderType=Stop Quantity=108,429 LimitPrice=0 StopPrice=1.5457 SignalName='Short' FromEntrySignal=''
                09/07/2012 22:00:00 Cancelled expired order: BarsInProgress=0: Order='NT-00026/Backtest' Name='Short' State=Working Instrument='$GBPUSD' Action=SellShort Limit price=0 Stop price=1.5457 Quantity=108,429 Strategy='PPPP' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='8324e797b0124fe3891ccb85aced0d90' Gtd='01/12/2099 00:00:00'

                Comment


                  #9
                  Hello sburtt,

                  Thank you for your response.

                  In your response you detail the error that occurred, you have also provided some information into the cause:
                  28/06/2012 22:00:00 Entered internal PlaceOrder() method at 28/06/2012 22:00:00: BarsInProgress=0 Action=SellShort OrderType=Stop Quantity=71,788 LimitPrice=0 StopPrice=1.5481 SignalName='Short' FromEntrySignal=''

                  29/06/2012 22:00:00
                  Entered internal PlaceOrder() method at 29/06/2012 22:00:00: BarsInProgress=0 Action=Buy OrderType=Stop Quantity=48,869 LimitPrice=0 StopPrice=1.5716 SignalName='Long' FromEntrySignal=''
                  29/06/2012 22:00:00 Ignored PlaceOrder() method at 29/06/2012 22:00:00: Action=Buy OrderType=Stop Quantity=48,869 LimitPrice=0 StopPrice=1.5716 SignalName=Long' FromEntrySignal='' Reason='An Enter() method to submit an entry order has been ignored.
                  Two orders to enter are submitted at the same time, the first order is accepted while the second order is rejected based on the following rule from the Internal Order Handling Rules:
                  Methods that generate orders to enter a position will be ignored if:
                  • The strategy position is flat and an order submitted by an enter method (EnterLongLimit() for example) is active and the order is used to open a position in the opposite direction
                  Based on this information you will need to focus on conditions and methods that may result in both entry orders being submitted at the same time.

                  Please let me know if I may be of further assistance.

                  Comment


                    #10
                    Originally posted by NinjaTrader_PatrickH View Post
                    Hello sburtt,

                    Thank you for your response.

                    In your response you detail the error that occurred, you have also provided some information into the cause:

                    Two orders to enter are submitted at the same time, the first order is accepted while the second order is rejected based on the following rule from the Internal Order Handling Rules:

                    Based on this information you will need to focus on conditions and methods that may result in both entry orders being submitted at the same time.

                    Please let me know if I may be of further assistance.
                    Patrick, if you have time can you have a look at the code i posted earlier, that is exactly it, but I am unable to figure out what is causing the trouble. I appreciate you time

                    Comment


                      #11
                      Hello sburtt,

                      Thank you for your response.

                      I would start by giving each order it's own signal name, this will help differentiate from exit and enter methods that are being called. This will give you a better idea in the Output from TraceOrders exactly which two orders are conflicting here.

                      Please let me know if you have any questions.

                      Comment


                        #12
                        Originally posted by NinjaTrader_PatrickH View Post
                        Hello sburtt,

                        Thank you for your response.

                        I would start by giving each order it's own signal name, this will help differentiate from exit and enter methods that are being called. This will give you a better idea in the Output from TraceOrders exactly which two orders are conflicting here.

                        Please let me know if you have any questions.
                        Hi Patrick, thanks for your advise, but have you had the chance to check the code? Correct me if wrong, but I think I've done this already. My LongEntry = "Long", my ShortEntry = "Short", my initial Stop = "Stop Loss" and my trailing stop = "New Stop-Loss". Please advise if you meant something different. Thanks

                        Comment


                          #13
                          Hello sburtt,

                          Thank you for your response.

                          I have reviewed your code and you are correct the signal names are different.
                          What Time Frame (From and To Dates) as well as what period and interval (Example: 1 Minute) have you ran the backtest on the $GBPUSD for?

                          I look forward to your response.

                          Comment


                            #14
                            Originally posted by NinjaTrader_PatrickH View Post
                            Hello sburtt,

                            Thank you for your response.

                            I have reviewed your code and you are correct the signal names are different.
                            What Time Frame (From and To Dates) as well as what period and interval (Example: 1 Minute) have you ran the backtest on the $GBPUSD for?

                            I look forward to your response.
                            HI Patrick, appreciate your help. I've run the strategy again on a 30 min time frame for 1 month of data in GBPUSD, data feed is from Interactive Brokers, attached are all the information you require. as you can notice on the 27/02/13 an Entry was ignore, I need to figure out why. when I start to you more complex code this occurs more frequently. this is a problem as i don't know how reliable the statistics are at this point. please i would appreciate you taking some time to investigate on the matter, if you require more info please ask. the strategy is in a previous post, it would be good if you can run it on different data to see if you have the same issue on your end. thanks

                            ***I've been doing some test and I noticed that if I run the strategy from lets say 01/01/13 to 01/07/13 and then I run the strategy from 02/01/13 to 01/07/13, or basically if i change the starting date I get the error on a different day, this is very strange and maybe it could be a bug, what you think?
                            Attached Files
                            Last edited by sburtt; 07-29-2013, 01:47 PM.

                            Comment


                              #15
                              Hello sburtt,

                              Thank you for your response.

                              I have tested further with your additional information and I see the same item.

                              What is occurring is (for my test) the entryOrderLong is submitted at 8:30 AM on February 27th, the next bar occurs and the entry condition for the entryOrderShort is true so this order is attempted, however the entryOrderLong is not cancelled yet and causes the conflict.

                              To resolves this you would need to place a check that both IOrder objects are null before entry:
                              Code:
                              		if (Position.MarketPosition == MarketPosition.Flat && [B]entryOrderLong ==null && entryOrderShort == null)[/B]
                              			{
                              				if(Close[0] >MAX(High,5)[1])
                              					{
                              						stopLoss = High[0] - Low[0] + slippage * 2 * TickSize;
                              						PositionSize();
                              						entryOrderLong = EnterLongStop(0, false, (int)Psize, High[0]+slippage*TickSize,"Long");	
                              					}
                              			}
                              		
                              		#endregion	
                              			
                              		#region Short Entry
                              		
                              		
                              		if(Position.MarketPosition == MarketPosition.Flat && [B]entryOrderLong ==null && entryOrderShort == null)[/B]
                              			{
                              				if(Close[0] < MIN(Low,5)[1])
                              				{
                              					stopLoss = High[0] - Low[0] + slippage * 2 * TickSize;
                              					PositionSize();
                              					entryOrderShort = EnterShortStop(0, false, (int)Psize, Low[0]-slippage*TickSize,"Short");
                              				}
                              			}
                              		
                              		#endregion
                              Please let me know if I may be of further assistance.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Aviram Y, Today, 05:29 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post Aviram Y  
                              Started by quantismo, 04-17-2024, 05:13 PM
                              3 responses
                              25 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by ScottWalsh, 04-16-2024, 04:29 PM
                              7 responses
                              34 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by cls71, Today, 04:45 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post cls71
                              by cls71
                               
                              Started by mjairg, 07-20-2023, 11:57 PM
                              3 responses
                              217 views
                              1 like
                              Last Post PaulMohn  
                              Working...
                              X