PDA

View Full Version : excute order entry just once


badasan
05-30-2009, 02:18 PM
Hi,

How should I write a code to excute order entry just once although
strategy may generate many signals? For example, if I have two moving
average cross strategy, it will generate long or short signal whenever
fast moving average crosses over or below slow moving average. I just
want to take first signal and ignore any signal after first. How should I
code this situation?

Thanks in advance.

NinjaTrader_Ben
05-30-2009, 06:05 PM
Hello,

I suggest creating a bool flag that is set to true or false, then have that flag as a condition to trading.

Let me know if you have questions.

m3power222
06-15-2009, 03:26 PM
Badasan did you come up with a solution for this? (http://www.ninjatrader-support2.com/vb/member.php?u=8915)

badasan
06-16-2009, 07:19 AM
Hi m3power222,

No. I just shut down the strategy as soon as I take the first signal.

Trade1953
07-03-2009, 02:41 PM
Badasan,
Here's a simple way to do what Ben is suggesting. I don't use the boolean, but a simple variable. I'm not going to write it in code, but it will give you the idea:

First, Add this to your variables section in the Ninjascript strat you are writing:
private int firstcross = 0:

Then, for the first entry condition:

If (firstcross <= 0
&& SMA7 crosses SMA 20
{
Enter Long (or Short);
firstcross = 1
}

From that point on, as long as firstcross is not reset to zero, it won't take any more trades.
Hope that helps,
Joe

** This variable thing is REALLY handy to do all kinds of things with a script!

badasan
07-05-2009, 08:28 AM
Thank you very much Trade1953. I appreciate your help.