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

Strategy generating issues

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

    Strategy generating issues

    Hi,

    I built a simple SMA Swing Strategy with NT8 Strategy Builder.

    Code:
    {
    	public class SwingSMA : Strategy
    	{
    		private SMA SMA1;
    		private SMA SMA2;
    
    		protected override void OnStateChange()
    		{
    			if (State == State.SetDefaults)
    			{
    				Description									= @"Swing-Strategie auf Basis des SMA";
    				Name										= "SwingSMA";
    				Calculate									= Calculate.OnBarClose;
    				EntriesPerDirection							= 1;
    				EntryHandling								= EntryHandling.AllEntries;
    				IsExitOnSessionCloseStrategy				= true;
    				ExitOnSessionCloseSeconds					= 30;
    				IsFillLimitOnTouch							= false;
    				MaximumBarsLookBack							= MaximumBarsLookBack.TwoHundredFiftySix;
    				OrderFillResolution							= OrderFillResolution.High;
    				OrderFillResolutionType						= BarsPeriodType.Minute;
    				OrderFillResolutionValue					= 1;
    				Slippage									= 0;
    				StartBehavior								= StartBehavior.WaitUntilFlat;
    				TimeInForce									= TimeInForce.Gtc;
    				TraceOrders									= false;
    				RealtimeErrorHandling						= RealtimeErrorHandling.StopCancelClose;
    				StopTargetHandling							= StopTargetHandling.PerEntryExecution;
    				BarsRequiredToTrade							= 20;
    				// Disable this property for performance gains in Strategy Analyzer optimizations
    				// See the Help Guide for additional information
    				IsInstantiatedOnEachOptimizationIteration	= true;
    				Stragiebeginn						= DateTime.Parse("08:00");
    				Strategieende						= DateTime.Parse("22:00");
    				Periode_schnell					= 10;
    				Periode_langsam					= 50;
    				SL_Ticks					= 1;
    			}
    			else if (State == State.Configure)
    			{
    				SetTrailStop("", CalculationMode.Ticks, SL_Ticks, false);
    			}
    			else if (State == State.DataLoaded)
    			{				
    				SMA1				= SMA(Close, Convert.ToInt32(Periode_schnell));
    				SMA1.Plots[0].Brush = Brushes.MediumSeaGreen;
    				AddChartIndicator(SMA1);
    				SMA2				= SMA(Close, Convert.ToInt32(Periode_langsam));
    				SMA2.Plots[0].Brush = Brushes.Maroon;
    				AddChartIndicator(SMA2);
    			}
    		}
    
    		protected override void OnBarUpdate()
    		{
    			if (CurrentBars[0] < 1)
    			return;
    
    			 // set 1
    			if ((CrossAbove(SMA1, SMA2, 1))
    				 && (Times[0][0].TimeOfDay >= Stragiebeginn.TimeOfDay)
    				 && (Times[0][0].TimeOfDay < Strategieende.TimeOfDay))
    			{
    				EnterLong(Convert.ToInt32(DefaultQuantity), "");
    			}
    			
    			 // set 2
    			if ((CrossBelow(SMA1, SMA2, 1))
    				 && (Times[0][0].TimeOfDay >= Stragiebeginn.TimeOfDay)
    				 && (Times[0][0].TimeOfDay < Strategieende.TimeOfDay))
    			{
    				EnterShort(Convert.ToInt32(DefaultQuantity), "");
    			}
    			
    			 // set 3
    			if (Times[0][0].TimeOfDay > Strategieende.TimeOfDay)
    			{
    				ExitLong(Convert.ToInt32(DefaultQuantity), "", "");
    				ExitShort(Convert.ToInt32(DefaultQuantity), "", "");
    			}
    			
    		}
    I traded EUREX (FDAX) this morning.

    My strategy sended an order at 02:50 CST. At 02:51 CST the order was closed with the error message (I am trying to translate) „Change of order not possible. Strategy sended cancellation requests, trying to close the position and closed itself.“

    Do you think it's set 3?


    Kind regards

    #2
    Hello,

    Thank you for the post.

    I tried the sample provided and I did get an error while running the script:

    submitted an order that generated the following error 'Unable to change order'. The strategy has sent cancel requests, attempted to close the position and terminated itself.

    Stop price can't be changed below the market. affected Order: BuyToCover 1 StopMarket @ 13450.5

    Can you tell me, is this the same error, mainly the second part about the StopPrice cannot be changed below the market?

    If so, I believe this is due to the trailing stop and using a 1 tick offset in that specific case. Can you confirm this is the same error or different? if you could copy/paste the error from the log tab that would be helpful.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi,

      many thanks for your message.

      'Unable to change order'. The strategy has sent cancel requests, attempted to close the position and terminated itself.
      This part is identical. (In German language). But the second part is not there, therefore I can not confirm this part.

      Stop price can't be changed below the market. affected Order: BuyToCover 1 StopMarket @ 13450.5
      What can I do to exclude this definitely, if this would be the reason?


      The more I research, the more I think, the trail stop is the main part of the problem. I can see from the log file: „Stop Markt’ Time in force = GTC. I once heard that EUREX (FDAX) is just accepting Time in force = DAY. I changed Time in force to "DAY" in my strategy.

      Comment


        #4
        Hello,

        Thank you for the reply.

        The best way to address what is specifically happening will be to review the log tab after this happens to look for the reason. The first part of the message is only letting you know the script is being disabled but that is not really the important message. The second part of that error will let you know the reason, being that the logic is very simple it is likely the same error is happening.

        You could run the script using Replay if you wanted to confirm the error message being sent. Otherwise, you could try increasing the trailing stop distance, in the case the market moves fast and the order is changed to an invalid price like in my test you could receive the message I had.


        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by TraderBCL, Today, 04:38 AM
        3 responses
        23 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by WeyldFalcon, 08-07-2020, 06:13 AM
        11 responses
        1,423 views
        0 likes
        Last Post jculp
        by jculp
         
        Started by RubenCazorla, Today, 09:07 AM
        0 responses
        4 views
        0 likes
        Last Post RubenCazorla  
        Started by BarzTrading, Today, 07:25 AM
        2 responses
        29 views
        1 like
        Last Post BarzTrading  
        Started by devatechnologies, 04-14-2024, 02:58 PM
        3 responses
        21 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Working...
        X