![]() |
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Jan 2009
Location: Melbourne
Posts: 179
Thanks: 3
Thanked 0 times in 0 posts
|
NT Team,
I'm trying to better understand how a strategy I've built is operating. The strategy is constructed using the IOrder structure including "OnOrderUpdate(IOrder order)", "OnExecution (IExecution execution)", and OnPositionUpdate(IPosition position) elements. When Print commands or Alerts are inserted into these elements the strategy seems to fall apart. It should be noted, I've created two near identical strategies, one for backtesting and one for live trading. The only difference is the backtesting strategy calculates on bar close, while the live strategy calculates within the last three seconds before a bar ends. There is clearly a gap in my understanding. Any insight on why these commands are causing such grief when placed in these elements of the code? As always, thanks Shannon |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,559
Thanks: 261
Thanked 1,015 times in 996 posts
|
Shannon, thanks for the post - could you please clarify what you mean by 'breaking apart'? Do you get any errors in the log tab?
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Jan 2009
Location: Melbourne
Posts: 179
Thanks: 3
Thanked 0 times in 0 posts
|
Bertrand,
Apologies for the lack of clarity. The strategy in question contains the below segment of code (excluding the Italicized Print lines). The code operates (i.e. runs successfully) but does not yield the expected results. The Italicized Print lines were added to help me understand what's happening and make amendments were necessary. // Long position TIME PERIOD, raise the stop-loss order to half of entry bar range and the profit-target order to breakeven.With the Italicized Print lines added, the strategy analyser runs until the first instance where the above code would be called, where a long position is six or more bars since entry. At this point the strategy stops (the last position remains open) and the following error appears in the log "Error on calling 'OnBarUpdate' method for strategy 'LivePPT2': Object reference not set to an instance of an object.". I'm sure I'm missing something, I've tried different syntax to return information on the stopOrder, in place of stopOrder.ToString(), but no luck. Any guidance would be appreciated. Regards Shannon |
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,559
Thanks: 261
Thanked 1,015 times in 996 posts
|
Shansen, with this error message in mind, please doublecheck your code to ensure you don't attempt to access an empty object.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Jan 2009
Location: Melbourne
Posts: 179
Thanks: 3
Thanked 0 times in 0 posts
|
Bertrand,
Thanks for the advice. It look quite some looking, but I uncovered the problem. Thanks Now I've corrected that problem and have a better understanding of the below code... I think what I was trying to do will not work. To frame my question, in the strategy when a long trade is entered a stoploss is placed at the low of the entry bar. In the event a trade has been in effect for 6 or more bars, I wished to move the stoploss up to the entry bar midpoint (i.e. (LongEntryLow + LongEntryHigh) / 2). I am unsure whether I can do this or need to check to ensure the CurrentBid is greater than this level first? Or, whether it would be better to state if a trade has been in effect for 6 or more bars and the CurrentBid is below entry bar midpoint ExitLong. If this is possible will existing Stop Orders be cancelled in the IOrder strategy structure. I'm sure this problem is on the ropes. Any guidance would be appreciated. Regards Shannon |
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,559
Thanks: 261
Thanked 1,015 times in 996 posts
|
Shansen, yes monitoring the CurrentBid / CurrentAsk is good to ensure those stops do not get rejected as you place them, you can of course also exit those with ExitLong / ExitShort as your Exit condition triggers, though you might need to test which gives you better fills....
Bertrand
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| BarsSinceEntry in IOrder strategy structure | Shansen | Strategy Development | 1 | 06-18-2009 06:43 AM |
| Coding structure questions | dirtybrown | Indicator Development | 2 | 05-26-2009 06:35 AM |
| Data structure | xewoox | Strategy Development | 1 | 03-02-2009 02:00 PM |
| Using IOrder in a Strategy | clfield | General Programming | 7 | 12-01-2008 03:46 PM |
| Fee structure for V6 | Antraman | Installation and Licensing | 1 | 12-18-2006 01:53 PM |