NinjaTrader Support Forum  
X

Attention!

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


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 11-30-2009, 09:48 AM   #1
stephenszpak
Senior Member
 
Join Date: Apr 2006
Location: , ,
Posts: 192
Thanks: 3
Thanked 0 times in 0 posts
Default help with simple strategy

I'm looking at the YM now using 10 tick SbS Renko bars (attachment).
(Does anyone at support know of a similar question asked recently
that I can look at in a thread? see below)

The idea is to put on a long trade with a stop, for a up Rekno, assuming up market.
Exit the trade should the stop be hit on the first bar.
Wait until next bar and enter long if up bar, or short, if down bar (with stop of course)
and then just stay with the trade if it goes up (or if short, down).

If long trade was entered, let's just say, then exit at the first down bar, go short,
with a stop of course, and just stay short.


I've tried with IF statements only. Should I use WHILE, or ????, or ????
Any hint(s) would help at this point. I know this is simple really.

- Stephen
Attached Images
File Type: jpg Clipboard-SbS.jpg (64.5 KB, 19 views)
stephenszpak is offline  
Reply With Quote
Old 11-30-2009, 10:00 AM   #2
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

You would use if-statements. Check if the close > open for up bars and close < open for down bars.
NinjaTrader_Josh is offline  
Reply With Quote
Old 11-30-2009, 10:21 AM   #3
stephenszpak
Senior Member
 
Join Date: Apr 2006
Location: , ,
Posts: 192
Thanks: 3
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_Josh View Post
You would use if-statements. Check if the close > open for up bars and close < open for down bars.
Thanks. That's what I did. I've got something like this, see below.
I've tried different things, but you might get the idea below of where I'm
trying to go in general.
(The BarsSinceExit, is so that the strategy doesn't enter long (or short)
a second time in the bar it just got stopped out of.)


if (BarsSinceExit()>0 && (BarsSinceExit()<2 && (Close[0]>Close[1])))
EnterLong();
SetStopLoss(CalculationMode.Ticks,10);

|| if (BarsSinceExit()>0 && (BarsSinceExit()<2&& (Close[0]<[1])))
EnterShort();
SetStopLoss(CalculationMode.Ticks,10);

if (Close[0]<Close[1])
ExitLong();
EnterShort();
SetStopLoss(CalculationMode.Ticks,10);

if (Close[0]>Close[1])
ExitShort();
EnterLong()
SetStopLoss(CalculationMode.Ticks,10);

I don't know. Still thinking (or what passes for it). I guess I need to get this
code into a loop of some sort?
stephenszpak is offline  
Reply With Quote
Old 11-30-2009, 10:34 AM   #4
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

Please describe exactly what part you feel does not work as expected. Thank you.
NinjaTrader_Josh is offline  
Reply With Quote
Old 11-30-2009, 10:53 AM   #5
stephenszpak
Senior Member
 
Join Date: Apr 2006
Location: , ,
Posts: 192
Thanks: 3
Thanked 0 times in 0 posts
Default

Well after this...

if (Close[0]<Close[1])
ExitLong();
EnterShort();
SetStopLoss(CalculationMode.Ticks,10);

...the long trade is exited and a short trade is entered with it's stop.
But then if I get stopped out on the short trade that I just entered, let's say,
stopped out immediately
(the short trade entered right now at the trend change).

So I must re-enter short trade on NEXT bar...
{I don't want to keep entering short (or long) on the same bar I just
got stopped out of.}

...IF it happens to be a down bar

OR else enter long trade on next bar IF a up bar.

(I'm going through various combinations here that have no relevance
to the attachment.)


I need to loop back on all this I assume somehow, using BarsSinceExit with
the stop loss parameters.
stephenszpak is offline  
Reply With Quote
Old 11-30-2009, 10:59 AM   #6
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

You need to limit your if-statement. That condition you have there does not care whether or not you just entered. You need to prevent it from evaluating to true again and again.

Some ideas.
Code:
if (Close[0] > Open[0] && enteredLong == false)
{
    // place trades;
    enteredLong = true;
    enteredShort = false;
}

if (Close[0] < Open[0] && enteredShort == false)
{
   // trades
   enteredLong = false;
   enteredShort = true;
}
NinjaTrader_Josh is offline  
Reply With Quote
Old 11-30-2009, 12:24 PM   #7
stephenszpak
Senior Member
 
Join Date: Apr 2006
Location: , ,
Posts: 192
Thanks: 3
Thanked 0 times in 0 posts
Default

Does this seem like it would work (see code below)? It's doing something now.
I appreciate the help so far.

Should I always see a trade in the DOM if the chart is showing that a trade has
been executed? I wonder about that. The YM is selected on the DOM yet it is
indicating flat now. Chart plots a long trade currently.


I noticed you used Open, as in,
if(Close[0]> OPEN[0] && enteredLong==false) using OPEN may be better than
using close. Anyway there is no such
thing as Renkos (that work). Even
roonius hasn't solved that yet. So
I'm looking at the SbSRenko as I said earlier.
(even though it's not what I want, it may
not even be possible for NT to do generic Renkos)



================================================== ================
================================================== ================

protected override void Initialize()
{
// Be sure to use TRUE here!
CalculateOnBarClose = true;
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
bool enteredLong=false;
bool enteredShort=false;
if (Close[0]>Close[1]&& enteredLong==false)
{
EnterLong();
SetStopLoss(CalculationMode.Ticks,10);

}
if (Close[0]<Close[1]&& enteredShort==false)
{
EnterShort();
SetStopLoss(CalculationMode.Ticks,10);

}

}

================================================== ================
================================================== ================
stephenszpak is offline  
Reply With Quote
Old 11-30-2009, 12:43 PM   #8
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

You would probably want to create those bools in the Variables region of your code before OnBarUpdate().
NinjaTrader_Josh is offline  
Reply With Quote
Old 11-30-2009, 12:53 PM   #9
stephenszpak
Senior Member
 
Join Date: Apr 2006
Location: , ,
Posts: 192
Thanks: 3
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_Josh View Post
You would probably want to create those bools in the Variables region of your code before OnBarUpdate().
Ok, trying that now.

I spent a few minutes with the DOM's properties, but I
still think it's not showing me long as it should. Will the DOM, if set up correctly,
always confirm the plots/executions on a chart running a strategy?

- Stephen
stephenszpak is offline  
Reply With Quote
Old 11-30-2009, 01:24 PM   #10
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

Not sure what you mean. What a strategy has in terms of positions can be seen in the Strategies tab of the Control Center.
NinjaTrader_Josh is offline  
Reply With Quote
Old 11-30-2009, 04:07 PM   #11
stephenszpak
Senior Member
 
Join Date: Apr 2006
Location: , ,
Posts: 192
Thanks: 3
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_Josh View Post
Not sure what you mean. What a strategy has in terms of positions can be seen in the Strategies tab of the Control Center.
Used BarChart today (first day) and NT crashed at the end of the day.
I checked on the box 'store real-time bar data' and it was checked but
that was after the fact. It looks like the day's data was recorded but then lost.
No big deal.
Well this computer is old so that's probably the reason. I might not be able
to get into this again for a few days, however I accomplised much more than
I ever thought I would with all your help today.

- Stephen
stephenszpak is offline  
Reply With Quote
Old 12-01-2009, 05:00 AM   #12
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,404
Thanks: 252
Thanked 973 times in 956 posts
Default

Stephen, I'm not sure I follow why you would need this option checked for BarChart - they provide historical data on theirs servers for backfilling, thus you could leave this unchecked for better performance.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 12-05-2009, 11:08 PM   #13
stephenszpak
Senior Member
 
Join Date: Apr 2006
Location: , ,
Posts: 192
Thanks: 3
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_Bertrand View Post
Stephen, I'm not sure I follow why you would need this option checked for BarChart - they provide historical data on theirs servers for backfilling, thus you could leave this unchecked for better performance.
Thanks. I will be looking into this today. So you say that I can get tick data, going back
XX days... ONLY during market hours, for the YM? This is exactly what I would want so
I can use market replay on the strategy.

- Stephen
stephenszpak is offline  
Reply With Quote
Old 12-06-2009, 07:58 AM   #14
stephenszpak
Senior Member
 
Join Date: Apr 2006
Location: , ,
Posts: 192
Thanks: 3
Thanked 0 times in 0 posts
Default

(The only video of Market Replay I've seen at the NT site is for an older version
so it doesn't help too much.)

I've gone to Tools|Options|Data| and clicked on Market Replay recorder.
I've gone to File| Connect | Market Replay connection...the Market Replay
connection words will not highlight, so obviously it will not activate.
I do have a chart up of Friday's YM but "Strategies" can not be engaged.

- Stephen

I finally got Market Replay to activate but I'm still trying to get it to see some
of the data I collected from last week.
Last edited by stephenszpak; 12-06-2009 at 01:42 PM.
stephenszpak is offline  
Reply With Quote
Old 12-06-2009, 09:48 PM   #15
stephenszpak
Senior Member
 
Join Date: Apr 2006
Location: , ,
Posts: 192
Thanks: 3
Thanked 0 times in 0 posts
Default

Last try for help on this thread

In Control Center|Tools|Options|Data ....

is it necessary to simultaneously have both these checked:

Store real-time bar data AND Run market replay recorder

I can display in a chart the last few days of the YM but the
file:

MyDocuments|NinjaTrader6.5|db|data will only show:

20091206


I did connect to BarChart.com briefly today. I guess this is that.
Apparently I have data is SOME format, since I can display a multi-day
SbS Renko chart but I'm going to assume MarketReplay can't use it unless
I'm told otherwise.

- Stephen
stephenszpak is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple Strategy BradB Strategy Development 3 04-23-2009 06:50 PM
Simple question about a simple strategy. shakira Strategy Development 1 02-14-2009 10:56 AM
Simple strategy rnr123 Strategy Analyzer 1 10-17-2008 07:04 AM
need help with simple strategy mike8943 Strategy Development 1 07-17-2008 08:21 AM
Simple Strategy Oli Automated Trading 2 03-05-2007 11:42 PM


All times are GMT -6. The time now is 12:48 PM.