![]() |
|
|||||||
| Indicator Development Support for the development of custom indicators using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Dec 2011
Posts: 190
Thanks: 16
Thanked 6 times in 6 posts
|
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.
|
|
|
|
|
|
#2 |
|
Senior Member
Join Date: Dec 2011
Posts: 190
Thanks: 16
Thanked 6 times in 6 posts
|
Basically - How do I say "if Price hasn't crossed either a swing high or a swing low for 10 bars, do Y"
|
|
|
|
|
|
#3 |
|
Senior Member
|
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?
|
|
|
|
|
|
#4 |
|
Senior Member
Join Date: Dec 2011
Posts: 190
Thanks: 16
Thanked 6 times in 6 posts
|
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; } } } |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Dec 2011
Posts: 190
Thanks: 16
Thanked 6 times in 6 posts
|
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.
|
|
|
|
|
|
#6 |
|
Senior Member
|
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:
|
|
|
|
|
|
#7 |
|
Member
Join Date: Aug 2011
Location: New York
Posts: 35
Thanks: 6
Thanked 2 times in 2 posts
|
Here is an indicator that has been written to be used with Strategy Wizard - Ultimate Swing High Low - NinjaTrader Indicator
|
|
|
|
|
|
#8 | |
|
Senior Member
Join Date: Dec 2011
Posts: 190
Thanks: 16
Thanked 6 times in 6 posts
|
Quote:
|
|
|
|
|
|
|
#9 |
|
Senior Member
Join Date: Dec 2011
Posts: 190
Thanks: 16
Thanked 6 times in 6 posts
|
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? |
|
|
|
|
|
#10 | |
|
Senior Member
|
Quote:
ref: http://www.ninjatrader.com/support/h...l?barcolor.htm |
|
|
|
|
|
|
#11 |
|
Senior Member
Join Date: Dec 2011
Posts: 190
Thanks: 16
Thanked 6 times in 6 posts
|
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? |
|
|
|
|
|
#12 | |
|
Senior Member
|
Quote:
|
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |