![]() |
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 |
|
Member
Join Date: Jul 2009
Posts: 43
Thanks: 4
Thanked 0 times in 0 posts
|
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. |
|
|
|
|
|
#2 |
|
Member
Join Date: Jul 2009
Posts: 43
Thanks: 4
Thanked 0 times in 0 posts
|
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; } |
|
|
|
|
|
#3 |
|
Member
Join Date: Jul 2009
Posts: 43
Thanks: 4
Thanked 0 times in 0 posts
|
///<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, ""); } |
|
|
|
|
|
#4 |
|
Member
Join Date: Jul 2009
Posts: 43
Thanks: 4
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#5 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
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
Bertrand
NinjaTrader Customer Service
Last edited by NinjaTrader_Bertrand; 08-13-2009 at 04:59 AM.
|
|
|
|
|
|
#6 |
|
Member
Join Date: Jul 2009
Posts: 43
Thanks: 4
Thanked 0 times in 0 posts
|
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
|
|
|
|
|
|
#7 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
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
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#8 |
|
Member
Join Date: Jul 2009
Posts: 43
Thanks: 4
Thanked 0 times in 0 posts
|
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? |
|
|
|
|
|
#9 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
Please provide the error message.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#10 |
|
Member
Join Date: Jul 2009
Posts: 43
Thanks: 4
Thanked 0 times in 0 posts
|
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.
|
|
|
|
|
|
#11 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
Please provide the complete and exact text of the error along with the complete and exact line causing the error.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#12 |
|
Member
Join Date: Jul 2009
Posts: 43
Thanks: 4
Thanked 0 times in 0 posts
|
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 .. |
|
|
|
|
|
#13 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
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.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#14 |
|
Member
Join Date: Jul 2009
Posts: 43
Thanks: 4
Thanked 0 times in 0 posts
|
thanks, bertrand, i would be comparing the bb value to bb band value n periods before and looking at the slope.
|
|
|
|
|
|
#15 |
|
NinjaTrader Customer Service
Join Date: May 2008
Location: Denver, CO
Posts: 3,157
Thanks: 0
Thanked 3 times in 3 posts
|
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
Ben
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |