NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Indicator Development

Indicator Development Support for the development of custom indicators using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 04-06-2012, 03:21 PM   #1
jmflukeiii
Senior Member
 
Join Date: Dec 2011
Posts: 190
Thanks: 16
Thanked 6 times in 6 posts
Default Using Price above Last Swing High/Low

Could anyone help me out with a simple line of code to determine whether the the current price is above the last swing high (as in the Ninja indicator Swing with default 5 setting)? Thank you

ACtually let me clarify:

Basically I"m looking to do something if I know that within the last 10 bars, price has crossed up over the most recent swing high. I'm also looking to do something else if I know that within the last 10 bars, price has crossed below the last swing low. I'm looking to do a third thing when over the last 10 bars, price has not moved past the last swing high, or the last swing low.

For example, price crosses the last swing high and Ninja will execute X - I want x to remain in effect until another Swing high starts printing (which requires a retracement). If during this retracement, price continues to retrace and not cross this swing high for 10 bars, I want Ninja to do something else Y and no longer do X. If during the course of that retracement, it happens to create a Swing Low, and then it happens to cross that Swing low, I want Ninja to do Z and to no longer do Y.

Is this possible? Should I be using a for loop, or will if statements work?
Last edited by jmflukeiii; 04-06-2012 at 03:59 PM.
jmflukeiii is offline  
Reply With Quote
Old 04-06-2012, 04:51 PM   #2
jmflukeiii
Senior Member
 
Join Date: Dec 2011
Posts: 190
Thanks: 16
Thanked 6 times in 6 posts
Default

Basically - How do I say "if Price hasn't crossed either a swing high or a swing low for 10 bars, do Y"
jmflukeiii is offline  
Reply With Quote
Old 04-07-2012, 07:36 AM   #3
koganam
Senior Member
 
Join Date: Feb 2008
Location: Durham, North Carolina, USA
Posts: 3,199
Thanks: 24
Thanked 1,225 times in 996 posts
Send a message via Skype™ to koganam
Default

Quote:
Originally Posted by jmflukeiii View Post
Basically - How do I say "if Price hasn't crossed either a swing high or a swing low for 10 bars, do Y"
Requirement is not very clear. You mean that you want to isolate a situation where in the last 10 bars, price has not broken out of the last swing low or swing high, no matter how long ago those swings occurred? Or do you mean something else?
koganam is offline  
Reply With Quote
Old 04-07-2012, 08:29 AM   #4
jmflukeiii
Senior Member
 
Join Date: Dec 2011
Posts: 190
Thanks: 16
Thanked 6 times in 6 posts
Default

Thank you for the reply, here is the sample script as is:

The problem here is that the outline turns blue only when the price is above the last swing high. However, by passing the swing high, the trend is deemed to be "up" and thus I want blue candles (colored for down, empty for up) until that "trend" is no longer moving strongly.... bear with me....
price crosses the swing, candles turn blue.
Price goes up for however long, and then a new swing high value forms during a retracement.
IF this retracement lasts 10 bars or more (meaning it does NOT cross the new swing high value), I want the candles to no longer be blue but turn yellow instead.

I've tried cross above also because the other issue with the way its written below is that if price crosses the swing high, but then pulls back below that swing high, it changes back colors. But the problem with cross above is it just looks back a certain number of bars and once that fixed period is over, it stops doing the condition - i.e. so price could cross the swing high and go straight up for 40 bars, but because the lookback on the cross above is only 10, it stops printing blue after 10 bars. Let me know if this question is still unclear

if (Close[0]<Swing(5).SwingLow[0])
{

if (Close[0]<Open[0])
{
CandleOutlineColor = candleOutlineDown;
BarColor = Color.Red;

}
else if (Close[0]>Open[0])
{
CandleOutlineColor = candleOutlineDown;
BarColor = Color.Transparent;
}

}
else if (Close[0]>Swing(5).SwingHigh[0])

{

if (Close[0]<Open[0])
{
CandleOutlineColor = candleOutlineUp;
BarColor = Color.DodgerBlue;

}
else if (Close[0]>Open[0])
{
CandleOutlineColor = candleOutlineUp;
BarColor = Color.Transparent;
}
}
else
{
if (Close[0]<Open[0])
{
CandleOutlineColor = candleOutlineDoji;
BarColor = Color.Yellow;

}
else if (Close[0]>Open[0])
{
CandleOutlineColor = candleOutlineDoji;
BarColor = Color.Transparent;
}
}
}
jmflukeiii is offline  
Reply With Quote
Old 04-07-2012, 09:03 AM   #5
jmflukeiii
Senior Member
 
Join Date: Dec 2011
Posts: 190
Thanks: 16
Thanked 6 times in 6 posts
Default

This is getting closer, but still not quite right.... This code snippet stops printing blue bars 5 bars after the second swing high value is created.... is the only way I can do that is if I have the strength be 10??

{
if (CrossAbove(EMA(1),Swing(5).SwingHigh[0],Swing(5).SwingHighBar(0,1,10)))
{
if (Close[0]<Open[0])
{
CandleOutlineColor = candleOutlineUp;
BarColor = Color.DodgerBlue;

}
else if (Close[0]>Open[0])
{
CandleOutlineColor = candleOutlineUp;
BarColor = Color.Transparent;
}
}
else if (CrossBelow(EMA(1),Swing(5).SwingLow[0],Swing(5).SwingLowBar(0,1,10)))
{
if (Close[0]<Open[0])
{
CandleOutlineColor = candleOutlineDown;
BarColor = Color.Red;

}
else if (Close[0]>Open[0])
{
CandleOutlineColor = candleOutlineDown;
BarColor = Color.Transparent;
}
}
}
Last edited by jmflukeiii; 04-07-2012 at 09:07 AM.
jmflukeiii is offline  
Reply With Quote
Old 04-07-2012, 03:48 PM   #6
koganam
Senior Member
 
Join Date: Feb 2008
Location: Durham, North Carolina, USA
Posts: 3,199
Thanks: 24
Thanked 1,225 times in 996 posts
Send a message via Skype™ to koganam
Default

There is still quite a bit that you have not accounted for, which means that it is still not quite clear.

Taking the long side only as an example, here is what might happen. How is your coloring scheme done for each situation?

Close is above last swing high (how many bars ago qualify it as a market?)

Then:
  • Price consolidates at the high, closing above and below it, but not creating a Swing point.
  • Price immediately retreats and keeps closing below the Swing high, but does not go below the Swing low, or form another Swing Low.
  • Price runs away in a breakout (this is the easy, obvious one).
koganam is offline  
Reply With Quote
Old 04-13-2012, 11:55 AM   #7
BankRobber
Member
 
Join Date: Aug 2011
Location: New York
Posts: 35
Thanks: 6
Thanked 2 times in 2 posts
Default

Here is an indicator that has been written to be used with Strategy Wizard - Ultimate Swing High Low - NinjaTrader Indicator
BankRobber is offline  
Reply With Quote
Old 04-14-2012, 08:08 AM   #8
jmflukeiii
Senior Member
 
Join Date: Dec 2011
Posts: 190
Thanks: 16
Thanked 6 times in 6 posts
Default

Quote:
Originally Posted by koganam View Post
There is still quite a bit that you have not accounted for, which means that it is still not quite clear.

Taking the long side only as an example, here is what might happen. How is your coloring scheme done for each situation?

Close is above last swing high (how many bars ago qualify it as a market?)

Then:
  • Price consolidates at the high, closing above and below it, but not creating a Swing point.
  • Price immediately retreats and keeps closing below the Swing high, but does not go below the Swing low, or form another Swing Low.
  • Price runs away in a breakout (this is the easy, obvious one).
The answer is the same, as soon as the price closes above the swing high, it would turn "blue". If it dances around for 10 bars and doesn't do anything after that "it turns yellow". But it remains blue until 10 bars of non progression have occurred.
jmflukeiii is offline  
Reply With Quote
Old 04-15-2012, 07:23 PM   #9
jmflukeiii
Senior Member
 
Join Date: Dec 2011
Posts: 190
Thanks: 16
Thanked 6 times in 6 posts
Default Next question

I solved my issue for the most part and the indicator works.

However, I want to change the outline color of the current bar in progress only while not affecting all bars that have happened. What is the most efficient way of doing that?
jmflukeiii is offline  
Reply With Quote
Old 04-16-2012, 05:34 AM   #10
koganam
Senior Member
 
Join Date: Feb 2008
Location: Durham, North Carolina, USA
Posts: 3,199
Thanks: 24
Thanked 1,225 times in 996 posts
Send a message via Skype™ to koganam
Default

Quote:
Originally Posted by jmflukeiii View Post
I solved my issue for the most part and the indicator works.

However, I want to change the outline color of the current bar in progress only while not affecting all bars that have happened. What is the most efficient way of doing that?
Change the BarColor.

ref: http://www.ninjatrader.com/support/h...l?barcolor.htm
koganam is offline  
Reply With Quote
Old 04-16-2012, 05:49 AM   #11
jmflukeiii
Senior Member
 
Join Date: Dec 2011
Posts: 190
Thanks: 16
Thanked 6 times in 6 posts
Default

Thanks Kogonam, I'm going to change CandleOutlineColor.

My question was more referring to how do I affect only the current bar's (the bar that is forming) outline while allowing the rest of the bars to be printed with colors I have already put together through the indicator?
jmflukeiii is offline  
Reply With Quote
Old 04-16-2012, 07:22 PM   #12
koganam
Senior Member
 
Join Date: Feb 2008
Location: Durham, North Carolina, USA
Posts: 3,199
Thanks: 24
Thanked 1,225 times in 996 posts
Send a message via Skype™ to koganam
Default

Quote:
Originally Posted by jmflukeiii View Post
Thanks Kogonam, I'm going to change CandleOutlineColor.

My question was more referring to how do I affect only the current bar's (the bar that is forming) outline while allowing the rest of the bars to be printed with colors I have already put together through the indicator?
No difference. Both BarColor and CandleOutlineColor refer to the specific bar on which they are invoked. That is how we can duplicate the custom bar coloring of TradeStation or Telechart.
koganam 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
Swing High, Swing Low rzeemeijer Strategy Development 1 10-24-2011 09:19 AM
Filtering a swing high or low Baseheadz Strategy Development 1 06-16-2011 02:21 AM
strategy that shows broken Swing high and Swing low? MoreYummy Strategy Development 1 06-06-2010 10:16 PM
Swing High/low nigeleyre Strategy Development 1 09-06-2009 12:38 PM
Swing high low indicator winJR NinjaScript File Sharing Discussion 1 02-06-2008 12:39 AM


All times are GMT -6. The time now is 06:16 PM.