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 07-30-2009, 09:19 PM   #1
lightfoot500
Member
 
Join Date: Jul 2009
Posts: 43
Thanks: 4
Thanked 0 times in 0 posts
Default building my first strategy

hello,
getting to know the strategy wizard on ninja and trying to put together a simple buy/sell strategy to get a handle on building strategys..

what i want is...is to enter a trade when price closes outside the bollinger band AND stochastics is oversold/overbot. so if price is outside the upper bb AND stochastics is >75 then i would enter a short(SET 1).... and if price is below the lower bb AND stoch is <25 then enter long.. (SET 2)
and i would exit using a trailing stop of one point which i believe is 4 ticks.
I want only one trade per overbot/oversold event because often such overbot/oversold conditions occur for more than one bar in a row.
and a one point stop loss.
i would also like to put arrow markers on the chart when the overbot/oversold event occurs for n bars.

what i got is.... something close, but i am not sure it is quite what i want.
first off, i dont get the arrow heads over the overbot/oversold event..?
is it placing two trades when it says for example, "close position 1@989.50 sell short 1@989.50".?
third, i am not sure the entry is occurring at the first event of the overbot/oversold ?
and my autotrail stop doesnt seem to stopping me out after 4 ticks.. assuming a tick is a quarter point?
this attached screen shot shows an example.




Attached Images
File Type: jpg ES 09-09 7_30_2009 (1 Min).jpg (85.0 KB, 37 views)
lightfoot500 is offline  
Reply With Quote
Old 07-30-2009, 09:21 PM   #2
lightfoot500
Member
 
Join Date: Jul 2009
Posts: 43
Thanks: 4
Thanked 0 times in 0 posts
Default and here is the code from the strategy builder

here is the code from the strategy..hope this is enough info..
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
///<summary>
/// entry on over extension of price...
///</summary>
[Description("entry on over extension of price... ")]
publicclass overbotsold : Strategy
{
#region Variables
// Wizard generated variables
// User defined variables (add any user defined variables below)
#endregion
///<summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
///</summary>
protectedoverridevoid Initialize()
{
SetStopLoss(
"", CalculationMode.Ticks, 4, false);
CalculateOnBarClose =
true;
}
lightfoot500 is offline  
Reply With Quote
Old 07-30-2009, 09:23 PM   #3
lightfoot500
Member
 
Join Date: Jul 2009
Posts: 43
Thanks: 4
Thanked 0 times in 0 posts
Default and here is the second half of the code

///<summary>
/// Called on each bar update event (incoming tick)
///</summary>
protectedoverridevoid OnBarUpdate()
{
// Condition set 1
if (High[0] >= Bollinger(2, 20).Upper[0]
&& StochasticsFilled(
3, 9, 3).K[0] >= 75)
{
DrawArrowDown(
"My down arrow" + CurrentBar, false, 0, 0, Color.Red);
EnterShort(DefaultQuantity,
"");
}
lightfoot500 is offline  
Reply With Quote
Old 07-30-2009, 09:25 PM   #4
lightfoot500
Member
 
Join Date: Jul 2009
Posts: 43
Thanks: 4
Thanked 0 times in 0 posts
Default and the third and final bit of code.

sorry for having to do it this way, i dont know of a way to shorten it up..
// Condition set 2
if (Low[0] >= Bollinger(2, 20).Lower[0]
&& StochasticsFilled(
3, 9, 3).K[0] <= 25)
{
DrawArrowUp(
"My up arrow" + CurrentBar, false, 0, 0, Color.Lime);
EnterLong(DefaultQuantit
lightfoot500 is offline  
Reply With Quote
Old 07-31-2009, 04:58 AM   #5
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

lightfoot500, welcome to the forums!

So first step is to get the arrows drawn to verify your trading conditions, this can fixed with assigned a correct Y axis value to the DrawArrow call you use (you use 0 now, so that's why they do not show up at all) -

http://www.ninjatrader-support.com/H...gOnAChart.html
Last edited by NinjaTrader_Bertrand; 08-13-2009 at 04:59 AM.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 08-12-2009, 06:57 PM   #6
lightfoot500
Member
 
Join Date: Jul 2009
Posts: 43
Thanks: 4
Thanked 0 times in 0 posts
Default

thanks bertrand, drawing arrows is working now.
i would like to work with the slope of one of the indicators. lets say the lower bb. i got it to print an "arrow" for a slope <= n .
how can i specify the absolute value of n, or do i need two statements in there to work with the absolute value.
second, is there a way to just print the slope value on the chart in place of the arrow so i can see what the slope value should be?
my objective is to place markers where the slope of my indicator is flat or near flat. what i have now are markers at near flat or falling because i am using a statement saying mark where the slope is <= n ... hope this clarifys why i want to use the absolute value,.
thanks
Last edited by lightfoot500; 08-12-2009 at 07:07 PM. Reason: add more info
lightfoot500 is offline  
Reply With Quote
Old 08-13-2009, 05:04 AM   #7
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

For getting the absolute value, you can use Math.Abs().

For plotting the slope you could use this inside an indicator or in realtime for the strategy, please try this -

http://www.ninjatrader-support2.com/...ead.php?t=6651
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 08-13-2009, 01:31 PM   #8
lightfoot500
Member
 
Join Date: Jul 2009
Posts: 43
Thanks: 4
Thanked 0 times in 0 posts
Default

ok, using the strategy wizard, i put the slope value of .05 inside the math.abs (.5) like this and it gave error message.
what is the proper way to use that function?
lightfoot500 is offline  
Reply With Quote
Old 08-13-2009, 01:35 PM   #9
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 provide the error message.
NinjaTrader_Josh is offline  
Reply With Quote
Old 08-13-2009, 04:22 PM   #10
lightfoot500
Member
 
Join Date: Jul 2009
Posts: 43
Thanks: 4
Thanked 0 times in 0 posts
Default

well, the error message is property value is not valid.
but i realize now that using the absolute value will not work for what i want to do anyways.
what i want is to "put an arrow" at each bar for which the upper bollinger band, for example, is between -.5 and .5 ..

right now, i have an arrow for slope <= .5....
Last edited by lightfoot500; 08-13-2009 at 04:31 PM.
lightfoot500 is offline  
Reply With Quote
Old 08-13-2009, 04:25 PM   #11
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 provide the complete and exact text of the error along with the complete and exact line causing the error.
NinjaTrader_Josh is offline  
Reply With Quote
Old 08-13-2009, 04:48 PM   #12
lightfoot500
Member
 
Join Date: Jul 2009
Posts: 43
Thanks: 4
Thanked 0 times in 0 posts
Default

thanks,
but i realize now that using the absolute value will not work for what i want to do anyways.
what i want is to "put an arrow" at each bar for which the upper bollinger band, for example, is between -.5 and .5 ..
lightfoot500 is offline  
Reply With Quote
Old 08-14-2009, 03:21 AM   #13
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

lightfoot500, ok the Bollinger Band value compared to what? You could use for example the Close price and calculate the difference between it and the Bollinger Band and then DrawArrowUp / Dn if it's within your set limits as mentioned.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 08-16-2009, 03:29 PM   #14
lightfoot500
Member
 
Join Date: Jul 2009
Posts: 43
Thanks: 4
Thanked 0 times in 0 posts
Default

thanks, bertrand, i would be comparing the bb value to bb band value n periods before and looking at the slope.
lightfoot500 is offline  
Reply With Quote
Old 08-16-2009, 07:16 PM   #15
NinjaTrader_Ben
NinjaTrader Customer Service
 
NinjaTrader_Ben's Avatar
 
Join Date: May 2008
Location: Denver, CO
Posts: 3,157
Thanks: 0
Thanked 3 times in 3 posts
Default

Hello,

Give it a try using index values in []'s. Here is an example of getting the value of the upper band 3 bars ago:
upperValue = Bollinger(2, 20).Upper[3];
This link will help:
http://www.ninjatrader-support.com/H...Bollinger.html

Also, this link may help:
http://www.ninjatrader-support2.com/...ad.php?t=19176
NinjaTrader_Ben 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
Building historical database d.allen101 General Programming 1 06-17-2009 04:13 PM
building and sharing strategies namo10 Strategy Development 1 06-12-2009 05:03 AM
building a pc ckait Miscellaneous Support 1 12-05-2008 03:25 AM
Having Difficulty Building a Particular Strategy champagneninja ATM Strategies (Discretionary Trading) 3 09-06-2005 01:43 AM
"Mass" Strategy building QuahTrader ATM Strategies (Discretionary Trading) 3 01-17-2005 10:35 PM


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