PDA

View Full Version : Stochastics fall below 20 & then move above 30 to trigger buy signal


sagatr
08-08-2010, 09:29 AM
Hi, This is my first post. I have been using Ninja Trader for few weeks and think its an excellent tool for trading.

I have been creating few stragies using the wizard and some manual coding.

But i just cant figure out how to code the following using the wizard or by coding:

if Stochastics(3, 5, 3) falls below 20

&& eventually Crosses above 30

{
EnterLong
}



Any help would be appreciated.

Thanks

NinjaTrader_Austin
08-08-2010, 10:54 AM
sagatr, there are quite a few ways to go about this, but you'll have to actually code it out. The best way would probably be to use a boolean (true/false) variable that stores information about if the stochastics have fallen below 20. Then, you can check for the cross above along with the boolean to decide if the value was below 20 and has gone above 30. In pseudo-code, it would look something like this:

private bool isBelowTwenty = false;
OnBarUpdate()
{
if (CrossAbove(Stochastics, 30) && isBelowTwenty)
EnterLong();

if (Stochastics < 20)
isBelowTwenty = true;
else
isBelowTwenty = false;
}


If you need coding assistance, you can contact one of our 3rd party NinjaScript consultants (http://www.ninjatrader.com/webnew/partners_onlinetrading_NinjaScript.htm).