NexusFi: Find Your Edge


Home Menu

 





ninjatrader platform order execution in automatic trading


Discussion in NinjaTrader

Updated
    1. trending_up 2,093 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 5 posts
    2. attach_file 0 attachments




 
Search this Thread

ninjatrader platform order execution in automatic trading

  #1 (permalink)
 pepbosch 
Madrid - Spain
 
Experience: Intermediate
Platform: NinjaTrader
Broker: CONTINUUM
Trading: ES, Currency Futures, Forex, oil, gold, EUR/USD, Stocks
Posts: 315 since Jun 2014
Thanks Given: 412
Thanks Received: 132

Hi , I am trying to understand how ninjatrader platform executes the order in automatic trading. Are the orders executed when the signal appears or at the end of the bar?
example: automatic trading in 60 minute chart , I get a buy signal at the middle of the bar, When will the buy order be executed? at next available offer or 30 minutes later when the close of the 60 minute bar?
thank you

Follow me on Twitter Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Footprint for strategy Builder
NinjaTrader
What broker to use for trading palladium futures
Commodities
Quantum physics & Trading dynamics
The Elite Circle
MC PL editor upgrade
MultiCharts
ZombieSqueeze
Platforms and Indicators
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Funded Trader platforms
54 thanks
Just another trading journal: PA, Wyckoff & Trends
19 thanks
Self sabotage reframed
15 thanks
Trading with Intuition
14 thanks
GFIs1 1 DAX trade per day journal
9 thanks
  #3 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863


If you generate the order when the signal is there (in your case middle of the bar) then the order will be executed at that moment, it means that your piece of code in your strategy should not only be called upon bar close, that is an option you can choose...

The answer is, yes it's possible

The execution of your order will depend on the type of order (market order, or limit order) and what is available at the bid/ask at that moment

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #4 (permalink)
 pepbosch 
Madrid - Spain
 
Experience: Intermediate
Platform: NinjaTrader
Broker: CONTINUUM
Trading: ES, Currency Futures, Forex, oil, gold, EUR/USD, Stocks
Posts: 315 since Jun 2014
Thanks Given: 412
Thanks Received: 132


rleplae View Post
If you generate the order when the signal is there (in your case middle of the bar) then the order will be executed at that moment, it means that your piece of code in your strategy should not only be called upon bar close, that is an option you can choose...

The answer is, yes it's possible

The execution of your order will depend on the type of order (market order, or limit order) and what is available at the bid/ask at that moment

Fantastic, thank you very much.
Pep

Follow me on Twitter Started this thread Reply With Quote
  #5 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863


pepbosch View Post
Hi , I am trying to understand how ninjatrader platform executes the order in automatic trading. Are the orders executed when the signal appears or at the end of the bar?
example: automatic trading in 60 minute chart , I get a buy signal at the middle of the bar, When will the buy order be executed? at next available offer or 30 minutes later when the close of the 60 minute bar?
thank you

While the bar is building your strategy can be called anytime there is an update in price. This allows you to fire an order 'inside the bar' that is building.

Like : (be carefull as this needs to be efficient and can generate a lot of calls)

 
Code
	protected override void OnMarketData (MarketDataEventArgs e)
		{
			System.TimeSpan NewDuration;			
			
			// ***************************************************
			
			if (e.MarketDataType == MarketDataType.Last)
			{
			if (mylong ==1)
			{
				// e.Time 
				myLastBarTime = e.Time;
				NewDuration = myLastBarTime - myEntryTime;

				// mfe ticks berekenen
				// new MFE ?
			
				if (e.Price > mylongentry)
				{
				if (Math.Min(e.Price,mylongtarget) > mfeval)
					mfeval = Math.Min(e.Price,mylongtarget);
				}
				if (mfeval > mylongentry)
					 mfeticks = Convert.ToInt32 ((mfeval-mylongentry)*myMULTIPLYER);
				
				// 5 minutes passed and never been positive
				// kick out
    			if (NewDuration.Minutes >= 5 && mfeticks == 0)
				{
	
				if (mfeticks == 0)
			    {			
					DebugPrint ("Kill : 5 minutes without any positive ticks *long*");
					ExitLong("Exit trade LU","ATM LU");
					
				}
				} // > 5 minutes and mfe 0
				
				// trade -5 and never been positive
				// kick-out
				if ( (e.Price <= (mylongentry - (7.0 * TickSize))) && mfeticks ==0 )
				{
					DebugPrint ("Kill : -7 ticks without any positive ticks *short*");
					ExitLong("Exit trade LU","ATM LU");

				}
				
				 
			} // we are in long
			
			if ( myshort ==1)
			{
				myLastBarTime = e.Time;
				NewDuration = myLastBarTime - myEntryTime;

     			// mfe ticks berekenen
				// new MFE ?
				if (e.Price < myshortentry)
				{
				 if (Math.Max(e.Price,myshorttarget) < mfeval)
					mfeval = Math.Max(e.Price,myshorttarget);
				}
				if (mfeval < myshortentry)
					 mfeticks = Convert.ToInt32 ((myshortentry - mfeval)*myMULTIPLYER);

    			if (NewDuration.Minutes >= 5 && mfeticks == 0)
				{
			
				if (mfeticks == 0)
			    {			
					DebugPrint ("Kill : 5 minutes without any positive ticks *short*");
			
									// new MAE ?
				    if (e.Price > myshortentry)
			 	    {
					 if (Math.Min(e.Price,myshortstop) > maeval)
						maeval = Math.Min(e.Price,myshortstop);
				    }

					ExitShort("Exit trade LD","ATM LD");

					
				}
				}

				// trade -5 and never been positive
				// kick-out
				if ( e.Price >= (myshortentry + (7.0 * TickSize)) && mfeticks ==0 )
				{
					DebugPrint ("Kill : -7 ticks without any positive ticks *short*");
					
  					if (Math.Min(e.Price,myshortstop) > maeval)
						maeval = Math.Min(e.Price,myshortstop);

					ExitShort("Exit trade LD","ATM LD");
				}
		
				
			} // we are in short
			} // new quote
			
		}
alternatively you can set

CalculateOnBarClose = false;
in your initialize section, then the onBarUpdate will be called on every tick


and then the

 
Code
      /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
			
			if (BarsInProgress == 1)
			{
				DebugPrint ("5 minute bar update...");
				return;
			}

	
			// Make sure this strategy does not execute against historical data
			if (Historical)
				return;
		
	
			BarCount++;
			
			
// ............
          // do your logic here -> and set myTradeCondition =1;

			if (myTradeCondition == 1)
			{
   			    DebugPrint("We go short");
			     if (myEntryOrder == null)
				 {
					//myReentry++;

				    // Set order parameters
					DebugPrint ("myEntryOrder == null");
				    SetStopLoss (CalculationMode.Ticks,mySTOPSHORT);
				    SetProfitTarget(CalculationMode.Ticks,myTARGETSHORT);
					myEntryOrder = 	EnterShort("ATM LD");
					barNumberOfOrder = CurrentBar;
					myshortorder = 1;			
				    StoreDataSnapShot ();
				    TradePuntC = myABCD_C;		
			 	 } 
								
				}
			
			
        } // on barupdate

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #6 (permalink)
 pepbosch 
Madrid - Spain
 
Experience: Intermediate
Platform: NinjaTrader
Broker: CONTINUUM
Trading: ES, Currency Futures, Forex, oil, gold, EUR/USD, Stocks
Posts: 315 since Jun 2014
Thanks Given: 412
Thanks Received: 132


rleplae View Post
While the bar is building your strategy can be called anytime there is an update in price. This allows you to fire an order 'inside the bar' that is building.

Like : (be carefull as this needs to be efficient and can generate a lot of calls)

 
Code
	protected override void OnMarketData (MarketDataEventArgs e)
		{
			System.TimeSpan NewDuration;			
			
			// ***************************************************
			
			if (e.MarketDataType == MarketDataType.Last)
			{
			if (mylong ==1)
			{
				// e.Time 
				myLastBarTime = e.Time;
				NewDuration = myLastBarTime - myEntryTime;

				// mfe ticks berekenen
				// new MFE ?
			
				if (e.Price > mylongentry)
				{
				if (Math.Min(e.Price,mylongtarget) > mfeval)
					mfeval = Math.Min(e.Price,mylongtarget);
				}
				if (mfeval > mylongentry)
					 mfeticks = Convert.ToInt32 ((mfeval-mylongentry)*myMULTIPLYER);
				
				// 5 minutes passed and never been positive
				// kick out
    			if (NewDuration.Minutes >= 5 && mfeticks == 0)
				{
	
				if (mfeticks == 0)
			    {			
					DebugPrint ("Kill : 5 minutes without any positive ticks *long*");
					ExitLong("Exit trade LU","ATM LU");
					
				}
				} // > 5 minutes and mfe 0
				
				// trade -5 and never been positive
				// kick-out
				if ( (e.Price <= (mylongentry - (7.0 * TickSize))) && mfeticks ==0 )
				{
					DebugPrint ("Kill : -7 ticks without any positive ticks *short*");
					ExitLong("Exit trade LU","ATM LU");

				}
				
				 
			} // we are in long
			
			if ( myshort ==1)
			{
				myLastBarTime = e.Time;
				NewDuration = myLastBarTime - myEntryTime;

     			// mfe ticks berekenen
				// new MFE ?
				if (e.Price < myshortentry)
				{
				 if (Math.Max(e.Price,myshorttarget) < mfeval)
					mfeval = Math.Max(e.Price,myshorttarget);
				}
				if (mfeval < myshortentry)
					 mfeticks = Convert.ToInt32 ((myshortentry - mfeval)*myMULTIPLYER);

    			if (NewDuration.Minutes >= 5 && mfeticks == 0)
				{
			
				if (mfeticks == 0)
			    {			
					DebugPrint ("Kill : 5 minutes without any positive ticks *short*");
			
									// new MAE ?
				    if (e.Price > myshortentry)
			 	    {
					 if (Math.Min(e.Price,myshortstop) > maeval)
						maeval = Math.Min(e.Price,myshortstop);
				    }

					ExitShort("Exit trade LD","ATM LD");

					
				}
				}

				// trade -5 and never been positive
				// kick-out
				if ( e.Price >= (myshortentry + (7.0 * TickSize)) && mfeticks ==0 )
				{
					DebugPrint ("Kill : -7 ticks without any positive ticks *short*");
					
  					if (Math.Min(e.Price,myshortstop) > maeval)
						maeval = Math.Min(e.Price,myshortstop);

					ExitShort("Exit trade LD","ATM LD");
				}
		
				
			} // we are in short
			} // new quote
			
		}
alternatively you can set

CalculateOnBarClose = false;
in your initialize section, then the onBarUpdate will be called on every tick


and then the

 
Code
      /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
			
			if (BarsInProgress == 1)
			{
				DebugPrint ("5 minute bar update...");
				return;
			}

	
			// Make sure this strategy does not execute against historical data
			if (Historical)
				return;
		
	
			BarCount++;
			
			
// ............
          // do your logic here -> and set myTradeCondition =1;

			if (myTradeCondition == 1)
			{
   			    DebugPrint("We go short");
			     if (myEntryOrder == null)
				 {
					//myReentry++;

				    // Set order parameters
					DebugPrint ("myEntryOrder == null");
				    SetStopLoss (CalculationMode.Ticks,mySTOPSHORT);
				    SetProfitTarget(CalculationMode.Ticks,myTARGETSHORT);
					myEntryOrder = 	EnterShort("ATM LD");
					barNumberOfOrder = CurrentBar;
					myshortorder = 1;			
				    StoreDataSnapShot ();
				    TradePuntC = myABCD_C;		
			 	 } 
								
				}
			
			
        } // on barupdate

Thank you very much. I really appreciate this.
Best.
Pep

Follow me on Twitter Started this thread Reply With Quote




Last Updated on September 8, 2015


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts