Range breakout strategy
Forums › ProRealTime English forum › ProOrder support › Range breakout strategy
- This topic has 4 replies, 4 voices, and was last updated 1 year ago by ZeroCafeine.
-
-
04/23/2023 at 11:19 PM #213642
Hi there, I am trying to code a strategy that involves collecting the highest high price and the lowest low of a particular time range in the morning. After this time, there is another period of 2 hour where if the price closes above this range, a long is opened with a stop loss at the lowest low point; and vice versa if close is below the lowest low.
Additionally, if the trade is stopped out; then an opposing trade is opened in the opposite direction, with the stop set again at the opposing end of the range.
I have tried several different ways of coding the entry but no matter what no trades are opened; or if they are, they are very inconsistent and do not conform to the rules and appear to be random and I cannot figure out which part of the code is incorrect and was hoping someone may be able to suggest what I am doing wrong?
Thank you
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061// VariablesDEFPARAM CumulateOrders = False // Disable accumulation of positionstargetPoints = 50 // Set global target price to 50 pointstradeStart = 1100 // Set start time for entering tradestradeEnd = 1300 // Set end time for entering tradessessionEnd = 1800 // Set end time for closing open positionsrangeStart = 0900 // Define range start timerangeEnd = 1100 // Define range end timeIf IntraDayBarIndex = 0 thenhighestPrice = 0lowestPrice = 999999endif// Calculate highest and lowest prices between 00:00 and 07:00IF time >= rangeStart AND time <= rangeEnd THENhighestPrice = max(high,highestPrice)lowestPrice = min(low,lowestPrice)ENDIF// Long entry conditionIF time >= tradeStart AND time <= tradeEnd AND close > highestPrice THENbuy at marketSET STOP stopLossLong LimitSET TARGET PROFIT targetPointsENDIF// Short entry conditionIF time >= tradeStart AND time <= tradeEnd AND close < lowestPrice THENsellshort at marketSET STOP stopLossShort limitSET TARGET PROFIT targetPointsENDIF// Stop loss and target for long positionsIF LONGONMARKET THENsell at stopLossLong stopsell at targetPoints limitIF barindex - tradeindex = 1 AND low[1] <= stopLossLong THENsellshort at marketstopLossShort = highestPriceSET TARGET PROFIT targetPointsENDIFENDIF// Stop loss and target for short positionsIF SHORTONMARKET THENexitshort at stopLossShort stopexitshort at targetPoints limitIF barindex - tradeindex = 1 AND high[1] >= stopLossShort THENbuy at marketstopLossLong = lowestPriceSET TARGET PROFIT targetPointsENDIFENDIFIF time >= sessionEnd THENsell at marketexitshort at marketENDIF04/24/2023 at 1:14 AM #21364304/24/2023 at 12:35 PM #21367304/24/2023 at 3:12 PM #213680no matter what no trades are opened;
Have you checked Closed Trades in the Detailed Report? You may be opening and closing trades in the same bar and so they do not show under the equity curve?
Also, try replacing Line 25 and Line 32 with Set Stop pLoss x and also comment out Line 36 to the end … just to get it going / taking trades.
You can then uncomment back in to see which part of the code is stopping the strategy working correctly.
Also include below at the end of your code to see when it is True.
GRAPH other variables & conditions to see how the code is / is not working.
A few ideas to try anyway, hope they help?
1GRAPH close > highestPrice04/25/2023 at 12:07 PM #213712 -
AuthorPosts
Find exclusive trading pro-tools on