Dark Theme
Light Theme
Welcome to NexusFi: the best trading community on the planet, with over 200,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to
register in order to view the content of the threads and start contributing to our community.
It's free for basic access, or support us by becoming an Elite Member -- discounts are available after registering.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Updated September 8, 2015
trending_up
2,863 views
thumb_up
1 thanks given
group
2 followers
forum
5 posts
attach_file
0 attachments
September 7th, 2015, 02:15 PM
Madrid - Spain
Experience: Intermediate
Platform: NinjaTrader
Broker: CONTINUUM
Trading: ES, Currency Futures, Forex, oil, gold, EUR/USD, Stocks
Posts: 317 since Jun 2014
Thanks Given: 417
Thanks Received: 133
Hi , I am trying to understand how 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
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
September 7th, 2015, 02:40 PM
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: 2,947 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,860
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
September 7th, 2015, 02:55 PM
Madrid - Spain
Experience: Intermediate
Platform: NinjaTrader
Broker: CONTINUUM
Trading: ES, Currency Futures, Forex, oil, gold, EUR/USD, Stocks
Posts: 317 since Jun 2014
Thanks Given: 417
Thanks Received: 133
rleplae
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
September 8th, 2015, 01:03 AM
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: 2,947 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,860
pepbosch
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
September 8th, 2015, 08:20 AM
Madrid - Spain
Experience: Intermediate
Platform: NinjaTrader
Broker: CONTINUUM
Trading: ES, Currency Futures, Forex, oil, gold, EUR/USD, Stocks
Posts: 317 since Jun 2014
Thanks Given: 417
Thanks Received: 133
rleplae
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
Last Updated on September 8, 2015