Hello community,
My purpose of this code is created a mix strategy between the indicator I developed over the volume indicator, which is already posted in my profile and the awesome strategy that everyone could see in this fórum, the amazin pathfinder system (Thanks.).
Basiclly, i keep the position size management and money management, i modified the parameters the entry long and short at the market.
- Conditions for long entry.
- a = AverageVolumeBuy CROSSES OVER AverageVolumeSell
- b = AverageVolumeBuy > AverageVolumeBuy[1]
- c = MACDVolume > AverageVolumeSell
- Conditions for short entry.
- d = AverageVolumeSell CROSSES OVER AverageVolumeBuy
- e = AverageVolumeSell > AverageVolumeSell[1]
- f= MACDVolume > AverageVolumeBuy
It is just a initial idea which is neccesary to analyze much deeper, moreover I don’t have too much volume data so if someone wants to join to help it’s welcome.
Please pleople, commento below if you know how to improve and together we can build a better strategy.
Regards
Xusto
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
//Created by Xusto //v0.1 //date: 201806 //Capital: 5000 // IG Market: 2 points of spread //Acelerate Volume in candles of 4H, code in based of Pathfinder System (Check the topic in the forum of ProRealTime). //The conditions of entry and exit from the market is in base of the acelerate volume, the other conditions (position sizy, and money management) were taken in the Pathfinder System, which is awesome. // ProOrder code parameter DEFPARAM CUMULATEORDERS = False // cumulate orders if not turned off DEFPARAM PRELOADBARS = 10000 // define intraday trading window startTime = 90000 // start time of trading window in CET endTime = 220000 // end time of trading window in CET // define position and money management parameter // size calculation: size = positionSize * trendMultiplier * saisonalPatternMultiplier positionSize = 1 // default start size trendMultiplier = 2 // >1 with dynamic position sizing; 1 without maxPositionSizePerTrade = 9 // maximum size per trade maxPositionSizeLong = 9 // maximum size for a long position maxPositionSizeShort = 9 // maximum size for a short position stopLossLong = 3.5 //3.5 in % stopLossShort = 2.5 // in % takeProfitLong = 3.5 // in % takeProfitShort = 3.5 //1.5 in % trailingStartLong = 1.5 //1.25 in % trailingStartShort = 0.75 //0.5 in % trailingStepLong = 0.5 // in % trailingStepShort = 0.5 // in % maxCandlesLongWithProfit = 16 //15 take long profit latest after x candles maxCandlesShortWithProfit = 5 // take short profit latest after x candles maxCandlesLongWithoutProfit = 75 //70 limit long loss latest after x candles maxCandlesShortWithoutProfit = 70 // limit short loss latest after x candles // define saisonal position multiplier for each month 1-15 / 16-31 (>0 - long / <0 - short / 0 no trade) January1 = 1 //1 January2 = 0 //2 0 February1 = 3 //3 February2 = 1 //1 March1 = 3 //3 1 March2 = 3 //3 April1 = 3 //2 3 April2 = 3 //3 May1 = 1 //1 May2 = 3 //3 June1 = 1 //1 June2 = 3 //3 July1 = 3 //3 July2 = 0 //0 August1 = 1 //1 August2 = 1 //0 x September1 = 2 //2 September2 = 0 //0 October1 = 2 //3 October2 = 2 //2 November1 = 0 //0 November2 = 3 //3 December1 = 2 //2 December2 = 2 //2 // dynamic position sizing based on weekly performance profitLastWeek = 0 IF DayOfWeek <> DayOfWeek[1] AND DayOfWeek = 1 THEN IF StrategyProfit > profitLastWeek + 1 THEN positionSize = MIN(trendMultiplier, positionSize + 1) // increase risk ELSE positionSize = MAX(1, positionSize - 1) // decrease risk ENDIF profitLastWeek = strategyProfit ENDIF // calculate acelerate volume PeriodFast = 4 //PeriodFast --> Bar numbers used for fast period calculations (Value Recomended 4) PeriodSlow = 10 //PeriodSlow --> Bar numbers used for slow period calculations (Value Recomended 10) //Candle Sections //Full Range a = high-low //Green Candle b = open-low c = high-close //Red Candle d = high-open e = close-low //Unitary volume (Buy&Sell) volUniBuy = volume/(a+b+c) //Green Candle volUniSell = volume/(a+d+e) //Red Candle //Volume calculated by candle VolBuyGreen=a*volUniBuy //Buy volume on green candle VolBuyRed=(d+e)*volUniSell //Buy volume on red candle VolSellGreen=(b+c)*volUniBuy //Sell Volume on green candle VolSellRed=a*volUniSell //Sell Volume on red candle if close>=open then VolBuyGreen = VolBuyRed VolSellGreen = 0 else VolSellRed = VolSellGreen VolBuyRed = 0 endif //Averages AverageVolBuy1=ExponentialAverage[PeriodFast](VolBuyGreen) AverageVolSell1=ExponentialAverage[PeriodFast](VolSellRed) AverageVolBuy2=Average[PeriodSlow](VolBuyGreen) AverageVolSell2=Average[PeriodSlow](VolSellRed) AverageVolumeBuy=AverageVolBuy1-AverageVolBuy2 AverageVolumeSell=AverageVolSell1-AverageVolSell2 //MACD calculated over volume MMFast = exponentialAverage[4](volume) MMSlow = exponentialAverage[10](volume) MACDVolume = MMFast - MMSlow // trade only in defined trading window IF Time >= startTime AND Time <= endTime THEN // set saisonal multiplier currentDayOfTheMonth = OpenDay midOfMonth = 15 IF CurrentMonth = 1 THEN IF currentDayOfTheMonth <= midOfMonth THEN saisonalPatternMultiplier = January1 ELSE saisonalPatternMultiplier = January2 ENDIF ELSIF CurrentMonth = 2 THEN IF currentDayOfTheMonth <= midOfMonth THEN saisonalPatternMultiplier = February1 ELSE saisonalPatternMultiplier = February2 ENDIF ELSIF CurrentMonth = 3 THEN IF currentDayOfTheMonth <= midOfMonth THEN saisonalPatternMultiplier = March1 ELSE saisonalPatternMultiplier = March2 ENDIF ELSIF CurrentMonth = 4 THEN IF currentDayOfTheMonth <= midOfMonth THEN saisonalPatternMultiplier = April1 ELSE saisonalPatternMultiplier = April2 ENDIF ELSIF CurrentMonth = 5 THEN IF currentDayOfTheMonth <= midOfMonth THEN saisonalPatternMultiplier = May1 ELSE saisonalPatternMultiplier = May2 ENDIF ELSIF CurrentMonth = 6 THEN IF currentDayOfTheMonth <= midOfMonth THEN saisonalPatternMultiplier = June1 ELSE saisonalPatternMultiplier = June2 ENDIF ELSIF CurrentMonth = 7 THEN IF currentDayOfTheMonth <= midOfMonth THEN saisonalPatternMultiplier = July1 ELSE saisonalPatternMultiplier = July2 ENDIF ELSIF CurrentMonth = 8 THEN IF currentDayOfTheMonth <= midOfMonth THEN saisonalPatternMultiplier = August1 ELSE saisonalPatternMultiplier = August2 ENDIF ELSIF CurrentMonth = 9 THEN IF currentDayOfTheMonth <= midOfMonth THEN saisonalPatternMultiplier = September1 ELSE saisonalPatternMultiplier = September2 ENDIF ELSIF CurrentMonth = 10 THEN IF currentDayOfTheMonth <= midOfMonth THEN saisonalPatternMultiplier = October1 ELSE saisonalPatternMultiplier = October2 ENDIF ELSIF CurrentMonth = 11 THEN IF currentDayOfTheMonth <= midOfMonth THEN saisonalPatternMultiplier = November1 ELSE saisonalPatternMultiplier = November2 ENDIF ELSIF CurrentMonth = 12 THEN IF currentDayOfTheMonth <= midOfMonth THEN saisonalPatternMultiplier = December1 ELSE saisonalPatternMultiplier = December2 ENDIF ENDIF // long position conditions a = AverageVolumeBuy CROSSES OVER AverageVolumeSell b = AverageVolumeBuy > AverageVolumeBuy[1] c = MACDVolume > AverageVolumeSell // short position conditions d = AverageVolumeSell CROSSES OVER AverageVolumeBuy e = AverageVolumeSell > AverageVolumeSell[1] f= MACDVolume > AverageVolumeBuy // long entry with order cumulation IF ( a AND b and c ) THEN // check saisonal booster setup and max position size IF saisonalPatternMultiplier > 0 THEN numberContracts = MIN(maxPositionSizePerTrade, positionSize * saisonalPatternMultiplier) IF (COUNTOFPOSITION + numberContracts) <= maxPositionSizeLong THEN IF SHORTONMARKET THEN EXITSHORT AT MARKET ENDIF BUY numberContracts CONTRACT AT MARKET ENDIF ELSIF saisonalPatternMultiplier <> 0 THEN numberContracts = MIN(maxPositionSizePerTrade, positionSize) IF (COUNTOFPOSITION + numberContracts) <= maxPositionSizeLong THEN IF SHORTONMARKET THEN EXITSHORT AT MARKET ENDIF BUY numberContracts CONTRACT AT MARKET ENDIF ENDIF stopLoss = stopLossLong takeProfit = takeProfitLong ENDIF // short entry with order cumulation IF ( d AND e AND f ) THEN // check saisonal booster setup and max position size IF saisonalPatternMultiplier < 0 THEN numberContracts = MIN(maxPositionSizePerTrade, positionSize * ABS(saisonalPatternMultiplier)) IF (ABS(COUNTOFPOSITION) + numberContracts) <= maxPositionSizeShort THEN IF LONGONMARKET THEN SELL AT MARKET ENDIF SELLSHORT numberContracts CONTRACT AT MARKET ENDIF ELSIF saisonalPatternMultiplier <> 0 THEN numberContracts = MIN(maxPositionSizePerTrade, positionSize) IF (ABS(COUNTOFPOSITION) + numberContracts) <= maxPositionSizeShort THEN IF LONGONMARKET THEN SELL AT MARKET ENDIF SELLSHORT numberContracts CONTRACT AT MARKET ENDIF ENDIF stopLoss = stopLossShort takeProfit = takeProfitShort ENDIF // stop and profit management // time exit posProfit = (((close - positionprice) * pointvalue) * countofposition) / pipsize numberCandles = (BarIndex - TradeIndex) m1 = posProfit > 0 AND numberCandles >= maxCandlesLongWithProfit m2 = posProfit > 0 AND numberCandles >= maxCandlesShortWithProfit m3 = posProfit < 0 AND numberCandles >= maxCandlesLongWithoutProfit m4 = posProfit < 0 AND numberCandles >= maxCandlesShortWithoutProfit // take profit after max candles IF LONGONMARKET AND (m1 OR m3) THEN SELL AT MARKET ENDIF IF SHORTONMARKET AND (m2 OR m4) THEN EXITSHORT AT MARKET ENDIF if (1=1) then // trailing stop function (convert % to pips) trailingStartLongInPoints = tradeprice(1) * trailingStartLong / 100 trailingStartShortInPoints = tradeprice(1) * trailingStartShort / 100 trailingStepLongInPoints = tradeprice(1) * trailingStepLong / 100 trailingStepShortInPoints = tradeprice(1) * trailingStepShort / 100 // reset the stoploss value IF NOT ONMARKET THEN newSL = 0 ENDIF // manage long positions IF LONGONMARKET THEN // first move (breakeven) IF newSL = 0 AND close - tradeprice(1) >= trailingStartLongInPoints * pipsize THEN newSL = tradeprice(1) + trailingStepLongInPoints * pipsize stopLoss = stopLossLong * 0.1 takeProfit = takeProfitLong * 2 ENDIF // next moves IF newSL > 0 AND close - newSL >= trailingStepLongInPoints * pipsize THEN newSL = newSL + trailingStepLongInPoints * pipsize ENDIF ENDIF // manage short positions IF SHORTONMARKET THEN // first move (breakeven) IF newSL = 0 AND tradeprice(1) - close >= trailingStartShortInPoints * pipsize THEN newSL = tradeprice(1) - trailingStepShortInPoints * pipsize ENDIF // next moves IF newSL > 0 AND newSL - close >= trailingStepShortInPoints * pipsize THEN newSL = newSL - trailingStepShortInPoints * pipsize ENDIF ENDIF // stop order to exit the positions IF newSL > 0 THEN IF LONGONMARKET THEN SELL AT newSL STOP ENDIF IF SHORTONMARKET THEN EXITSHORT AT newSL STOP ENDIF ENDIF endif // superordinate stop and take profit SET STOP %LOSS stopLoss SET TARGET %PROFIT takeProfit ENDIF |
Share this
No information on this site is investment advice or a solicitation to buy or sell any financial instrument. Past performance is not indicative of future results. Trading may expose you to risk of loss greater than your deposits and is only suitable for experienced investors who have sufficient financial means to bear such risk.
ProRealTime ITF files and other attachments :PRC is also on YouTube, subscribe to our channel for exclusive content and tutorials
Thank you Xusto. Thank you a lot for your contribution 🙂
Since your code is a Pathfinder’s fork, you should alert users of it in the specific Pathfinder topic : https://www.prorealcode.com/topic/pathfinder-trading-system/
You can also create your own topic to discuss about this new idea.
Hello,
Fully Agree, I will update it with your advice.
Btw Can would you like share you comment about this idea?
Thanks
do you now if it’s possible to use this strategy with this code in tradingview also?
This code for metastock ?, can for amibroker . Thanks