View Full Version : Questions on execution of strategy code
ThePatientOne
05-02-2007, 06:33 AM
I am in the middle of creating a strategy based on a custom complex indicator. This strategy has two data series. This custom indicator executes on the data from the second data series.
I am having an issue that doesn't make sense to me. I already wrote this strategy as an indicator and it works perfectly.
I now have the code moved into a strategy, however, some peculiar results are showing up.
I have two variables that I use to prevent "double" entries from being taken (entries taken *right* after a profit/stop gets filled). In essence, I only take one trade in one direction and then wait for a trade in the opposite direction to "reset" possible entries in the first direction.
Here is what it looks like in the strategy:
if (criteria1 and criteria2 and OKForLong)
{
EnterLong(1);
OKForLong = false;
OKForShort = true;
}
if (criteria3 and criteria4 and OKForShort)
{
EnterShort(1);
OKForShort = false;
OKForLong = true;
}
This code works perfectly in the indicator but generates NO orders in the strategy. (the indicator places arrows/text on the bars on the chart instead of enter() orders)
NOW ... when I take out the OKForLong/Short out of the if() statements, all of the correct trade entries get generated (including the double entries of course). BUT ... with them in, no trades at all.
This tells me that these two variables are not getting reset.
Couple of things:
1) These variables are global scope to the strategy
2) They are reset to true when ToDay(Times[1][0]) != ToDay(Times[1][1]) (A new day starts in the second data series on which my indicator/strategy is driven).
Any ideas?
Thanks!
NinjaTrader_Dierk
05-02-2007, 06:55 AM
Not sure how your strategy should work in all details and analyzing complete strategies is beyond the scope of what we can support, but here are some hints:
- OKForLong and OKForShort need to be initialized to true. If not then your logic never will make it into the if branches
- printing out values of OKForLong and OKForShort could help
- is there funny stuff in the logs which would indicate coding bugs
- Times[1][0] indicates a multi series strategy (Times[1] is the second ! series). Is that your intention? I suggest starting simply as possible with a single series strategy
ThePatientOne
05-02-2007, 07:01 AM
Thanks Dierk,
I found out that the Strategy is, in fact, working correctly. HOWEVER, the Strategy Analyzer is what is failing.
Here is debug code from my Strategy as reported by the output window. I am printing when the OKForLong/Short is reset as well as when the strategy actually goes long/short.
20070105: Resetting. Longs=True / Shorts=True
95000 Short
104500 Long
143000 Long
20070108: Resetting. Longs=True / Shorts=True
91500 Short
94500 Long
105000 Long
111500 Long
123500 Long
135000 Short
145000 Short
20070109: Resetting. Longs=True / Shorts=True
94000 Long
However, I get NO trades listed in the Trades tab, Charts tab or Summary tab in the Strategy Analyzer. Removing the OKForLong/Short from the criteria list, produces the same output but I actually get results in the Analyzer.
Clues?
NinjaTrader_Dierk
05-02-2007, 07:04 AM
Try TraceOrders=true in Initialize() to see what happens to your signals.
NinjaTrader_Dierk
05-02-2007, 07:05 AM
Did you check the logs?
ThePatientOne
05-02-2007, 08:40 AM
Sorry for the delay ... had to step out.
Thanks for the help so far. Here is what trace reports:
90500 Short
Entered internal PlaceOrder() method at 1/4/2007 9:05:00 AM: Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName=se2' FromEntrySignal=''
Entered internal SetStopTarget() method at 1/4/2007 9:05:00 AM: Type=Target FromEntrySignal='' Mode=Ticks Value=15 Currency=0 Simulated=False
Entered internal SetStopTarget() method at 1/4/2007 9:05:00 AM: Type=Stop FromEntrySignal='' Mode=Ticks Value=21 Currency=0 Simulated=False
95000 Long
Entered internal PlaceOrder() method at 1/4/2007 9:50:00 AM: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName=le2' FromEntrySignal=''
Entered internal SetStopTarget() method at 1/4/2007 9:50:00 AM: Type=Target FromEntrySignal='' Mode=Ticks Value=15 Currency=0 Simulated=False
Entered internal SetStopTarget() method at 1/4/2007 9:50:00 AM: Type=Stop FromEntrySignal='' Mode=Ticks Value=21 Currency=0 Simulated=False
110500 Long
Entered internal PlaceOrder() method at 1/4/2007 11:05:00 AM: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName=le2' FromEntrySignal=''
Entered internal SetStopTarget() method at 1/4/2007 11:05:00 AM: Type=Target FromEntrySignal='' Mode=Ticks Value=15 Currency=0 Simulated=False
Entered internal SetStopTarget() method at 1/4/2007 11:05:00 AM: Type=Stop FromEntrySignal='' Mode=Ticks Value=21 Currency=0 Simulated=False
112000 Short
Entered internal PlaceOrder() method at 1/4/2007 11:20:00 AM: Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName=se2' FromEntrySignal=''
Entered internal SetStopTarget() method at 1/4/2007 11:20:00 AM: Type=Target FromEntrySignal='' Mode=Ticks Value=15 Currency=0 Simulated=False
Entered internal SetStopTarget() method at 1/4/2007 11:20:00 AM: Type=Stop FromEntrySignal='' Mode=Ticks Value=21 Currency=0 Simulated=False
122000 Long
Entered internal PlaceOrder() method at 1/4/2007 12:20:00 PM: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName=le2' FromEntrySignal=''
Entered internal SetStopTarget() method at 1/4/2007 12:20:00 PM: Type=Target FromEntrySignal='' Mode=Ticks Value=15 Currency=0 Simulated=False
Entered internal SetStopTarget() method at 1/4/2007 12:20:00 PM: Type=Stop FromEntrySignal='' Mode=Ticks Value=21 Currency=0 Simulated=False
125000 Short
Entered internal PlaceOrder() method at 1/4/2007 12:50:00 PM: Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName=se2' FromEntrySignal=''
Entered internal SetStopTarget() method at 1/4/2007 12:50:00 PM: Type=Target FromEntrySignal='' Mode=Ticks Value=15 Currency=0 Simulated=False
Entered internal SetStopTarget() method at 1/4/2007 12:50:00 PM: Type=Stop FromEntrySignal='' Mode=Ticks Value=21 Currency=0 Simulated=False
131500 Long
Entered internal PlaceOrder() method at 1/4/2007 1:15:00 PM: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName=le2' FromEntrySignal=''
Entered internal SetStopTarget() method at 1/4/2007 1:15:00 PM: Type=Target FromEntrySignal='' Mode=Ticks Value=15 Currency=0 Simulated=False
Entered internal SetStopTarget() method at 1/4/2007 1:15:00 PM: Type=Stop FromEntrySignal='' Mode=Ticks Value=21 Currency=0 Simulated=False
145000 Short
Entered internal PlaceOrder() method at 1/4/2007 2:50:00 PM: Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName=se2' FromEntrySignal=''
Entered internal SetStopTarget() method at 1/4/2007 2:50:00 PM: Type=Target FromEntrySignal='' Mode=Ticks Value=15 Currency=0 Simulated=False
Entered internal SetStopTarget() method at 1/4/2007 2:50:00 PM: Type=Stop FromEntrySignal='' Mode=Ticks Value=21 Currency=0 Simulated=False
20070105: Resetting. Longs=True / Shorts=True
95000 Short
Entered internal PlaceOrder() method at 1/5/2007 9:50:00 AM: Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName=se2' FromEntrySignal=''
Entered internal SetStopTarget() method at 1/5/2007 9:50:00 AM: Type=Target FromEntrySignal='' Mode=Ticks Value=15 Currency=0 Simulated=False
Entered internal SetStopTarget() method at 1/5/2007 9:50:00 AM: Type=Stop FromEntrySignal='' Mode=Ticks Value=21 Currency=0 Simulated=False
Still doesn't report any trades in the Analyzer even though they are being entered according to the logs.
ThePatientOne
05-02-2007, 08:54 AM
I have a hunch:
My two bar series are two different markets. I get my signals from the second bar series (1) and want to place trades on the first bar series (0).
When I *don't* check for BarsInProgress == 1, I get trades in the Analyzer when I place EnterXX() orders. When I *do* check and place EnterXX() orders, I don't get trades in the Analyzer.
My broker does not support trades against the second bar series but *does* for the first bar series. Therefore, I am probably not getting trades listed because the order is being rejected ... even though the logs and trace logs do not report this.
Question: when I place EnterXX() orders, do these orders automatically get placed against bar series (0) or the bar series generating the call to OnBarUpdate()?
Can I force the order to a particular symbol or bar series?
Thanks
ThePatientOne
05-02-2007, 09:06 AM
BINGO!
This is the issue I am having.
I'll figure something out.
Thanks for the help Dierk!!
You guys are doing a super job with this platform ... keep it up!!!!
NinjaTrader_Dierk
05-02-2007, 04:49 PM
Great. You always you should check the logs first, since they hold messages in case there is something wrong with order placement on "wrong" series.
ThePatientOne
05-03-2007, 12:47 AM
Thanks Dierk.
Now another question.
My strategy is set to execute on the close of the bar and it needs to be that way. However, the strategy trade execution and management is driven from the second data series (BarsArray[1]) BUT it needs to trade the market loaded into the primary data series (BarsArray[0]). Is there ANYWAY this can be done in a NinjaTrader strategy?
Before any trade can be entered into, I *must* have a closed bar on BarsArray[1] that my strategy code is executing against.
Thanks
NinjaTrader_Dierk
05-03-2007, 12:53 AM
Not that I could think of. However, we will consider that and let you know.
ThePatientOne
05-03-2007, 01:46 AM
Thanks Dierk.
Anything on this would help. My Strategy is pretty much complete and operational EXCEPT this.
Thanks again for the help.
NinjaTrader_Dierk
05-03-2007, 02:51 AM
We discussed this issue but found that changing the implementation now would have serious impact on the stability of the product. However we put this on our list of high priority issues and will provide a soltuion later on this year.
Sorry for the inconvenience and thanks for your understanding.
ThePatientOne
05-03-2007, 03:34 AM
I understand and agree with your statements.
Thank you for all of your help. You guys are doing a terrific job and have done *much* in such a short amount of time.
ThePatientOne
05-08-2007, 08:05 AM
We discussed this issue but found that changing the implementation now would have serious impact on the stability of the product. However we put this on our list of high priority issues and will provide a soltuion later on this year.
Do you have any ETA on when this may be implemented? If you need assistance in testing this feature during a beta, I would be interested in assisting.
Thanks again.
NinjaTrader_Ray
05-08-2007, 08:13 AM
No confirmed ETA but fall time frame would be reasonable. We will put this release through a beta cycle and appreciate your willingess to participate.