Reversal long
Forums › ProRealTime English forum › ProOrder support › Reversal long
- This topic has 6 replies, 4 voices, and was last updated 3 weeks ago by JS.
-
-
10/11/2024 at 7:25 AM #238845
Hi.
Idea:
- 4 hits within a 10-point price range (e.g., 20000, 20007, 20002, 20007).
- Find support
- These hits should happen within a time limit of 20 bars.
- each candle must be within a size of 35-85 points (the difference between its high and low).
- enter long after fourth hit
ChatGTP that did not get it right. Can Anyone help me out?
Long reversal1234567891011121314151617181920212223242526272829303132333435363738394041424344// Strategy parametersrangeLimit = 10 // 10-point range for hitsbarLimit = 20 // Max 20 bars to evaluate for hitsminCandleSize = 35 // Minimum candle size in pointsmaxCandleSize = 85 // Maximum candle size in points// Initialize variableshits = 0lowestPrice = highhighestPrice = lowentrySignal = 0// Loop through the last 20 bars to check for hitsFOR i = 1 TO barLimit DOcandleSize = high[i] - low[i] // Calculate the candle size// Check if the candle size is between 35 and 85 pointsIF (candleSize >= minCandleSize AND candleSize <= maxCandleSize) THEN// If price hits the bottom within a 10-point rangeIF (low[i] <= lowestPrice + rangeLimit AND low[i] >= lowestPrice) THENhits = hits + 1 // Count the hit// Update lowest and highest hits within the rangelowestPrice = MIN(low[i], lowestPrice)highestPrice = MAX(low[i], highestPrice)ENDIF// Check the spread between the lowest and highest hits (must stay within 10 points)hitRange = highestPrice - lowestPriceIF hitRange > rangeLimit THENhits = 0 // Reset hits if the spread exceeds 10 pointsBREAKENDIFENDIFNEXT// Check if 4 hits have occurred within the rangeIF hits >= 4 THENentrySignal = 1 // Generate an entry signalENDIF// Place a market order when an entry signal is triggeredIF entrySignal THENBUY 1 CONTRACT AT MARKETENDIF10/11/2024 at 1:20 PM #238869I still need Help to do this:
Ivan, Roberto? 🙂
Strategy Conditions:
Range Calculation (RangeBars):The strategy calculates the range of price movement (highest high minus lowest low) over 20 bars.
The range (referred to as RangeBars) must be between 30 and 80 points for the strategy to proceed.Bounce Detection:
A “bounce” refers to a candlestick where the low is within 10 points of the lowest low over the last 20 bars. This low is considered as forming or aligning with a support line.
The strategy loops through each of the last 20 bars and counts how many of these bars qualify as “bounces.”
Entry Condition:The strategy will only enter a trade if 4 or more bounces (candles near the support line) are identified within the last 20 bars.
Stop Loss:
The stop loss is set to 20 points below the lowest identified bounce (support level) within the 20-bar window.
Exit Condition:
The strategy will exit the position if the price closes below the 14-period Exponential Moving Average (EMA14).
Key Parameters:
- nBars: 20 bars used for range and bounce detection.
- rangeMin: Minimum range of 30 points for valid trades.
- rangeMax: Maximum range of 80 points for valid trades.
- bounceThreshold: Threshold of 10 points within which a candle’s low must fall to be counted as a bounce (support line validation).
- stopLossBuffer: 20 points below the lowest detected bounce (support) for setting stop loss.
- emaPeriod: 14-period EMA used for exit condition.
The strategy aims to identify support levels by detecting multiple bounces (candles with lows near the support line) before entering a trade. The trade is initiated only when there is enough confirmation of support in the form of multiple bounces, and the stop loss is set just below this support level to minimize risk.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152DEFPARAM CumulateOrders = False // Cumulating positions deactivated// Define parametersnBars = 20 // Period to calculate RangeBarsrangeMin = 30rangeMax = 80studsThreshold = 10stopLossBuffer = 20emaPeriod = 14// EMA for exit conditionema14 = ExponentialAverage[emaPeriod](close)// Define the RangeBars calculationhighestHigh = highest[nBars](high)lowestLow = lowest[nBars](low)rangeBars = highestHigh - lowestLow// Store the lowest low over the last nBarslowestLow = lowest[nBars](low)// Initialize counter for studs and tracking the lowest bouncecountStudsar = 0lowestBounce = low[0] // Start value for the lowest bounce// Check if the RangeBars over the last 20 bars is within 30-80 pointsIF RangeBars >= rangeMin AND RangeBars <= rangeMax THEN// Loop through the last nBars to identify studsFOR i = 0 TO nBars-1 DO// Check if candle lows are within the threshold (10 points) from the lowestLowIF ABS(Low[i] - lowestLow) <= studsThreshold THENcountStudsar = countStudsar + 1lowestBounce = MIN(lowestBounce, Low[i]) // Update the lowest bounceENDIFNEXT// Entry condition: Only enter if 4 or more studs have been identifiedIF countStudsar >= 4 THEN// Ensure no multiple entries if already on the marketIF NOT ONMARKET THEN// Buy at market when entry condition is metBUY 1 CONTRACT AT MARKET// Set stop loss 20 points below the lowest identified bounceSET STOP pLOSS (lowestBounce - stopLossBuffer)ENDIFENDIFENDIF// Exit condition: Close position if price crosses below the EMA14IF close < ema14 THENSELL AT MARKETENDIF10/11/2024 at 3:46 PM #238876Hi! Beyond the logic of the system there are some things that are not right. You must include the pipsize expression in the control ranges and levels for the calculation to make sense.
1RangeBars >= rangeMin*pipsize AND RangeBars <= rangeMax*pipsize)1ABS(Low[i] - lowestLow) <= studsThreshold*pipsize1SET STOP pLOSS stopLossBufferI hope that with these changes you can draw conclusions and see if the strategy works or not.
10/11/2024 at 4:10 PM #238878There you go:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647DEFPARAM CumulateOrders = False // Cumulating positions deactivated// Define parametersnBars = 20 //20 Period to calculate RangeBarsBounceBars = 4 //4 bouce periodsrangeMin = 10 * PipSizerangeMax = 80 * PipSizestudsThreshold = 10 * PipSizestopLossBuffer = 20 * PipSizeemaPeriod = 14// EMA for exit conditionema14 = ExponentialAverage[emaPeriod](close)// Define the RangeBars calculationhighestHigh = highest[nBars](high)lowestLow = lowest[nBars](low)Count1 = 0Count2 = 0lowestBounce = 9999999FOR i = 0 TO (nBars - 1)IF (range[i] >= rangeMin) AND (range[i] <= rangeMax) THENCount1 = Count1 + 1ENDIFIF (low[i] <> lowestLow) AND (abs(low[i] - lowestLow) <= studsThreshold) THENCount2 = Count2 + 1lowestBounce = min(lowestBounce,low[i])ENDIFNEXTRangebars = (Count1 = nBars)Bounce = (Count2 >= BounceBars)// Initialize counter for studs and tracking the lowest bounceIF (close > ema14) AND Not OnMarket AND RangeBars AND Bounce THENBUY 1 Contract at MarketStopLoss = lowestBounce - stopLossBufferSET STOP PRICE StopLossENDIF// Exit condition: Close position if price crosses below the EMA14IF close < ema14 THENSELL AT MARKETENDIF////graphonprice StopLoss AS "Stop Loss" coloured("Red")//graphonprice TradePrice AS "Entry Price" coloured("Blue")//graphonprice lowestBounce10/11/2024 at 9:05 PM #238880I am very grateful for your help, Roberto. However, I can see that we haven’t quite reached the finish line yet.
As you can see from the image, the range here is 145.5 points within 20 bars.
The condition is that the range should be at least 35 points and at most 85 points.10/12/2024 at 11:47 AM #238900This is what you just asked:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647DEFPARAM CumulateOrders = False // Cumulating positions deactivated// Define parametersnBars = 20 //20 Period to calculate RangeBarsBounceBars = 4 //4 bouce periodsrangeMin = 10 * PipSizerangeMax = 80 * PipSizestudsThreshold = 10 * PipSizestopLossBuffer = 20 * PipSizeemaPeriod = 14// EMA for exit conditionema14 = ExponentialAverage[emaPeriod](close)// Define the RangeBars calculationhighestHigh = highest[nBars](high)lowestLow = lowest[nBars](low)myRange = highestHigh - lowestLowRangebars = (myRange >= rangeMin) AND (myRange <= rangeMax)Count = 0lowestBounce = 9999999IF Rangebars THENFOR i = 0 TO (nBars - 1)IF (low[i] <> lowestLow) AND (abs(low[i] - lowestLow) <= studsThreshold) THENCount = Count + 1lowestBounce = min(lowestBounce,low[i])ENDIFNEXTENDIFBounce = (Count >= BounceBars)// Initialize counter for studs and tracking the lowest bounceIF (close > ema14) AND Not OnMarket AND Bounce THENBUY 1 Contract at MarketStopLoss = lowestBounce - stopLossBufferSET STOP PRICE StopLossENDIF// Exit condition: Close position if price crosses below the EMA14IF close < ema14 THENSELL AT MARKETENDIF////graphonprice StopLoss AS "Stop Loss" coloured("Red")//graphonprice TradePrice AS "Entry Price" coloured("Blue")//graphonprice lowestBounce10/13/2024 at 11:12 AM #238928Hi,
Try this one:
Reversal Long123456789101112131415161718192021222324252627DefParam CumulateOrders=FalseMinBounce=4Bars=20BounceThreshold=10*PipSizeSLBuffer=20*PipSizeTPBuffer=20*PipSizeEMAPeriod=14EMA14=ExponentialAverage[EMAPeriod](Close)RangeBarsMin=30*PipSizeRangeBarsMax=80*PipSizeHH=Highest[Bars](High)LL=Lowest[Bars](Low)RangeBars=HH-LLCheckRB=Summation[Bars](RangeBars>=RangeBarsMin and RangeBars<=RangeBarsMax)=20CheckCondition=Summation[20](Low<=LL+BounceThreshold)=4If CheckRB and CheckCondition and Close>EMA14 then//Bounce=MinBounce then//and Close>EMA14 thenBuy 1 contract at MarketSL=LL-SLBufferSet Stop Price SLTP=HH+TPBufferSet Target Price TPEndIf - 4 hits within a 10-point price range (e.g., 20000, 20007, 20002, 20007).
-
AuthorPosts
Find exclusive trading pro-tools on