![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| Automated Trading Support for automated trading systems using NinjaScript. Support for our ATI (Automated Trading Interface) used to link an external application such as TradeStation and eSignal to NinjaTrader. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Jun 2009
Posts: 737
Thanks: 19
Thanked 8 times in 8 posts
|
Hello,
when I have set COBC=true in the script strategy then "setstoploss" works also within a bar and not only at close of bar. But for my targets eg if (GetCurrentAsk(0) < Position.AvgPrice - 6 * TickSize) ExitShort..........; this is only realized at close of bar, so eg with 5 Range-Bars with 10 pips in profit and not with 6 pips. How can one do with COBC so that also targets are realized at certain pips and not close of bar (but avoiding "setprofittarget" - as I donīt want to work with brackets) Thank you! ![]() Tony |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
Hello tonynt,
Thanks for writing in and I am happy to assist you. You can set COBC to true place your exit logic in the OnMarketData event. As such your entry codes which is placed in OnBarUpdate will be calculated at bar close but your exits will be calculated realtime. http://www.ninjatrader.com/support/h...marketdata.htm Alternatively you can set COBC to false but filter the entry codes in the FirstTickOfBar (thus it gets calculated only once at the start of the bar). Since COBC is set to false your exit logic will be calculated on every tick. Please see the below sample code which demonstrates this. http://ninjatrader.com/support/forum...ad.php?t=19387 Please let me know if I can assist you any further.
Joydeep M.
NinjaTrader Customer Service |
|
|
|
|
|
#3 | |
|
Senior Member
Join Date: Jun 2009
Posts: 737
Thanks: 19
Thanked 8 times in 8 posts
|
Thank you for your reply.
The question is only important because of CPU of my computer (or maybe its not important). Is there a big difference for CPU and PC-ressources when running a script-strategy with COBC=true or with COBC=false? If not, I can continue using COBC=false. In the meantime I found in the forum the information that "OnBarUpdate() fires on each bar update or tick (COBC setting for study), while the OnMarketData() fires on each Level 1 event change (bid, ask, last ...)" - does this work on forex? And is there a difference for the PC-ressources then? At this moment I want to add another question please: is it possible to start a script with "SetStopLoss("S2A", CalculationMode.Ticks, 10, false);" but to change it later on referring to certain condtions to "SetTrailStop("S2A",CalculationMode.Ticks, 3, false); (I know I can not use both together, therefore I ask if I can substitute SetStopLoss by SetTrailStop during a running script, eg when certain ticks in profit. For better understanding - its not only to change 10 by 3 - of course I could do only with Trail - this is only an example here, the SetStopLoss starts with certain variables) Thank you! Tony Quote:
Last edited by tonynt; 03-09-2012 at 12:34 PM.
Reason: clearify question
|
|
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
Hello tonynt,
How CPU intensive it will be depends on your code. For example if your entry logic are complex and CPU intensive but your exit codes are not, then your strategy wont be CPU intensive since the entry logic are being calculated once. OnMarketData opens a data stream and you will get all bid/ask/last price through OnMarketData and thus it is resource intensive. However you can filter the data as: Code:
protected override void OnMarketData(MarketDataEventArgs e)
{
if (e.MarketDataType == MarketDataType.Last)
{
//do something only when last price updates
}
}
No, you cannot mix SetStopLoss with SetTrialStop. However you can reassign the SetStopLoss method. For example if you initially placed SetStopLoss(CalculationMode.Tick, 10) order you can reassign it as SetStopLoss(CalculationMode.Tick, 3). This will change your stop loss order. Please let me know if I can assist you any further.
Joydeep M.
NinjaTrader Customer Service |
|
|
|
|
|
#5 | |
|
Senior Member
Join Date: Jun 2009
Posts: 737
Thanks: 19
Thanked 8 times in 8 posts
|
Thank you. To understand correctly - for same entry-conditions which one is more CPU intensive - onbarupdate or onmarketdata?
And last question in this concern please: when I have COBC=false; and simple entry-condtion eg Close[0] < Open[0]) why is the entry done immediately when enabling the strategy - and now when "Close" < Open? Thanks Tony Quote:
Last edited by tonynt; 03-09-2012 at 01:48 PM.
|
|
|
|
|
|
|
#6 | |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
Hello tonynt,
OnMarketData will be more resource intesive. From help file: Quote:
It is difficult to say without seeing the complete code, but with COBC set to false, orders will be submitted as and when the condition meets and wont wait for the close of the bar. If you want the trades to be submitted only on the close of the bar with COBC set to false then please filter the code with FirstTickOfBar function. Please let me know if I can assist you any further.
Joydeep M.
NinjaTrader Customer Service |
|
|
|
|
|
|
#7 | |
|
Senior Member
Join Date: Jun 2009
Posts: 737
Thanks: 19
Thanked 8 times in 8 posts
|
Thank You! So, finally for understanding the Close[0]
The code simply (for testing COBC) is: (COBC=false) ......... if (Position.MarketPosition == MarketPosition.Flat && Close[0] < Open[0]) {EnterShort(1000, "S1A");} The entry is not after close - its immediately when enabling the strategy. Shouldnīt be the entry only after "Close[0]" even when COBC= false? Then we got it. Thank you Tony Quote:
Last edited by tonynt; 03-09-2012 at 02:38 PM.
|
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Backtesting with COBC - False | Ashtree gambler | Strategy Development | 3 | 02-07-2012 07:53 AM |
| Cobc | ziggymeister | Strategy Development | 1 | 11-30-2011 02:08 AM |
| Cpu - cobc | tonynt | Connecting | 3 | 11-29-2011 12:50 PM |
| Multi-TimeFrame and COBC ? | jonmoron | Strategy Development | 14 | 09-07-2010 03:53 AM |
| Strategy COBC=false, Indicator COBC=true? | MXASJ | Version 7 Beta General Questions & Bug Reports | 2 | 06-28-2010 05:35 AM |