Why is my indicator so slow when I use it in a strategy?
Forums › ProRealTime English forum › ProOrder support › Why is my indicator so slow when I use it in a strategy?
- This topic has 11 replies, 4 voices, and was last updated 3 months ago by robertogozzi.
-
-
05/25/2021 at 9:06 PM #170406
This is code of indicator that take:
- StopLossType => Select type of stop loss trailing (integer)
- LongPosition => True if is on long position (boolean)
- ShortPosition => True if is on short position (boolean)
- EnterPrice => Last price of position (decimal)
- EnterPriceClose => Last close price of position (decimal)
- TrailingStopLoss => Trailing stop loss pips (integer)
- StartBreakeven => Breakeven pips (integer)
- PointsToKeep => Points for breakeven (integer)
StopLossController123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051SupertrendMulti = 18SupertrendPeriod = 150BreakevenLevel = 0IF StopLossType = 2 THENSupertrendIndicator = Supertrend[SupertrendMulti,SupertrendPeriod]ENDIFIF NOT LongPosition AND NOT ShortPosition THENCurrentMaxPrice = 0CurrentMinPrice = CLOSE * 1000ENDIF// --- BUY SIDE ---IF LongPosition AND StopLossType = 1 AND NOT StopLossType = 0 THENCurrentMaxPrice = Max(CurrentMaxPrice,CLOSE)IF CurrentMaxPrice - EnterPrice >= TrailingStopLoss * PointSize THENBreakevenLevel = CurrentMaxPrice - TrailingStopLoss * PointSizeENDIFENDIFIF LongPosition AND StopLossType = 2 AND NOT StopLossType = 0 AND EnterPriceClose >= StartBreakeven * PointSize THENIF BreakevenLevel = 0 THENBreakevenLevel = EnterPrice + PointsToKeep * PointSizeELSEIF CLOSE > SupertrendIndicator THENBreakevenLevel = Max(BreakevenLevel,SupertrendIndicator)ENDIFENDIFENDIF// --- SELL SIDE ---IF ShortPosition AND StopLossType = 1 AND NOT StopLossType = 0 THENCurrentMinPrice = Min(CurrentMinPrice,CLOSE)IF EnterPrice -CurrentMinPrice>=TrailingStopLoss*PointSize THENBreakevenLevel = CurrentMinPrice+TrailingStopLoss*PointSizeENDIFENDIFIF ShortPosition AND StopLossType = 2 AND NOT StopLossType = 0 AND EnterPriceClose > StartBreakeven*PointSize THENIF BreakevenLevel = 0 THENBreakevenLevel = EnterPrice - PointsToKeep*PointSizeELSEIF CLOSE < SupertrendIndicator THENBreakevenLevel = MIN(BreakevenLevel,SupertrendIndicator)ENDIFENDIFENDIFReturn BreakevenLevel AS "Breakeven Level"I can add to the charts but if I add to my strategy it is so slow.
My strategy :
Example of strategy12345678910111213141516171819202122232425262728293031323334353637383940DEFPARAM Preloadbars = 10000IF NOT LongOnMarket THENBUY 1 CONTRACTS AT MARKETENDIFSET STOP PLOSS 10LongPosition = 0ShortPosition = 0TrailingStopLoss = 15StartBreakeven = 15PointsToKeep = 5EnterPrice = 0EnterPriceClose = 0StopLossType = 2IF LONGONMARKET THENLongPosition = 1ENDIFIF SHORTONMARKET THENShortPosition = 1ENDIFIF ONMARKET THENEnterPrice = TradePrice(1)EnterPriceClose = TradePrice(1)-CloseBreakevenLevel = CALL "StopLossController"[StopLossType, LongPosition, ShortPosition, EnterPrice, EnterPriceClose, TrailingStopLoss, StartBreakeven, PointsToKeep]ENDIFIF LONGONMARKET AND BreakevenLevel > 0 THENSELL AT BreakevenLevel STOPENDIFIF SHORTONMARKET AND BreakevenLevel > 0 THENEXITSHORT AT BreakevenLevel STOPENDIFWhy?? any suggestion?
Thanks
05/26/2021 at 7:11 AM #17042905/26/2021 at 8:10 AM #17043305/26/2021 at 8:17 AM #170434Actually it’s very slow. I tried embedding the indicator in the strategy and it’s fast (Dax, 4h, 200K).
I am attaching the modified version.
05/26/2021 at 8:18 AM #170436I was posting while you were replying. So you already experienced that. Sorry.
05/26/2021 at 9:59 AM #17045705/26/2021 at 10:42 AM #170471It’s incredible, if I put my code from indicator to my strategy is working well, but if commit all code in indicator is very slow yet.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051SupertrendMulti = 18SupertrendPeriod = 150BreakevenLevel = 0//IF StopLossType = 2 THEN//SupertrendIndicator = Supertrend[SupertrendMulti,SupertrendPeriod]//ENDIF////IF NOT LongPosition AND NOT ShortPosition THEN//CurrentMaxPrice = 0//CurrentMinPrice = CLOSE * 1000//ENDIF////// --- BUY SIDE ---//IF LongPosition AND StopLossType = 1 AND NOT StopLossType = 0 THEN//CurrentMaxPrice = Max(CurrentMaxPrice,CLOSE)//IF CurrentMaxPrice - EnterPrice >= TrailingStopLoss * PointSize THEN//BreakevenLevel = CurrentMaxPrice - TrailingStopLoss * PointSize//ENDIF//ENDIF////IF LongPosition AND StopLossType = 2 AND NOT StopLossType = 0 AND EnterPriceClose >= StartBreakeven * PointSize THEN//IF BreakevenLevel = 0 THEN//BreakevenLevel = EnterPrice + PointsToKeep * PointSize//ELSE//IF CLOSE > SupertrendIndicator THEN//BreakevenLevel = Max(BreakevenLevel,SupertrendIndicator)//ENDIF//ENDIF//ENDIF//////// --- SELL SIDE ---//IF ShortPosition AND StopLossType = 1 AND NOT StopLossType = 0 THEN//CurrentMinPrice = Min(CurrentMinPrice,CLOSE)//IF EnterPrice -CurrentMinPrice>=TrailingStopLoss*PointSize THEN//BreakevenLevel = CurrentMinPrice+TrailingStopLoss*PointSize//ENDIF//ENDIF////IF ShortPosition AND StopLossType = 2 AND NOT StopLossType = 0 AND EnterPriceClose > StartBreakeven*PointSize THEN//IF BreakevenLevel = 0 THEN//BreakevenLevel = EnterPrice - PointsToKeep*PointSize//ELSE//IF CLOSE < SupertrendIndicator THEN//BreakevenLevel = MIN(BreakevenLevel,SupertrendIndicator)//ENDIF//ENDIF//ENDIFReturn BreakevenLevel AS "Breakeven Level"05/26/2021 at 11:56 AM #170488If you call it with constants, instead of variables, it works fine:
1BreakevenLevel = CALL "StopLossController"[0,0,15,15,5,0,0,2]05/26/2021 at 12:30 PM #170496Grazie Roberto, but it is not useful, in a lot of situation I need pass to indicator dynamic variable.
problem is decimal inputs,
- EnterPrice => Last price of position (decimal)
- EnterPriceClose => Last close price of position (decimal)
1BreakevenLevel = CALL "StopLossController"[StopLossType,LongPosition,ShortPosition,15,15,TrailingStopLoss,StartBreakeven,PointsToKeep]05/26/2021 at 1:59 PM #170504Yes, I know variables are necessary.
It’s just to know what happens in multiple different situations, in case you want to report this issue to PRT.
1 user thanked author for this post.
09/07/2024 at 10:41 PM #23730209/07/2024 at 11:42 PM #237303The issue with using CALL was sorted out a few years ago, when CALLed indicators were automatically appended to the code, so now the only overhead is the CALL itself, not loading the indicator.
I sometimes experience slow backtesting, as well. It usually lasts one day or a few days, then the regular speed is restored.
It may be due to overloaded servers because of too many strategies running at the same time or to demo account while in maintenance mode.
Try enquiring ProRealTime.
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on