Sounds wrong coding, anyone can help pls
Forums › ProRealTime English forum › ProOrder support › Sounds wrong coding, anyone can help pls
- This topic has 12 replies, 7 voices, and was last updated 1 month ago by
LucasBest.
-
-
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.
02/21/2025 at 8:56 PM #24418002/21/2025 at 10:47 PM #244182Regarding the original error message, and just for future reference, I think this is what’s happening.
In a INDICATOR, if you just return a variable like, a[1], via the return line, you get the ‘Variable is Undefined’ error message.
Alternatively, if in the main code you have a=a[1], and Return a, the code will run, but the line for ‘a’ doesn’t display in the chart.
I believe this is because, on the first bar, Barindex = 0, the value of a[1] is undefined still, so there’s no value to display from the bar before bar zero.
This means that the equation evaluates to undefined, and maybe on the following bars the prior value is always undefined because of the prior attempted calculation.
In back-test, the a=a[1] does the same, the code runs, however, if you graph ‘a’, again no line is drawn for the variable, because it’s undefined, similar to above.
One way to check if variables are defined in the back-test code is to Graph them and look if their line displays/appears.
It’s worth noting that, if you don’t assign a value/variable to a variable, then you get the red ‘~’ line in the editor and the ‘Unknown Command’ error message if you try to ‘ADD’.
But you don’t get it is you assign a variable with a undefined variable, like here to the bar before zero.
Now in ProOrder, apart from only a couple of options, there’s no user/ext interaction with the strategy, any error will ‘Stop’ the strategy.
However, since the code is only run once a bar, it’s not until the end of the bar the strategy was started on, the Strategy is ‘Stopped’.
On small timeframes, that would be quite quick, but on long timeframe it will be slow, both could get impression that they worked for a while, before they don’t.
In fact the the strategy is not tried till the start next new bar.
In this case, the above called indicator must have return an undefined value, which triggered the strategy to STOP.
So the ‘ server.strategy.probacktest.error.missing_data.call’ must mean, an undefined value was returned from the call’ed file.
If this undefined variable scenario happens with out a call file, you get the error message,
‘The Trading system was stopped because the historical data loaded was insufficient to
calculate at least one indicator during the evaluation of the last candlestick.’
Leading you to a problem with PRELOADBARS.
If you cannot retrieve a value from before bar zero, no amount of PLB’s will cure problem.
The simple explanation is just a undefined variable, trying to retrieve a value from the previous bar to bar zero.
In the original TV code, the variables were parameters of the called ‘nv()’ function.
This function defaulted the variable to zero, I believe, if it was undefined or NAN, this zero value allowed the equation to derive a proper result value.
In proOrder, you get a ‘Stopped’ system, and the usual cryptic message, unless your lucky.
Regards all
1 user thanked author for this post.
02/24/2025 at 10:54 AM #244278So after druby superlative analysis of the problem … if you change Lines 35 to 38 (in JS code above) to below … Rejection for ‘historical data loaded was insufficient‘ does not occur!
Now I understand why ‘If barindex > 2’ is a fix! 🙂 I have used it before to stop Rejections in other strategies, but on an intuitive basis, now I have the full understanding as to why it is a fix!
Big Thank You to …
js for the code amendment.
druby for the analysis of [1] undefined / Strategy Rejection.12345If barindex > 2 ThensTR = (sTR[1] * (adxLen - 1) + TrueRange) / adxLensDMPos = (sDMPos[1] * (adxLen - 1) + dmPos) / adxLensDMNeg = (sDMNeg[1] * (adxLen - 1) + dmNeg) / adxLenEndif02/24/2025 at 11:17 AM #244279Try 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
First sTR need to be defined first or in a different way than by its previous value…
(sTR[1] – sTR[1]) = 0 🙂
Mean sTR = 0 anytime…
Then sTR is used to divide which means division by 0…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.