![]() |
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
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Apr 2006
Location: , ,
Posts: 192
Thanks: 3
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#2 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
You would use if-statements. Check if the close > open for up bars and close < open for down bars.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#3 | |
|
Senior Member
Join Date: Apr 2006
Location: , ,
Posts: 192
Thanks: 3
Thanked 0 times in 0 posts
|
Quote:
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? |
|
|
|
|
|
|
#4 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
Please describe exactly what part you feel does not work as expected. Thank you.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Apr 2006
Location: , ,
Posts: 192
Thanks: 3
Thanked 0 times in 0 posts
|
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. |
|
|
|
|
|
#6 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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;
}
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Senior Member
Join Date: Apr 2006
Location: , ,
Posts: 192
Thanks: 3
Thanked 0 times in 0 posts
|
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); } } ================================================== ================ ================================================== ================ |
|
|
|
|
|
#8 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
You would probably want to create those bools in the Variables region of your code before OnBarUpdate().
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#9 | |
|
Senior Member
Join Date: Apr 2006
Location: , ,
Posts: 192
Thanks: 3
Thanked 0 times in 0 posts
|
Quote:
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 |
|
|
|
|
|
|
#10 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
Not sure what you mean. What a strategy has in terms of positions can be seen in the Strategies tab of the Control Center.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#11 | |
|
Senior Member
Join Date: Apr 2006
Location: , ,
Posts: 192
Thanks: 3
Thanked 0 times in 0 posts
|
Quote:
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 |
|
|
|
|
|
|
#12 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,404
Thanks: 252
Thanked 973 times in 956 posts
|
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.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#13 | |
|
Senior Member
Join Date: Apr 2006
Location: , ,
Posts: 192
Thanks: 3
Thanked 0 times in 0 posts
|
Quote:
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 |
|
|
|
|
|
|
#14 |
|
Senior Member
Join Date: Apr 2006
Location: , ,
Posts: 192
Thanks: 3
Thanked 0 times in 0 posts
|
(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.
|
|
|
|
|
|
#15 |
|
Senior Member
Join Date: Apr 2006
Location: , ,
Posts: 192
Thanks: 3
Thanked 0 times in 0 posts
|
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 |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |