Sounds wrong coding, anyone can help pls
Forums › ProRealTime English forum › ProOrder support › Sounds wrong coding, anyone can help pls
- This topic has 8 replies, 5 voices, and was last updated 21 hours ago by
JS.
-
-
02/20/2025 at 2:00 AM #244086Long Dema Xing ATR-ADX12345678910// Definition of code parametersDEFPARAM CumulateOrders = TRUE // Cumulating positions deactivated// Var indicatorATX = CALL "PRC_Adaptive-ATR-ADX-Trend-V2"[21, 3.5, 1.75, 14, 30, 0, 1](close)DEM = DEMA[14](close)// Logicif DEM CROSSES OVER ATX thenBUY 5 CONTRACTS AT MARKETENDIF02/20/2025 at 10:12 AM #244093
I don’t see errors. The system buys when the DEMA (orange) crosses over ATX (blue).
12345678910111213// Definition of code parametersDEFPARAM CumulateOrders = TRUE // Cumulating positions deactivated// Var indicatorATX = CALL "PRC_Adaptive-ATR-ADX-Trend-V2"[21, 3.5, 1.75, 14, 30, 0, 1](close)DEM = DEMA[14](close)// Logicif DEM CROSSES OVER ATX thenBUY 5 CONTRACTS AT MARKETENDIFgraphonprice ATX coloured("blue")graphonprice DEM coloured("orange")02/20/2025 at 12:34 PM #24409502/20/2025 at 2:52 PM #244100Try putting / embedding the called Indicator in with the code of the rest of Strategy.
Also, isn’t Line 35 (see below) of the ‘Adaptive Ind’ wrong / ‘suspect’ as STR is not defined anywhere, but STR is used in the rest of the ‘Adaptive Ind’? This might be causing ProOrder to Reject the overall code?
sTR = (sTR[1] – sTR[1]) / adxLen + tr
02/20/2025 at 3:10 PM #244101Here is the Indicator if anybody has any ideas about fixing Line 35??
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137//PRC_Adaptive-ATR-ADX-Trend-V2 | indicator//29.06.2017//Nicolas @ www.prorealcode.com//Sharing ProRealTime knowledge//translated from tradingview code// --- settingsatrLen = 21m1 = 3.5 //"ATR Multiplier - ADX Rising"m2 = 1.75 //"ATR Multiplier - ADX Falling"adxLen = 14adxThresh = 30 //"ADX Threshold"aboveThresh = 1 //true, title = "ADX Above Threshold uses ATR Falling Multiplier Even if Rising?")useHeiken = 1 //(false, title = "Use Heiken-Ashi Bars (Source will be ohlc4)")// --- end of settingssource = MedianPrice// DI-Pos, DI-Neg, ADXhR = high-high[1]lR = -(low-low[1])if hr>lr thendmPos=max(hr,0)elsedmPos=0endifif lr>hr thendmNeg=max(lr,0)elsedmNeg=0endifsTR = (sTR[1] - sTR[1]) / adxLen + trsDMPos = (sDMPos[1] - sDMPos[1]) / adxLen + dmPossDMNeg = (sDMNeg[1] - sDMNeg[1]) / adxLen + dmNegDIP = sDMPos / sTR * 100DIN = sDMNeg / sTR * 100DX = abs(DIP - DIN) / (DIP + DIN) * 100aadx = average[adxLen](DX)// Heiken-Ashiif barindex<2 thenxClose = closexOpen = openelsexClose = TotalPricexOpen = (xOpen[1] + close[1]) / 2endifxHigh = max(high, max(xOpen, xClose))xLow = min(low, min(xOpen, xClose))// Trailing ATRv1 = abs(xHigh - xClose[1])v2 = abs(xLow - xClose[1])v3 = xHigh - xLowtrueRange = max(v1, max(v2, v3))if useHeiken thenatr = WilderAverage[atrLen](trueRange)elseatr = AverageTrueRange[atrLen]endifif aadx>aadx[1] and (adx < adxThresh or not aboveThresh) thenm=m1elsif aadx<aadx[1] or (adx > adxThresh and aboveThresh) thenm=m2elsem = m[1]endifif DIP >= DIN thenmUp=melsemUp=m2endifif DIN >= DIP thenmDn=melsemDn=m2endifif useHeiken thensrc=xClosec=Xcloset=(xHigh+xLow)/2elsesrc=sourcec=closet=MedianPriceendifup = t - mUp * atrdn = t + mDn * atrif max(src[1], c[1]) > TUp[1] thenTUp = max(up,TUp[1])elseTUp = upendifif min(src[1], c[1]) < TDown[1] thenTDown = min(dn, TDown[1])elseTDown = dnendif//trendif min(src,min(c,close))>TDown[1] thentrend=1elsif max(src,max(c,close))<TUp[1] thentrend=-1elsetrend=trend[1]endifif trend=1 thensstop=TUpr=0g=255elsesstop=TDownr=255g=0endifif trend<>trend[1] thendrawtext("•",barindex,sstop,Dialog,Standard,30) coloured(r,g,0)endifreturn sstop coloured(r,g,0) style(line,2)02/20/2025 at 5:16 PM #24410902/20/2025 at 8:18 PM #244114Thanks JS, but please could not you (anybody) rejig the code so that the subsequent use of sTR in the Strategy is removed / replaced with something meaningful?
Examples are Line 40 & 41 –DIP = sDMPos / sTR * 100DIN = sDMNeg / sTR * 100I recall ages ago working up a decent backtest performance with the ‘Adaptive Indicator’, but the Algo got Rejected every time it ran due to ‘not enough historical data’ (yes, I did use Defparam PreLoadbars = 10000.
The error messages we see are not always ‘true to the words’ and I am thinking that this useless bit of code (STR) was causing my Rejection and also the problems now experienced by the OP / efahmy
02/20/2025 at 8:37 PM #244115Assuming that’s the source code:
https://www.tradingview.com/script/8TQl2WyE-Adaptive-ATR-ADX-Trend-V2-Strategy/
Then for line 35 mentionned by GraHal, I would keep it and go instead with brackets modified like this (equivalent to “no brackets”, but just for the sake of better visibility…):
1sTR = sTR[1] - (sTR[1]) / adxLen + trSame thing by the way for lines 37 and 38, which could be modified as follows:12sDMPos = sDMPos[1] - (sDMPos[1]) / adxLen + dmPossDMNeg = sDMNeg[1] - (sDMNeg[1]) / adxLen + dmNegTo be tested to see if it helps…1 user thanked author for this post.
02/20/2025 at 9:27 PM #244127I think the code should be adjusted like this:
Adaptive ATR ADX Trend123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147//PRC_Adaptive-ATR-ADX-Trend-v3//------------// Parameters//------------atrLen = 21m1 = 3.5 // ATR Multiplier - ADX Risingm2 = 1.75 // ATR Multiplier - ADX FallingadxLen = 14adxThresh = 30 // ADX ThresholdaboveThresh = 1 // Use ATR Falling Multiplier even if ADX is risinguseHeiken = 1 // Use Heiken-Ashi bars//------------// Source Data//------------source = MedianPrice//------------// ADX Calculation//------------hR = High - High[1]lR = -(Low - Low[1])IF hR > lR THENdmPos = MAX(hR, 0)ELSEdmPos = 0ENDIFIF lR > hR THENdmNeg = MAX(lR, 0)ELSEdmNeg = 0ENDIFsTR = (sTR[1] * (adxLen - 1) + TrueRange) / adxLensDMPos = (sDMPos[1] * (adxLen - 1) + dmPos) / adxLensDMNeg = (sDMNeg[1] * (adxLen - 1) + dmNeg) / adxLenDIP = sDMPos / sTR * 100DIN = sDMNeg / sTR * 100DX = ABS(DIP - DIN) / (DIP + DIN) * 100aadx = Average[adxLen](DX)//------------// Heiken-Ashi Calculation//------------IF BarIndex < 2 THENxClose = ClosexOpen = OpenELSExClose = TotalPricexOpen = (xOpen[1] + Close[1]) / 2ENDIFxHigh = MAX(High, MAX(xOpen, xClose))xLow = MIN(Low, MIN(xOpen, xClose))//------------// Trailing ATR Calculation//------------v1 = ABS(xHigh - Close[1])v2 = ABS(xLow - Close[1])v3 = xHigh - xLowtrueRange = MAX(v1, MAX(v2, v3))IF useHeiken THENatr = WilderAverage[atrLen](trueRange)ELSEatr = AverageTrueRange[atrLen]ENDIFIF aadx > aadx[1] AND (aadx < adxThresh OR NOT aboveThresh) THENm = m1ELSIF aadx < aadx[1] OR (aadx > adxThresh AND aboveThresh) THENm = m2ELSEm = m[1]ENDIFIF DIP >= DIN THENmUp = mELSEmUp = m2ENDIFIF DIN >= DIP THENmDn = mELSEmDn = m2ENDIF//------------// Trend Calculation//------------IF useHeiken THENsrc = xClosec = xCloset = (xHigh + xLow) / 2ELSEsrc = sourcec = Closet = MedianPriceENDIFup = t - mUp * atrdn = t + mDn * atrIF MAX(src[1], c[1]) > TUp[1] THENTUp = MAX(up, TUp[1])ELSETUp = upENDIFIF MIN(src[1], c[1]) < TDown[1] THENTDown = MIN(dn, TDown[1])ELSETDown = dnENDIF//------------// Trend Detection//------------IF MIN(src, MIN(c, Close)) > TDown[1] THENtrend = 1ELSIF MAX(src, MAX(c, Close)) < TUp[1] THENtrend = -1ELSEtrend = trend[1]ENDIFIF trend = 1 THENsstop = TUpr = 0g = 255ELSEsstop = TDownr = 255g = 0ENDIFIF trend <> trend[1] THENDRAWTEXT("•", BarIndex, sstop, Dialog, Standard, 30) COLOURED(r, g, 0)ENDIFRETURN sstop COLOURED(r, g, 0) STYLE(line,2)1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on
Nicolas, Can you explain the numerator logic – e.g. Line 35 is (sTR[1] – sTR[1]) which would appear to be either null or zero.