NinjaTrader Support Forum  

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 08-13-2008, 09:36 AM   #1
stefy
Senior Member
 
Join Date: Apr 2008
Posts: 310
Thanks: 0
Thanked 0 times in 0 posts
Question Taking Highs and Lows depending on an indicator

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
stefy is offline  
Reply With Quote
Old 08-13-2008, 10:56 AM   #2
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,

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.
NinjaTrader_Ben is offline  
Reply With Quote
Old 08-14-2008, 06:38 AM   #3
stefy
Senior Member
 
Join Date: Apr 2008
Posts: 310
Thanks: 0
Thanked 0 times in 0 posts
Default

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
stefy is offline  
Reply With Quote
Old 08-14-2008, 07:20 AM   #4
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

double myMax = MAX(myIndicator, 4)[3];

where the value of 4 is the absolute value between 3 bars ago and 7 bars ago.
NinjaTrader_Ray is offline  
Reply With Quote
Old 08-14-2008, 07:33 AM   #5
stefy
Senior Member
 
Join Date: Apr 2008
Posts: 310
Thanks: 0
Thanked 0 times in 0 posts
Default

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
stefy is offline  
Reply With Quote
Old 08-14-2008, 07:49 AM   #6
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

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.
NinjaTrader_Ray is offline  
Reply With Quote
Old 08-14-2008, 09:55 AM   #7
stefy
Senior Member
 
Join Date: Apr 2008
Posts: 310
Thanks: 0
Thanked 0 times in 0 posts
Default

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
stefy is offline  
Reply With Quote
Old 08-14-2008, 10:20 AM   #8
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

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...
NinjaTrader_Ray is offline  
Reply With Quote
Old 08-14-2008, 11:30 AM   #9
stefy
Senior Member
 
Join Date: Apr 2008
Posts: 310
Thanks: 0
Thanked 0 times in 0 posts
Default

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
stefy is offline  
Reply With Quote
Old 08-14-2008, 12:27 PM   #10
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

On each call to OnBarUpdate() always set the same plot value.
NinjaTrader_Ray 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
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


All times are GMT -6. The time now is 10:38 AM.