![]() |
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Apr 2008
Posts: 310
Thanks: 0
Thanked 0 times in 0 posts
|
Hi
I developed a custom indicator, and I'd like to store the security High and Low for each period when the indicator is below 0. I'm not sure how I should code this. Any help appreciated Thank you |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: May 2008
Location: Denver, CO
Posts: 3,157
Thanks: 0
Thanked 3 times in 3 posts
|
Hello,
Thank you for your post. Try something like this: if(myIndicator[0] < 0) { myLow = MIN(Low, periodValue)[0]; } Here are links on MIN and MAX: http://www.ninjatrader-support.com/H...inimumMIN.html http://www.ninjatrader-support.com/H...aximumMAX.html If this is not what you want, please let me know.
Ben
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Apr 2008
Posts: 310
Thanks: 0
Thanked 0 times in 0 posts
|
Hi Ben,
Thank you for your reply, but it's not what I need. The problem in what you wrote if(myIndicator[0] < 0) { myLow = MIN(Low, periodValue)[0]; } is that periodValue depends on the indicator itself. Let me explain: let's say that my custom indicator turns negative [7] bars ago and then turns positive [3] bars ago. I need to calculate (and plot) the MIN and MAX of that range (between 7 and 3 bars ago). Your help is very much appreciated |
|
|
|
|
|
#4 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
double myMax = MAX(myIndicator, 4)[3];
where the value of 4 is the absolute value between 3 bars ago and 7 bars ago.
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Apr 2008
Posts: 310
Thanks: 0
Thanked 0 times in 0 posts
|
Thank you, Ray, but the example above was just an example.
I have an indicator "MyIndicator" which can swing above and below zero. I want to store (and plot) the security's MAX and MIN price in the interval when MyIndicator is negative. Something like: if (MyIndicator[1] >0 && MyIndicator[0] <0) { startdate } if (MyIndicator[1] <0 && MyIndicator[0] >0) { enddate } double MIN = MIN(Low, enddate - startdate)[0] double MAX = MAX(High, enddate - startdate)[0] Thank you for help |
|
|
|
|
|
#6 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
Not sure what your question is? Based on your last example it looks like you know what to do? Just subsitute startDate with startBar. You can assign it CurrentBar and thus you can then subtraced endBar from startBar to get the period length.
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Senior Member
Join Date: Apr 2008
Posts: 310
Thanks: 0
Thanked 0 times in 0 posts
|
Ray,
I did this but it doesn't work (it compiles, but it plots just once a day, and not correctly): if (MyIndicator[1] >0 && MyIndicator[0] <0) { startDateTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, Time[0].Hour, Time[0].Minute, 0); } if (MyIndicator[1] <0 && MyIndicator[0] >0) { endDateTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, startHour, startMinute, 0); } int startBarsAgo = GetBar(startDateTime); int endBarsAgo = GetBar(endDateTime); double highestHigh = MAX(High, startBarsAgo - endBarsAgo)[endBarsAgo]; double lowestLow = MIN(Low, startBarsAgo - endBarsAgo)[endBarsAgo]; HighestHigh.Set(highestHigh); LowestLow.Set(lowestLow); I understand you were suggesting a simpler way to go, but I didn't understand what you meant with "Just subsitute startDate with startBar. You can assign it CurrentBar and thus you can then subtraced endBar from startBar to get the period length." How can I do it? Thank you |
|
|
|
|
|
#8 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
You will have to debug your code to see where the logic fails.
What I suggested is that since you need to now the start bar and end bar, the property "CurrentBar" is an integer value for every bar on the chart. Once the conditino for the starting bar is met, record the value of CurrentBar since that represents a unique value for when this condition was met. Same for the end bar. Now that you have marked the values, you now the bar range. This is the period value that you wanted...
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#9 |
|
Senior Member
Join Date: Apr 2008
Posts: 310
Thanks: 0
Thanked 0 times in 0 posts
|
Thank you, Ray. I did as you suggested and it works (and it was much easier to do!).
Unfortunately, I don't get two horizontal lines each time the conditions are met, but something resembling two bands, changing almost at each bar. How can I edit the code to require that once the local high and low are plotted, they will stay the same in the following bars until the conditions for a new high and low are met? Thank you |
|
|
|
|
|
#10 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
On each call to OnBarUpdate() always set the same plot value.
Ray
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Question about HIGHS | miketpcc2 | General Programming | 2 | 07-28-2008 08:21 AM |
| Backtest results change depending on the indicators plotted | ssierra | Strategy Analyzer | 9 | 05-21-2008 08:24 AM |
| Retrieving the High/Lows of a Previous Move | TAJTrades | Indicator Development | 3 | 12-10-2007 11:49 PM |
| New highs/lows | qitrader | Indicator Development | 2 | 10-03-2007 06:52 AM |
| highs and lows marker | tradingkevin | Suggestions And Feedback | 2 | 05-10-2007 06:55 PM |