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

Orders Sent then Immediately Cancelled on Multi TF

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

    Orders Sent then Immediately Cancelled on Multi TF

    Hi, Having progressed my strategy from a single timeframe to a multi time I am having a problem when placing orders.

    The Orders are sent to the order manager and then immediately cancelled. I can only assume it has something to do with the Multi TF code I have added.

    Although I have referred to it as "Multi Timeframe" I am actually using range bars of two periods (20 and 50 Range) Tick on Forex.

    Code is Below:

    Code:
     protected override void Initialize()
            {
                
                SetProfitTarget("DonLa", CalculationMode.Ticks, WT1L);
                SetProfitTarget("DonSa", CalculationMode.Ticks, WT1S);
                ExitOnClose = false;
                CalculateOnBarClose = false;
                ClearOutputWindow();
                Add(PeriodType.Range,50); //Added Second Time-Frame to Collect Data for Trend - Array Index is 1
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                if (FirstTickOfBar)
                {
                    trend = SMA(BarsArray[1],10)[0]; // Calculate the Trend
                    Print(Instrument.FullName+":"+Position.MarketPosition+":"+Time);
                    Print("Trend: "+trend);    
                        //Print(Bars.BarsSinceSession+":"+Time);
                        // MA Entry Long
                        if (
                            Close[currentBar] > SMA(Close,14)[currentBar]
                            && Close[currentBar] > Open[currentBar]
                            && Close[previousBar] <= SMA(Close,14)[previousBar]
                            && Close[currentBar] >= trend
                            )
                        {                
                            //Print ("MarketPosFromLong:"+Position.MarketPosition+":"+Position.Quantity);
                            if (Position.MarketPosition == MarketPosition.Flat) 
                            {
                                EnterLongLimit(wSingleOrderQuantity, Close[0]+(2*TickSize), "MALa");
                                Print ("EnterLong: "+Instrument.FullName+":"+Position.MarketPosition+":"+Position.AvgPrice+":"+Bars.BarsSinceSession+":"+Time);
                            }
                            //Always put a stop loss in!
                            SetStopLoss(CalculationMode.Ticks, wStopL);
                        }
                        // MA Entry Short
                        if (
                            Close[currentBar] < SMA(Close,14)[currentBar]
                            && Close[currentBar] < Open[currentBar]
                            && Close[previousBar] >= SMA(Close,14)[previousBar]
                            && Close[currentBar] <= trend
                            )
                        {                            
                            //Print ("MarketPosFromShort:"+Position.MarketPosition+":"+Position.Quantity);
                            if (Position.MarketPosition == MarketPosition.Flat) 
                            {
                                EnterShortLimit(wSingleOrderQuantity, Close[0]-(2*TickSize), "DonSa");
                                //EnterShortLimit(wSingleOrderQuantity, Close[0]-(2*TickSize), "DonSb");
                                Print ("EnterShort: "+Instrument.FullName+":"+Position.MarketPosition+":"+Position.AvgPrice+":"+Bars.BarsSinceSession+":"+Time);
                            }
                            //Always put a stop loss in!
                            SetStopLoss(CalculationMode.Ticks, wStopS);
                        }
                }
            }

    #2
    hodgsos, welcome to the forums - please set those to liveUntiCancelled or resubmit them until filled, otherwise they get cancelled per default on the next OnBarUpdate() call - http://www.ninjatrader-support.com/H...verview36.html
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thank you for your quick response, I will give this a try.

      Regards

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by tkaboris, Today, 08:01 AM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by Lumbeezl, 01-11-2022, 06:50 PM
      31 responses
      817 views
      1 like
      Last Post NinjaTrader_Adrian  
      Started by xiinteractive, 04-09-2024, 08:08 AM
      5 responses
      15 views
      0 likes
      Last Post NinjaTrader_Erick  
      Started by swestendorf, Today, 11:14 AM
      2 responses
      6 views
      0 likes
      Last Post NinjaTrader_Kimberly  
      Started by Mupulen, Today, 11:26 AM
      0 responses
      7 views
      0 likes
      Last Post Mupulen
      by Mupulen
       
      Working...
      X