Shared conversation on NexusTrade
PineScript Strategy: Consecutive Green-Red Candles Long Strategy
Conversion of a TradingView indicator to a PineScript v6 strategy that goes long based on consecutive green and red candle patterns, with a 10% price drop exit condition.
Aurora: Hello. Do you need help finding some new stocks for your watchlist? Maybe we can find stocks based on their Volume or Volume?
User: what are the best trading times for momentum daytrading, in New York time and Lisbon, Portugal time.
Aurora: The best trading times for momentum day trading generally align with periods of high market volatility and volume, which often occur during the market open and close. For the New York Stock Exchange (NYSE), the most active trading hours are typically: - 9:30 AM to 11:30 AM EST (market open period) - 3:00 PM to 4:00 PM EST (market close period) In Lisbon, Portugal, which is usually 5 hours ahead of New York (Eastern Time) during Eastern Daylight Time (EDT), these times correspond to: - 2:30 PM to 4:30 PM WEST (market open period) - 8:00 PM to 9:00 PM WEST (market close period) These periods tend to have the highest liquidity and price movements, which are ideal for momentum day trading strategies. However, individual preferences and specific stock behaviors may vary, so it's good to backtest your strategies during these times using NexusTrade or NextTrade platforms.
User: You are a professional PineScript v6 developer. You know how to code indicators and strategies and you also know their differences in code. I need your help to turn a TradingView indicator into a strategy please. When to buy and when to sell: - Go long when price closes above the upper Bollinger Band. - Close long when price closed below the lower Bollinger Band. Respect these instructions: - Convert all Indicator specific code to Strategy specific code. Don't use any code that a TradingView Strategy won't support. Especially timeframes and gaps. Define those in code so they are semantically the same as before. - Preserve the timeframe logic if there is one. Fill gaps. - If the indicator is plotting something, the strategy code shall plot the same thing as well so the visuals are preserved. - Don't trigger a short. Simply go Long and Flat. - Always use 100% of capital. - Set commission to 0.1%. - Set slippage to 0. - strategy.commission.percent and strategy.slippage don't exist in PineScript. Please avoid this mistake. Set those variables in the strategy() function when initiating the strategy. - When initiating the strategy() function, don't use line breaks as this will cause a c…
Aurora: ```pinescript //@version=5 strategy("Demo GPT - Bollinger Bands Long Only Strategy", overlay=true, commission_type=strategy.commission.percent, commission_value=0.1, slippage=0) // Inputs for start and end date filters startYear = input.int(2018, "Start Year", minval=1970, maxval=2069) startMonth = input.int(1, "Start Month", minval=1, maxval=12) startDay = input.int(1, "Start Day", minval=1, maxval=31) endYear = input.int(2069, "End Year", minval=1970, maxval=2069) endMonth = input.int(12, "End Month", minval=1, maxval=12) endDay = input.int(31, "End Day", minval=1, maxval=31) // Convert input dates to timestamps startTime = timestamp(startYear, startMonth, startDay, 0, 0) endTime = timestamp(endYear, endMonth, endDay, 23, 59) // Time filter: only trade within the selected date range inDateRange = (time >= startTime) and (time <= endTime) // Bollinger Bands parameters length = 20 src = close mult = 2.0 basis = ta.sma(src, length) dev = mult * ta.stdev(src, length) upperBB = basis + dev lowerBB = basis - dev // Plot Bollinger Bands and basis for visual reference plot(basis, color=color.orange, title="Basis (SMA 20)") p1 = plot(upperBB, color=color.blue, title="Upper Bollinger Band…
User: New script:
Aurora: pinescript //@version=5 strategy("Demo GPT - Bollinger Bands Long Only Strategy", overlay=true, commission_type=strategy.commission.percent, commission_value=0.1, slippage=0) // Inputs for start and end date filters startYear = input.int(2018, "Start Year", minval=1970, maxval=2069) startMonth = input.int(1, "Start Month", minval=1, maxval=12) startDay = input.int(1, "Start Day", minval=1, maxval=31) endYear = input.int(2069, "End Year", minval=1970, maxval=2069) endMonth = input.int(12, "End Month", minval=1, maxval=12) endDay = input.int(31, "End Day", minval=1, maxval=31) // Convert input dates to timestamps startTime = timestamp(startYear, startMonth, startDay, 0, 0) endTime = timestamp(endYear, endMonth, endDay, 23, 59) // Time filter: only trade within the selected date range inDateRange = (time >= startTime) and (time <= endTime) // Bollinger Bands parameters length = 20 src = close mult = 2.0 basis = ta.sma(src, length) dev = mult * ta.stdev(src, length) upperBB = basis + dev lowerBB = basis - dev // Plot Bollinger Bands and basis for visual reference plot(basis, color=color.orange, title="Basis (SMA 20)") p1 = plot(upperBB, color=color.blue, title="Upper Bollinger Band")…
User: When to buy and when to sell: - Go Long, when there there are 3 consecutive green candles, followed by 1, max 3 red candles, followed by 1 - 3 green candles. The dip of the red candles can be max 50% of the gain of the 3 previous green candles. And the latest green bar must be equal or higher then the high of the former red candles. Don't use any abbreviations.
Aurora: **Description:** This strategy aims to enter a long position based on a specific candle pattern signaling a potential continuation of upward momentum after a minor pullback. The buy condition requires observing three consecutive green candles (each closing higher than the previous), followed by one to three red candles (each closing lower than the previous) that form a dip no deeper than fifty percent of the total gain from the initial three green candles. After this dip, the strategy looks for one to three green candles where the latest green candle closes at or above the highest point reached during the red candle dip. This pattern suggests a healthy retracement and a resumption of upward price movement. The strategy goes long when this pattern is detected. The sell condition is not specified, so the strategy remains long until manually closed or another exit condition is implemented. **Strategy:** - Buy 100 percent of buying power in the asset when: - There are three consecutive green candles (each candle's close is higher than the previous candle's close), - Followed by one to three consecutive red candles (each candle's close is lower than the previous candle's close), - The…
User: You are a professional PineScript v6 developer, your code is perfect in v6 format. You describe all your code. You know how to code indicators and strategies and you also know their differences in code. I need your help to turn a TradingView indicator into a strategy please. When to buy and when to sell: - Go Long, when there there are 3 consecutive green candles, followed by 1, max 3 red candles, followed by 1 - 3 green candles. The dip of the red candles can be max 50% of the gain of the 3 previous green candles. And the latest green bar must be equal or higher then the high of the former red candles. Don't use any abbreviations. - Go Short, when a red candles low is 10% of the cumulative rise of the green candles that trigger the Long Respect these instructions: - Convert all Indicator specific code to Strategy specific code. Don't use any code that a TradingView Strategy won't support. Especially timeframes and gaps. Define those in code so they are semantically the same as before. - Preserve the timeframe logic if there is one. Fill gaps. - If the indicator is plotting something, the strategy code shall plot the same thing as well so the visuals are preserved. - Don't trigger…
Aurora: ```pinescript //@version=5 strategy("Demo GPT - Consecutive Candles Dip Rebound Long Strategy", overlay=true, commission_type=strategy.commission.percent, commission_value=0.1, slippage=0) // Inputs for start and end date filters startYear = input.int(2018, "Start Year", minval=1970, maxval=2069) startMonth = input.int(1, "Start Month", minval=1, maxval=12) startDay = input.int(1, "Start Day", minval=1, maxval=31) endYear = input.int(2069, "End Year", minval=1970, maxval=2069) endMonth = input.int(12, "End Month", minval=1, maxval=12) endDay = input.int(31, "End Day", minval=1, maxval=31) // Convert input dates to timestamps startTime = timestamp(startYear, startMonth, startDay, 0, 0) endTime = timestamp(endYear, endMonth, endDay, 23, 59) // Time filter: only trade within the selected date range inDateRange = (time >= startTime) and (time <= endTime) // Helper function to check if candle is green (close > previous close) isGreen(idx) => close[idx] > close[idx + 1] // Helper function to check if candle is red (close < previous close) isRed(idx) => close[idx] < close[idx + 1] // Find 3 consecutive green candles starting at current bar offset 3 (to look back) threeGreen = isGreen(3)…
User: Write in pinescript version 6! The 'strategy.entry' function does not have an argument with the name 'qty_percent'
Aurora: ```pinescript //@version=6 strategy("Demo GPT - Consecutive Candles Dip Rebound Long Strategy", overlay=true, commission_type=strategy.commission.percent, commission_value=0.1, slippage=0) // Inputs for start and end date filters startYear = input.int(2018, "Start Year", minval=1970, maxval=2069) startMonth = input.int(1, "Start Month", minval=1, maxval=12) startDay = input.int(1, "Start Day", minval=1, maxval=31) endYear = input.int(2069, "End Year", minval=1970, maxval=2069) endMonth = input.int(12, "End Month", minval=1, maxval=12) endDay = input.int(31, "End Day", minval=1, maxval=31) // Convert input dates to timestamps startTime = timestamp(startYear, startMonth, startDay, 0, 0) endTime = timestamp(endYear, endMonth, endDay, 23, 59) // Time filter: only trade within the selected date range inDateRange = (time >= startTime) and (time <= endTime) // Helper functions isGreen(idx) => close[idx] > close[idx + 1] isRed(idx) => close[idx] < close[idx + 1] // Check for 3 consecutive green candles starting 3 bars ago threeGreen = isGreen(3) and isGreen(2) and isGreen(1) // Calculate cumulative gain of these 3 green candles precisely greenGainPrecise = (close[3] - close[4]) + (close[2…
User: You are a professional PineScript v6 developer, you code in pinescript v6 format. You describe all your code. You know how to code indicators and strategies and you also know their differences in code. I need your help to turn a TradingView indicator into a strategy please. When to buy and when to sell: - Go Long, when there there are 3 consecutive green candles, followed by 1, max 3 red candles, followed by 1 - 3 green candles. The dip of the red candles can be max 50% of the gain of the 3 previous green candles. And the latest green bar must be equal or higher then the high of the former red candles. - Go Short, when a red candles low is 10% of the cumulative rise of the green candles that triggered the Long. Respect these instructions: - Convert all Indicator specific code to Strategy specific code. Don't use any code that a TradingView Strategy won't support. Especially timeframes and gaps. Define those in code so they are semantically the same as before. - Preserve the timeframe logic if there is one. Fill gaps. - If the indicator is plotting something, the strategy code shall plot the same thing as well so the visuals are preserved. - Don't trigger a short. Simply go Long an…
Aurora: ```pinescript //@version=6 strategy("Demo GPT - Consecutive Candles Dip Rebound Long Strategy", overlay=true, commission_type=strategy.commission.percent, commission_value=0.1, slippage=0) // Inputs for start and end date filters (from 7 days ago to now) startTimeInput = input.time(timestamp("GMT-5", year(timenow), month(timenow), dayofmonth(timenow) - 7, 0, 0), "Start Time") endTimeInput = input.time(timestamp("GMT-5", year(timenow), month(timenow), dayofmonth(timenow), 23, 59), "End Time") // Time filter: only trade within the selected date range inDateRange = (time >= startTimeInput) and (time <= endTimeInput) // Helper functions to check candle colors relative to previous candle isGreen(idx) => close[idx] > close[idx + 1] isRed(idx) => close[idx] < close[idx + 1] // Check for 3 consecutive green candles starting 3 bars ago threeConsecutiveGreen = isGreen(3) and isGreen(2) and isGreen(1) // Calculate cumulative gain of these 3 green candles precisely greenGain = (close[3] - close[4]) + (close[2] - close[3]) + (close[1] - close[2]) // Count consecutive red candles after the 3 green candles (up to 3) redCount = 0 for i = 0 to 2 if isRed(i) redCount += 1 else break redDipExists =…
User: You are a professional PineScript v6 developer, you code in pinescript v6 format. You describe all your code. You know how to code indicators and strategies and you also know their differences in code. I need your help to turn a TradingView indicator into a strategy please. When to buy and when to sell: - Go Long, when there there are 3 consecutive green candles, followed by 1, max 3 red candles, followed by 1 - 3 green candles. The dip of the red candles can be max 50% of the gain of the 3 previous green candles. And the latest green bar must be equal or higher then the high of the former red candles. - Go Short, when a red candles low is 10% of the cumulative rise of the green candles that triggered the Long. Respect these instructions: - Convert all Indicator specific code to Strategy specific code. Don't use any code that a TradingView Strategy won't support. Especially timeframes and gaps. Define those in code so they are semantically the same as before. - Preserve the timeframe logic if there is one. Fill gaps. - If the indicator is plotting something, the strategy code shall plot the same thing as well so the visuals are preserved. - Don't trigger a short. Simply go Long an…
Aurora: ```pinescript //@version=6 strategy("Demo GPT - Consecutive Candles Dip Rebound Long Strategy", overlay=true, commission_type=strategy.commission.percent, commission_value=0.1, slippage=0) // Inputs for start and end date/time filters: from 30 bars ago to now // Using input.time with confirm=true for interactive selection defaultStartTime = ta.barssince(bar_index == 0) > 30 ? time[30] : time startTimeInput = input.time(defval=defaultStartTime, title="Start Time", confirm=true) endTimeInput = input.time(defval=timenow, title="End Time", confirm=true) // Time filter: only trade within the selected date range inDateRange = (time >= startTimeInput) and (time <= endTimeInput) // Helper functions to check candle colors relative to previous candle isGreen(idx) => close[idx] > close[idx + 1] isRed(idx) => close[idx] < close[idx + 1] // Check for 3 consecutive green candles starting 3 bars ago threeConsecutiveGreen = isGreen(3) and isGreen(2) and isGreen(1) // Calculate cumulative gain of these 3 green candles precisely greenGain = (close[3] - close[4]) + (close[2] - close[3]) + (close[1] - close[2]) // Count consecutive red candles after the 3 green candles (up to 3) redCount = 0 for i =…
User: You are a professional PineScript v6 developer, you code in pinescript v6 format. You describe all your code. You know how to code indicators and strategies and you also know their differences in code. I need your help to turn a TradingView indicator into a strategy please. When to buy and when to sell: - Go Long on: 3 consecutive green candles, followed by 1, max 3, red candles, triggered by the price which is equal or higher than the high of the last red candle - Go Short, when the price has lowered with 10% from the cummulative gain since the long position Respect these instructions: - Convert all Indicator specific code to Strategy specific code. Don't use any code that a TradingView Strategy won't support. Especially timeframes and gaps. Define those in code so they are semantically the same as before. - Preserve the timeframe logic if there is one. Fill gaps. - If the indicator is plotting something, the strategy code shall plot the same thing as well so the visuals are preserved. - Don't trigger a short. Simply go Long and Flat. - initial capital is 1000 - Always use 100% of capital. - Set commission to 0.1%. - Set slippage to 0. - strategy.commission.percent and strategy.s…
Aurora: ```pinescript //@version=6 strategy("Demo GPT - Consecutive Green-Red Candles Long Strategy", overlay=true, initial_capital=1000, commission_type=strategy.commission.percent, commission_value=0.1, slippage=0) // Settings for variables maxRedCandles = input.int(3, "Maximum Number of Red Candles", minval=1, maxval=3) minGreenCandles = 3 // Fixed: 3 consecutive green candles before red candles useFullCapital = true // Always use 100% of capital // Helper functions to check candle colors relative to previous candle isGreen(idx) => close[idx] > close[idx + 1] isRed(idx) => close[idx] < close[idx + 1] // Detect 3 consecutive green candles starting 3 bars ago threeConsecutiveGreen = isGreen(3) and isGreen(2) and isGreen(1) // Count consecutive red candles after the 3 green candles, up to maxRedCandles redCount = 0 for i = 0 to maxRedCandles - 1 if isRed(i) redCount += 1 else break redCandlesValid = redCount >= 1 and redCount <= maxRedCandles // Highest high of the last red candle in the sequence (the last red candle is at index redCount - 1) lastRedCandleHigh = redCandlesValid ? high[redCount - 1] : na // Current price must be equal or higher than the high of the last red candle priceTri…