Pine script conversion using ChatGPT 4
Forums › ProRealTime English forum › General trading discussions › Pine script conversion using ChatGPT 4
- This topic has 41 replies, 7 voices, and was last updated 1 year ago by LucasBest.
-
-
09/11/2023 at 10:44 PM #220818
Spent few hours with chatgpt helping me (or maybe i was helping him?:-)) to translate an indicator from tradingview.
Finally we did it, but it tooks twice or 3 times more times than if i did it alone…
Original code : https://fr.tradingview.com/script/5zoE62bC-TKP-T3-Trend-With-Psar-Barcolor/
TKP T3 Trend With Psar Barcolor123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272//this script is intended to help identify reversals and attempt to anticiapate them. Psar and Tilson templates are from Chris Moody and TKP Trader//@Bjorgum on Stocktwits//Bull trends are identified by blue bars, while bear trades are identified by red. Points of reversal are indicated with yellow candles.//Bars change to yellow as bar close crosses the Tilson moving averages. Blue or red is confrimed as the two Tilson avergaes themselves cross.//Buy and sell signal is given on yellow bars//TURN CANDLE BORDERS OFF//Psar helps identify reversals and provide stop loss values//Arrows appear above or below candles to incorporate a momentum aspect. This condition is based on a rising or falling TSI value while under or over the signal line.//This can show momentum 'headwinds' or 'tailwinds' as TSI 'curls'.//@version=4// TSI Inputsshort = 5signal = 14// Calculate TSIpc = close - close[1]// Calculate double smoothed PCfirstsmooth = ExponentialAverage[long](pc)doublesmoothedpc = ExponentialAverage[short](firstsmooth)// Calculate double smoothed absolute PCabspc = abs(pc)firstsmoothabs = ExponentialAverage[long](abspc)doublesmoothedabspc = ExponentialAverage[short](firstsmoothabs)tsivalue = 100 * (doublesmoothedpc / doublesmoothedabspc)// Calculate Signalsdata = tsivalue > tsivalue[1] AND tsivalue < ExponentialAverage[signal](tsivalue)dtat = tsivalue < tsivalue[1] AND tsivalue > ExponentialAverage[signal](tsivalue)// Define ATRatr = AverageTrueRange[14](close)// Plot Upward-Pointing Triangle using drawtext for "Curl Up" with color "green"IF data THENDRAWTEXT("▴", barindex, low - atr / 2, dialog, bold, 25) coloured(0, 255, 0, 255)ENDIF// Plot Downward-Pointing Triangle using drawtext for "Curl Down" with color "orange"IF dtat THENDRAWTEXT("▾", barindex, high + atr / 2, dialog, bold, 25) coloured(255, 165, 0, 255)ENDIF// Parabolic Stop and ReversestartValue = 0.043incrementValue = 0.043maximumValue = 0.34// Calculate PSARsarUp = SAR[startValue, incrementValue, maximumValue]sarDown = SAR[startValue, incrementValue, maximumValue]// Define ColorscolUpR = 100colUpG = 181colUpB = 246colDownR = 239colDownG = 83colDownB = 80// Condition to check if close is greater or equal to sarDownIF close >= sarDown THENDRAWPOINT(barindex, sarUp, 3) coloured(colUpR, colUpG, colUpB, 255)ENDIF// Condition to check if close is less or equal to sarUpIF close <= sarUp THENDRAWPOINT(barindex, sarDown, 3) coloured(colDownR, colDownG, colDownB, 255)ENDIF// T3 MA5aLength = 5AxPrice = closeaxe1 = ExponentialAverage[aLength](AxPrice)axe2 = ExponentialAverage[aLength](axe1)axe3 = ExponentialAverage[aLength](axe2)axe4 = ExponentialAverage[aLength](axe3)axe5 = ExponentialAverage[aLength](axe4)axe6 = ExponentialAverage[aLength](axe5)ab = 0.7ac1 = -ab * ab * abac2 = 3 * ab * ab + 3 * ab * ab * abac3 = -6 * ab * ab - 3 * ab - 3 * ab * ab * abac4 = 1 + 3 * ab + ab * ab * ab + 3 * ab * abanT3Average = ac1 * axe6 + ac2 * axe5 + ac3 * axe4 + ac4 * axe3p2 = anT3AveragecolOne = anT3Average > anT3Average[1]colTwo = anT3Average < anT3Average[1]IF colOne THENT3ColorR = 100T3ColorG = 181T3ColorB = 246ELSIF colTwo THENT3ColorR = 239T3ColorG = 83T3ColorB = 80ELSET3ColorR = undefinedT3ColorG = undefinedT3ColorB = undefinedENDIF// T3 MA8Length = 8xPrice = closexe1 = ExponentialAverage[Length](xPrice)xe2 = ExponentialAverage[Length](xe1)xe3 = ExponentialAverage[Length](xe2)xe4 = ExponentialAverage[Length](xe3)xe5 = ExponentialAverage[Length](xe4)xe6 = ExponentialAverage[Length](xe5)b = 0.7c1 = -b * b * bc2 = 3 * b * b + 3 * b * b * bc3 = -6 * b * b - 3 * b - 3 * b * b * bc4 = 1 + 3 * b + b * b * b + 3 * b * bnT3Average = c1 * xe6 + c2 * xe5 + c3 * xe4 + c4 * xe3p1 = nT3AverageupCol = nT3Average > nT3Average[1]downCol = nT3Average < nT3Average[1]IF upCol THENmyColorR = 100myColorG = 181myColorB = 246ELSIF downCol THENmyColorR = 239myColorG = 83myColorB = 80ELSEmyColorR = undefinedmyColorG = undefinedmyColorB = undefinedENDIF// T3 area fillfillData = nT3Average < anT3AveragefillDtat = nT3Average > anT3AverageIF fillData THENFillColorR = 100FillColorG = 181FillColorB = 246ELSIF fillDtat THENFillColorR = 239FillColorG = 83FillColorB = 80ELSEFillColorR = undefinedFillColorG = undefinedFillColorB = undefinedENDIFCOLORBETWEEN(nT3Average, anT3Average, FillColorR, FillColorG, FillColorB, 80)// Heikin-Ashi Bar InputhaClose = (open + high + low + close) / 4haOpen = (open + close) / 2IF NOT haOpen[1] = undefined THENhaOpen = (haOpen[1] + haClose[1]) / 2ENDIFhaHigh = MAX(high, MAX(haOpen, haClose))haLow = MIN(low, MIN(haOpen, haClose))// Define colorsBullTrendColorR = 100BullTrendColorG = 181BullTrendColorB = 246BearTrendColorR = 239BearTrendColorG = 83BearTrendColorB = 80BullReversalColorR = 255BullReversalColorG = 241BullReversalColorB = 118BearReversalColorR = 255BearReversalColorG = 241BearReversalColorB = 118// Bar Coloruc = (close > nT3Average) AND (anT3Average >= nT3Average)dc = (close < nT3Average) AND (anT3Average <= nT3Average)dr = (close < nT3Average) AND (anT3Average >= nT3Average)ur = (close > nT3Average) AND (anT3Average <= nT3Average)hauc = (haClose > nT3Average) AND (anT3Average >= nT3Average)hadc = (haClose < nT3Average) AND (anT3Average <= nT3Average)hadr = (haClose < nT3Average) AND (anT3Average >= nT3Average)haur = (haClose > nT3Average) AND (anT3Average <= nT3Average)hadu = haClose >= haOpenhadd = haClose < haOpenIF uc THENBarColorR = BullTrendColorRBarColorG = BullTrendColorGBarColorB = BullTrendColorBELSIF dc THENBarColorR = BearTrendColorRBarColorG = BearTrendColorGBarColorB = BearTrendColorBELSIF dr THENBarColorR = BearReversalColorRBarColorG = BearReversalColorGBarColorB = BearReversalColorBELSIF ur THENBarColorR = BullReversalColorRBarColorG = BullReversalColorGBarColorB = BullReversalColorBELSEBarColorR = undefinedBarColorG = undefinedBarColorB = undefinedENDIF// Heikin-Ashi Bar ColorIF hauc THENHABarColorR = BullTrendColorRHABarColorG = BullTrendColorGHABarColorB = BullTrendColorBELSIF hadc THENHABarColorR = BearTrendColorRHABarColorG = BearTrendColorGHABarColorB = BearTrendColorBELSIF hadr THENHABarColorR = BearReversalColorRHABarColorG = BearReversalColorGHABarColorB = BearReversalColorBELSIF haur THENHABarColorR = BullReversalColorRHABarColorG = BullReversalColorGHABarColorB = BullReversalColorBELSIF hadu THENHABarColorR = BullTrendColorRHABarColorG = BullTrendColorGHABarColorB = BullTrendColorBELSEHABarColorR = BearTrendColorRHABarColorG = BearTrendColorGHABarColorB = BearTrendColorBENDIFhaover = 0 // Overlays HA bars in place of regular candles.rPrice = 0 // Displays 'real close' levelIF haover THENDRAWCANDLE(haOpen, haHigh, haLow, haClose) COLOURED(HABarColorR, HABarColorG, HABarColorB, 255)ELSEDRAWCANDLE(haOpen, haHigh, haLow, haClose) COLOURED(255, 255, 255, 255) // Default color (white) when haover is not active.ENDIFIF rPrice THENDRAWsegment(barindex - 1, close, barindex, close) COLOURED(HABarColorR, HABarColorG, HABarColorB, 255) // Displaying the real close levelENDIFc = (close > nT3Average[1] AND close[1] < nT3Average) OR (close < nT3Average[1] AND close[1] > nT3Average)d = (nT3Average > anT3Average[1] AND nT3Average[1] < anT3Average) OR (nT3Average < anT3Average[1] AND nT3Average[1] > anT3Average)// These conditions can be used in ProRealTime to create alerts.RETURN nT3Average coloured(myColorR, myColorG, myColorB, 255), anT3Average coloured(T3ColorR, T3ColorG, T3ColorB, 255)3 users thanked author for this post.
09/13/2023 at 12:25 PM #22093009/13/2023 at 12:45 PM #22093409/13/2023 at 3:49 PM #22096409/13/2023 at 4:27 PM #220967manque la variable : long
Sorry, don”t know how it was working without…
Nevermind, you can add line 14 : long = 2509/14/2023 at 2:33 PM #221026Thanks a lot; what prompt did you use?
09/17/2023 at 8:14 AM #221145Whatever the prompt i use at the begining Chatgpt does a lot of errors, syntax errors and confusion between the different languages (for example, it sometimes creats new instruction when it does not know how to translate to probuilder…)
What i don’t like is that sometimes it seems to forget all i’ve said before and does simple syntax errors it did not before… Weird! AI they said? Then Ai is dumb from time to time…
For functions, the prompt that seems to work is to tell him : whenever you meet a function, do not translate it because probuilder dos not support functions yet, but instead apply the logic of the function each time the pine script will call the function later in the code.
Also, chatgpt (v4) is not comfortable with probuilder when it comes to ploting… So it often needs some hints to know which instructions to use for plotting (Drawsegment, drawcandle, drawpoint, drawtext or simply return…)
When it comes to color, i tell him to split colors in 3 differents variables with r g and b values.
I tried to feed him with a list of all instructions that exist in probuilder, but his level in prorealtime coding remain the same from my point of view…
1 user thanked author for this post.
09/17/2023 at 8:43 AM #221154For example, for the conversion of this code which is rather simple, i had to help him a lot, as it was lost with nz() and na() instructions and how to translate them (even with using if then else). It tooks more than 3 hours while i would have need only 1h to do it without chatgpt…
L3 Banker Fund Flow Trend Osci123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100If Barindex >35 then// First xsa call:srcValue1 = 100*(close - Lowest[27](low)) / (Highest[27](high) - Lowest[27](low))lenValue1 = 5weiValue1 = 1sumf1 = 0ma1 = 0out1 = 0sumf1 = (not (sumf1[1] = undefined)) * sumf1[1] - ((not (srcValue1[lenValue1] = undefined)) * srcValue1[lenValue1] + srcValue1)ma1 = not (srcValue1[lenValue1] = undefined) * (sumf1 / lenValue1)IF out1[1] = 0 THENout1 = ma1ELSEout1 = (srcValue1 * weiValue1 + out1[1] * (lenValue1 - weiValue1)) / lenValue1ENDIF// Now, 'out1' is the result of the first xsa.// Second xsa call with out1 as the input:srcValue2 = out1lenValue2 = 3weiValue2 = 1sumf2 = 0ma2 = 0out2 = 0sumf2 = (NOT (sumf2[1] = UNDEFINED)) * sumf2[1] - ((NOT (srcValue2[lenValue2] = UNDEFINED)) * srcValue2[lenValue2] + srcValue2)ma2 = not (srcValue2[lenValue2] = UNDEFINED) * (sumf2 / lenValue2)IF out2[1] = UNDEFINED THENout2 = ma2ELSEout2 = (srcValue2 * weiValue2 + out2[1] * (lenValue2 - weiValue2)) / lenValue2ENDIF// Now, 'out2' is the result of the second xsa.// Fund trend final calculation:fundtrend = (3 * out1 - 2 * out2 - 50) * 1.032 + 50// Defining typical price for banker fundtyp = (2*close + high + low + open) / 5// Lowest low with mid term fib # 34lol = lowest[34](low)// Highest high with mid term fib # 34hoh = highest[34](high)// Define banker fund flow bull bear linebullbearline = exponentialaverage[13]((typ - lol) / (hoh - lol) * 100)// Define banker entry signal using 'crosses over'bankerentry = (fundtrend crosses over bullbearline) AND bullbearline < 25//banker fund entry with yellow candleIF bankerentry THENDRAWCANDLE(0, 50, 0, 50) COLOURED(255,255,0)// Yellow colorENDIF//banker increase position with green candleIF fundtrend > bullbearline THENDRAWCANDLE(fundtrend, bullbearline, fundtrend, bullbearline) COLOURED(0,255,0) // Green colorENDIF//banker decrease position with white candleIF fundtrend < (fundtrend[1] * 0.95) THENDRAWCANDLE(fundtrend, bullbearline, fundtrend, bullbearline) COLOURED(255,255,255)// White colorENDIF//banker fund exit/quit with red candleIF fundtrend < bullbearline THENDRAWCANDLE(fundtrend, bullbearline, fundtrend, bullbearline) COLOURED(255,0,0) // Red colorENDIF//banker fund Weak rebound with blue candleIF fundtrend < bullbearline AND fundtrend > (fundtrend[1]*0.95) THENDRAWCANDLE(fundtrend, bullbearline, fundtrend, bullbearline) COLOURED(0,0,255) // Blue colorENDIFh1 = 80h2 = 20h3 = 10h4 = 90// Coloring between the linescolorbetween(h1, h4, 255, 0, 255, 100) // Fuchsia shade between 80 and 90colorbetween(h2, h3, 255, 255, 0, 100) // Yellow shade between 20 and 10EndifRETURN h1 style(line,1) coloured(255,0,0), h2 style(line,1) coloured(255,255,0), h3 style(line,1) coloured(0,255,0), h4 style(line,1) coloured(255,0,255)09/17/2023 at 11:16 AM #22115809/17/2023 at 11:45 AM #221159Hola Lucas
I don’t see a yellow candle for entry in position ? have you an example please
this indicator feel good !
have a nice day.
I made the conversion yesteerday of 3 or 4 indicators, so i had no time to test them yet.
But, i think yellow candle does not appears very often also in the original post on tradingview :
https://www.tradingview.com/script/791WkWcm-blackcat-L3-Banker-Fund-Flow-Trend-Oscillator/As you can see, even while scrolling left and right the chart, yellow candle appears only once.
It is because of line 62 :
bankerentry = (fundtrend crosses over bullbearline) AND bullbearline < 25 You need to have a cross over while bullbearline is below 25. What you can do is to add a variable call it SupertitiThrshold = 25 (by default) Change line 62 : bankerentry = (fundtrend crosses over bullbearline) AND bullbearline < SupertitiThrshold Then play in configuration table with that SupertitiThrshold until you see as much yellow candle as you would like09/17/2023 at 12:20 PM #221161Hola a todos,
Here is the screener for the white candlesticks above 80…
Que disfruteis
// L3 BANKER WHITE SCREENER by DID 17.09.2023
// L3 BANKER FUND FLOW TREND OSCILLATOR by Lucasbest 17.09.2023
// defparam calculateonlastbars = 150
If Barindex >35 then
// First xsa call:
srcValue1 = 100*(close – Lowest[27](low)) / (Highest[27](high) – Lowest[27](low))
lenValue1 = 5
weiValue1 = 1sumf1 = 0
ma1 = 0
out1 = 0sumf1 = (not (sumf1[1] = undefined)) * sumf1[1] – ((not (srcValue1[lenValue1] = undefined)) * srcValue1[lenValue1] + srcValue1)
ma1 = not (srcValue1[lenValue1] = undefined) * (sumf1 / lenValue1)
IF out1[1] = 0 THEN
out1 = ma1
ELSE
out1 = (srcValue1 * weiValue1 + out1[1] * (lenValue1 – weiValue1)) / lenValue1
ENDIF// Now, ‘out1’ is the result of the first xsa.
// Second xsa call with out1 as the input:
srcValue2 = out1
lenValue2 = 3
weiValue2 = 1
sumf2 = 0
ma2 = 0
out2 = 0sumf2 = (NOT (sumf2[1] = UNDEFINED)) * sumf2[1] – ((NOT (srcValue2[lenValue2] = UNDEFINED)) * srcValue2[lenValue2] + srcValue2)
ma2 = not (srcValue2[lenValue2] = UNDEFINED) * (sumf2 / lenValue2)
IF out2[1] = UNDEFINED THEN
out2 = ma2
ELSE
out2 = (srcValue2 * weiValue2 + out2[1] * (lenValue2 – weiValue2)) / lenValue2
ENDIF// Now, ‘out2’ is the result of the second xsa.
// Fund trend final calculation:
fundtrend = (3 * out1 – 2 * out2 – 50) * 1.032 + 50// Defining typical price for banker fund
typ = (2*close + high + low + open) / 5// Lowest low with mid term fib # 34
lol = lowest[34](low)// Highest high with mid term fib # 34
hoh = highest[34](high)// Define banker fund flow bull bear line
bullbearline = exponentialaverage[13]((typ – lol) / (hoh – lol) * 100)// Define banker entry signal using ‘crosses over’
bankerentry = (fundtrend crosses over bullbearline) AND bullbearline < 25//banker fund entry with yellow candle
IF bankerentry THEN
//DRAWCANDLE(0, 50, 0, 50) COLOURED(255,255,0)// Yellow color
ENDIF//banker increase position with green candle
IF fundtrend > bullbearline THEN
//DRAWCANDLE(fundtrend, bullbearline, fundtrend, bullbearline) COLOURED(0,255,0) // Green color
ENDIF//banker decrease position with white candle
IF fundtrend < (fundtrend[1] * 0.95) THEN
//DRAWCANDLE(fundtrend, bullbearline, fundtrend, bullbearline) COLOURED(255,255,255)// White color
ENDIF//banker fund exit/quit with red candle
IF fundtrend < bullbearline THEN
//DRAWCANDLE(fundtrend, bullbearline, fundtrend, bullbearline) COLOURED(255,0,0) // Red color
ENDIF//banker fund Weak rebound with blue candle
IF fundtrend < bullbearline AND fundtrend > (fundtrend[1]*0.95) THEN
//DRAWCANDLE(fundtrend, bullbearline, fundtrend, bullbearline) COLOURED(0,0,255) // Blue color
ENDIF//h1 = 80
//h2 = 20
//h3 = 10
//h4 = 90// Coloring between the lines
//colorbetween(h1, h4, 255, 0, 255, 100) // Fuchsia shade between 80 and 90
//colorbetween(h2, h3, 255, 255, 0, 100) // Yellow shade between 20 and 10Endif
//RETURN h1 style(line,1) coloured(255,0,0), h2 style(line,1) coloured(255,255,0), h3 style(line,1) coloured(0,255,0), h4 style(line,1) coloured(255,0,255)
//Entrée du banquier dans le fonds avec une bougie jaune
//augmentation de la position de la banque avec la bougie verte
//Banker diminue sa position avec une bougie blanche
//Sortie du fonds bancaire/quit avec la bougie rouge
//Fonds bancaire Faible rebond avec la bougie bleue
C1 = fundtrend >80
C2 = fundtrend < (fundtrend[1] * 0.95)SCREENER [C1 and C2 ]
09/17/2023 at 2:15 PM #221167Sometimes ChatGPT is funny… Or maybe upset as i made him work to much ? See below his last answer :
“If you’re serious about porting this over to ProBuilder, you might consider working with a developer familiar with both Pine Script and ProBuilder to ensure accurate and functional translation.”2 users thanked author for this post.
09/18/2023 at 8:28 AM #221185Just a tip, this kind of “direct” translation from Pinescript is not accurate :
ma1 = not (srcValue1[lenValue1] = undefined) * (sumf1 / lenValue1)
(in this case you are multiplying the result of the boolean with (sumf1 / lenValue1) )The original code was using a single conditional statement within a single line, and with (na) testing:
ma := na(src[len]) ? na : sumf/lenIMO, it should be coded as below:
ma = undefined
if srcValue1[lenValue1] >0 then
ma = sumf/len
endif1 user thanked author for this post.
09/18/2023 at 8:42 AM #22118609/18/2023 at 9:19 AM #221190To be clear, think of this:
ma := na(src[len]) ? na : sumf/len
as this:
if IsNaN(src[len]) then ma = NaN else ma = sumf / len
in ProBuilder, there is no “NaN” state (Not a Number) by default, until you declare a variable as UNDEFINED. So it is better to test if it’s equal to 0, because all variables equal to 0 at start of code.
Sometimes it is useful to set a variable to UNDEFINED, to make it not visible on chart until its first calculation for instance, but keep in mind, that UNDEFINED can only be assign once.
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on