Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Converting Tradingview to Ninjascript, can someone help me?
Collapse
X
-
Also noticing from your screenshot examples, I had not taken into account if looking back to find a swing high, if that swing high was already broken.
if (Position.MarketPosition == MarketPosition.Long)
{
for (int i = 1; i <5; i++)
{
if (High[i] > High[i-1] && High[i] > High[i+1] && High[i] > HighestBar(High, i)
swingHigh = High[i] + TickOffset * TickSize; // Where default TickOffset = 1;
break;
}
}
-
Yes the 5th candle was a swing high but we didn’t broke it, so we are looking for a formation of an another swing, the new one formed was lower than the previous one, so we look to break the new one.
Leave a comment:
-
Ok. I guess I'm not understanding the logic of what you consider a swing high. In the first picture, you mention that the 5th candle does not have a swing. A few candles before it there was a doji swing high, are you not counting this because it was already broken by that fifth candle? You also pointed out that a later candle was a valid swing, does this mean that original 5th candle was somehow not a valid swing? Or it was, but because a new one popped up, you're just counting that one now?
Leave a comment:
-
The strategy is from Steven primo: we need to have 5 closes above the upper Bollinger band, then we look for the most recent swing high, the swing high can be after 5 or more candles for example, we enter long when we break it if we didn’t close again inside the bands, cycle rest when we close inside the band and we look again for 5 closes and swing high break again
Leave a comment:
-
Ok. so it's not the most recent of the swing highs. Are you looking for the highest swing high out of the 5 closes? Also, when you say 5 closes, assuming the current bar is [0], you are looking at High[1] - High[5]?
I suppose you can take out the break and it will keep searching and if there is another swing high, it will update swingHigh to the next one found. If nothing is found the loop will end and swingHigh will remain the last value it was assigned. On the next bar, it will search again using the most recent 5 closes.
Leave a comment:
-
- break;
- Once a swing high is found, the loop is exited immediately using the break statement. This means that the code will only find the first swing high within the last 4 bars and then stop searching.
Leave a comment:
- break;
-
Hello,
If you want to track Swing highs and lows, you can use the Swing indicator:Action:- If the price breaks the last swing high by at least one tick (without waiting for the candle to close), display an up arrow for a Long signal.
- If the price breaks the last swing low by at least one tick, display a down arrow for a Short signal.
High Value
Swing(int strength).SwingHigh[int barsAgo]
Swing(ISeries<double> input, int strength).SwingHigh[int barsAgo]
Low Value
Swing(int strength).SwingLow[int barsAgo]
Swing(ISeries<double> input, int strength).SwingLow[int barsAgo]
Close[0] will be the current price of the currently forming bar if you are using Calculate.OnPriceChange or .OnEachTick. So to compare the price to the Swing + 1 tick, you could do something like:
if (Close[0] >= mySwingHigh + (1*TickSize)) // do something
Then, to draw up or down arrows, you can use the following Draw methods.
Please let us know if you have any further specific questions.Last edited by NinjaTrader_Gaby; 02-17-2025, 12:28 PM.
Leave a comment:
-
Off the top of my head, this is the logic that I'm thinking of when looking for swing highs. You would change it to Short and swap High with Low for shorts....Do you think that would work?
if (Position.MarketPosition == MarketPosition.Long)
{
for (int i = 1; i <5; i++)
{
if (High[i] > High[i-1] && High[i] > High[i+1])
swingHigh = High[i] + TickOffset * TickSize; // Where default TickOffset = 1;
break;
}
}
Leave a comment:
-
Here is the summary of Strategy if it can help:
1. Strategy Settings- Overlay: The strategy is plotted on the main chart.
- Default Quantity Type: Uses 100% of the available equity for each trade.
- Process Orders on Close: Orders are executed at the close of the candle.
- Max Labels Count: Limits the number of labels on the chart to 500.
2. Inputs
Bollinger Bands Settings- Price Source: The closing price is used as the default source for Bollinger Bands calculations.
- Bollinger Length: The length of the Bollinger Bands (default: 20).
- Standard Deviation Multiplier: The multiplier for the standard deviation (default: 0.382).
- Order Direction: Allows the user to choose between long, short, or both directions (default: long).
- Use Trailing Stop: Enables or disables trailing stop functionality (default: false).
- Consecutive Closes for Setup: The number of consecutive closes required for a setup (default: 5).
- Extension (%): The percentage extension for calculating the target price (default: 100%).
3. Bollinger Bands Calculation- The Bollinger Bands are calculated using the ta.bb function:
- Middle Band: Exponential moving average (EMA) of the log-transformed price.
- Upper Band: Middle band + (standard deviation × multiplier).
- Lower Band: Middle band - (standard deviation × multiplier).
- The bands are then transformed back using math.exp to plot on the chart.
4. Setup Conditions
Long Setup- Condition: The close price is above the upper Bollinger Band.
- Consecutive Closes: The close must remain above the upper band for a specified number of consecutive candles (consecutiveCloses).
- Pivot High: A pivot high must occur within the range of the setup.
- Condition: The close price is below the lower Bollinger Band.
- Consecutive Closes: The close must remain below the lower band for a specified number of consecutive candles (consecutiveCloses).
- Pivot Low: A pivot low must occur within the range of the setup.
5. Entry Conditions
Long Entry- Condition: The setup for a long trade is confirmed (canBuy).
- Entry Price: The pivot high price + 1 tick.
- Stop Loss: The pivot low price.
- Target Price: Calculated as the entry price + (extension × (entry price - stop loss)).
- Condition: The setup for a short trade is confirmed (canSell).
- Entry Price: The pivot low price - 1 tick.
- Stop Loss: The pivot high price.
- Target Price: Calculated as the entry price - (extension × (stop loss - entry price)).
6. Exit Conditions- Stop Loss: The stop loss is set at the pivot low for long trades and the pivot high for short trades.
- Target Price: The target price is calculated based on the extension percentage.
- Trailing Stop: If enabled, the stop loss trails the price for long trades (moves up) or for short trades (moves down).
7. Order Management- Entry Orders:
- Long orders are placed if the long setup conditions are met.
- Short orders are placed if the short setup conditions are met.
- Exit Orders:
- Exit orders are placed with a stop loss and target price.
- If a trailing stop is enabled, the stop loss is updated dynamically.
- Cancel Orders: If no setup is confirmed, pending orders are canceled.
8. Plotting- Bollinger Bands: The upper, middle, and lower bands are plotted on the chart.
- Stop Loss and Target: The stop loss and target levels are plotted for visual reference.
Summary of Key Conditions- Long Trade:
- Close price > Upper Bollinger Band for consecutiveCloses candles.
- Pivot high within the setup range.
- Entry at pivot high + 1 tick.
- Stop loss at pivot low.
- Target price calculated using the extension percentage.
- Short Trade:
- Close price < Lower Bollinger Band for consecutiveCloses candles.
- Pivot low within the setup range.
- Entry at pivot low - 1 tick.
- Stop loss at pivot high.
- Target price calculated using the extension percentage.
- Trailing Stop:
- If enabled, the stop loss trails the price for open trades.
- Order Direction:
- The strategy can be configured to trade long, short, or both directions.
Leave a comment:
-
Yes, that’s true, after 5 closes I start looking for the most recent high to break if we are long and the most recent low if we are short.
Leave a comment:
-
Ok. So you would be looking at it in the way I mentioned then. Does it just need to break the most recent swing high? The way I'm thinking about it, you could either start from the 5th candle and check if there are any highs and lows and work back to the current candle, or you could do the reverse and get the most recent one.
Leave a comment:
-
There are two ways to trade: Long and Short.
For Long we need a swing high to be broken: formed by 3 candles, the one in the middle have a high higher than the 2 others.
For Short we need a swing low
Leave a comment:
-
What are you considering a swing high? Is it where a potential bar's high (I'll call it 'x') is higher than the both the previous candle and the proceeding candle?
(High[x] > High[x-1] && High[x] > High[x+1])?
If you are in a downtrend where the top is a pivot and it creates a pullback for another pivot, and both are within 5 candles, which would you consider the swing high? The higher of the two? I'm guessing you'll need a double value to keep track of the level you need to keep track so that if Close[0] >= level (in a long scenario) then that level has been broken.
Leave a comment:
-
Can you help
What I’ve Accomplished So Far:- Created a custom Bollinger Bands indicator.
- Implemented a feature to display the number 5 after 5 consecutive closes occur either above or below the bands.
- Added an alert system to notify when this condition is met.
- Configured the system to display all swing points with a strength of 1.
Now i need to code this:
Condition:
After observing 5 consecutive candle closes, identify the last swing high for a Long position and the last swing low for a Short position.
Action:- If the price breaks the last swing high by at least one tick (without waiting for the candle to close), display an up arrow for a Long signal.
- If the price breaks the last swing low by at least one tick, display a down arrow for a Short signal.
Reset Condition:
If the price closes inside the bands before breaking the last swing high or low, the counter resets, and the last swing high/low is no longer valid. In this case, wait for the next cycle of 5 consecutive closes to reassess the condition.
Last edited by Babbou72; 02-17-2025, 10:08 AM.
Leave a comment:
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by DannyP96, 05-18-2026, 02:38 PM
|
1 response
93 views
0 likes
|
Last Post
|
||
|
Started by CarlTrading, 05-11-2026, 05:56 AM
|
0 responses
144 views
0 likes
|
Last Post
by CarlTrading
05-11-2026, 05:56 AM
|
||
|
Started by CarlTrading, 05-10-2026, 08:12 PM
|
0 responses
83 views
0 likes
|
Last Post
by CarlTrading
05-10-2026, 08:12 PM
|
||
|
Started by Hwop38, 05-04-2026, 07:02 PM
|
0 responses
257 views
0 likes
|
Last Post
by Hwop38
05-04-2026, 07:02 PM
|
||
|
Started by Mindset, 04-21-2026, 06:46 AM
|
0 responses
337 views
0 likes
|
Last Post
by Mindset
04-21-2026, 06:46 AM
|

Leave a comment: