Steven Primo Indicator to Strategy
Forums › ProRealTime English forum › ProOrder support › Steven Primo Indicator to Strategy
- This topic has 12 replies, 2 voices, and was last updated 1 year ago by robertogozzi.
-
-
11/05/2023 at 4:16 PM #223217
Hi everyone, after a lot of work i finaly converted the Steven Primo bollinger Bands indicator from Tradingview to a prorealcode indicator and added some features.
i just want to convert this indicator in an autmated Strategy, if you can help, here is the code and i upload the indicator itf
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190DEFPARAM CalculateOnLastBars = 5000// Atributs :OffsetArrow = ArrowDistance * pipsizeOffsetText = TextDistance * pipsizeOffsetFifth = FifthDistance * pipsizeOffsetDistance = ContractDistance * pipsizeOffsetEntry = EntryText * pipsizePipi = pipsizeSMA50 = Average[50](close)// Conditions for Close > Bollinger UPindicator3 = Average[20](close)+0.382*std[20](close)c7 = (close > indicator3)SMA20 = Average[20](close)// Conditions for 5 Closes above Bollinger Upc9=SUMMATION[5](c7)=5if c9 and lastsig=0 then // and close > SMA50 then // Price above SMA50if FifthCandle thendrawtext("5",barindex,low-OffsetFifth,SansSerif,bold,25)coloured(0,200,0)lastsig=1endifendif//Setup Reset if closes under Boll Upif close<indicator3 thenlastsig=0endif// Conditions for Closes < Bollinger Downindicator4 = Average[20](close)-0.382*std[20](close)c8 = (close < indicator4)// Conditions for 5 Closes under Bollinger downc10=SUMMATION[5](c8)=5if c10 and lastsig2=0 then // and close < SMA50 then // Price below SMA50if FifthCandle thendrawtext("5",barindex,high+OffsetFifth,SansSerif,bold,25)coloured(200,0,0)lastsig2=1endifendif//Setup Reset if closes above Boll Downif close>indicator4 thenlastsig2=0endifatr14=averagetruerange[14]// BB setuplongComparison = close > indicator3shortComparison = close < indicator4if longComparison thenif countlong=0 and longComparison[1] thencountlong=0elsecountlong=countlong+1endifelsecountlong=0endifif shortComparison thenif countshort=0 and shortComparison[1] thencountshort=0elsecountshort=countshort+1endifelsecountshort=0endifpvHighInRange = barssince(pivothigh)<countlongpvLowInRange = barssince(pivotlow)<countshort// Pivot setuppivotH = high[1]>high[2] and high[1]>high //TV Script pivotHigh = ta.pivothigh(1, 1)pivotL = low[1]<low[2] and low[1]<low //TV Script pivotLow = ta.pivotlow(1, 1)if pivotH and High[1] = Highest[xPeriod](High) then // Parametrer le nombre de candles pour le pivot, quand je l'ai mis à 3 c presque comme TV mais ce qui est bien dans prorealtime c qu'il est sorti d'une position Long perdante et à tout de suite shorté quand le paramètrage le permettaitpivotHigh=high[1]starthigh=barindex[1]pivottype=1endifif pivotL and Low[1] = Lowest[xPeriod](Low) thenpivotLow=low[1]startlow=barindex[1]pivottype=-1endifpvHighInRange = barssince(pivothigh)<countlongpvLowInRange = barssince(pivotlow)<countshort// Entry priceepLong = (pivotHigh) + ticksizeepShort = (pivotLow) - ticksizestopLong = epShortstopShort = epLong// Target pricetargetLong = epLong+(abs(epLong-stopLong)*(extension/100))targetShort = epShort-(abs(epShort-stopShort)*(extension/100))contractSizeL = Risk/(epLong-stoplong)contractSizeS = Risk/(stopshort-epShort)// Entry condition//canBuy = countLong >= consecutiveCloses and pvHighInRange and high < epLong and epLong>0//canSell = countShort >= consecutiveCloses and pvLowInRange and low > epShort and epShort>0canBuy = countLong > consecutiveCloses and pvHighInRange and epLong>0 and high crosses over epLong and orderLong //and close > SMA50 // and SMA20>SMA50 //modif car tradingview repaint!!canSell = countShort > consecutiveCloses and pvLowInRange and epShort>0 and low crosses under epShort and orderShort// and close < SMA50 // and SMA20<SMA50 //modif car tradingview repaint!!//trading signalscontractSizeL = round(contractSizeL,2)contractSizeS = round(contractSizeS,2)atr = average[100](range)*0.25//AverageTrueRange[100](close)signal=0if canBuy and order<>1 and order <> -1 and signalBuy = 0 then // order <> 1 not longonmarket order <> -1 not shortonmarket, added signalBuy to tell him that we entered once the tradedrawarrowup(barindex,low-OffsetArrow) coloured("blue")drawtext("LONG",barindex,low-OffsetText,SansSerif,Bold,12) COLOURED(0,102,80)//drawtext(contractSizeL,barindex,low-OffsetDistance)//drawtext(pivothigh+0.1,barindex,low-OffsetEntry,SansSerif,Bold,10) COLOURED(204,0,204)drawtext(pivothigh+0.1,barindex[8],pivothigh,SansSerif,Bold,12) COLOURED(0,102,80)drawtext("▶",barindex[1],pivothigh) coloured("blue")drawtext("à",barindex[13],pivothigh,SansSerif,Bold,12) COLOURED(0,102,80)drawtext(contractSizeS,barindex[16],pivothigh,SansSerif,Bold,12) COLOURED(0,102,80)takeprofit=targetlongstoploss=stoplongorder = 1 //on marketorderlevel = pivothighorderbar = barindexsignalBuy = 1 // signal now = 1 because we had a trade and in the line 112 signalBuy was = 0 , to avoid an another trade we must have signalBuy = 0 that's why in line 141 i added if close crosses under indicator3 signalBuy = 0 and now he can enter an another trade if all conditions were metelsif canSell and order<>-1 and order <> 1 and signalSell = 0 then // order <> 1 not longonmarket order <> -1 not shortonmarketdrawarrowdown(barindex,high+OffsetArrow) coloured("red")drawtext("SHORT",barindex,high+OffsetText,SansSerif,Bold,12) COLOURED(240,0,10)//drawtext(contractSizeS,barindex,high+OffsetDistance)drawtext(contractSizeS,barindex[16],pivotlow,SansSerif,Bold,12) COLOURED(240,0,10)//drawtext(pivotlow-0.1,barindex,high+OffsetEntry,SansSerif,Bold,10) COLOURED(204,0,204)drawtext("à",barindex[13],pivotlow,SansSerif,Bold,12) COLOURED(240,0,10)drawtext(pivotlow-0.1,barindex[8],pivotlow,SansSerif,Bold,12) COLOURED(240,0,10)drawtext("◀",barindex+1,pivotlow) coloured("red")signal=-1takeprofit=targetshortstoploss=stopshortorder = -1 //on marketorderlevel = pivotloworderbar = barindexsignalSell = 1endifif close < indicator3 then // to tell him that we reset the SetupsignalBuy = 0endifif close > indicator4 thensignalSell = 0endif//if canbuy and not onmarket then//BUY 1 shares at market//ENDIF//plot the tp & sl linesif order<>0 thendrawsegment(orderbar,takeprofit,barindex,takeprofit) coloured("darkgreen") style(line,2)drawtext(takeprofit,orderbar-5,takeprofit)drawsegment(orderbar,stoploss,barindex,stoploss) coloured("red") style(line,2)drawtext(stoploss,orderbar-5,stoploss)endif//reset the order/tp/slif order=1 then //case longif high crosses over takeprofit or low crosses under stoploss thenorder=0drawarrowdown(barindex,high+OffsetArrow) coloured("BlueViolet")drawtext("Exit L",barindex,high+OffsetText)endifendif//if order=1 then // Trying to Put YES for Winning Trades//if high crosses over takeprofit then//drawtext("YES",barindex+1,takeprofit+atr*8) coloured(0,255,0)//endif//endifif order=-1 then //case shortif low crosses under takeprofit or high crosses over stoploss thenorder=0drawarrowup(barindex,low-OffsetArrow) coloured("BlueViolet")drawtext("Exit S",barindex,low-OffsetText)endifendifColorBetween (indicator3,indicator4,255,153,255,110)return indicator3 as "Upper band" coloured(128,0,92), indicator4 as "Lower band" coloured(128,0,92), SMA20 as "MA20" coloured(255,0,0), signalBuy as "LONG", signalSell as "SHORT"11/05/2023 at 6:25 PM #223223Yes please, attach the ITF file, if possible.
11/05/2023 at 6:45 PM #22322811/05/2023 at 7:56 PM #22323411/08/2023 at 1:41 PM #223364There you go:
123456789101112DEFPARAM CumulateOrders = Falsep1,p2,p3,p4,p5 = CALL "Projet Primo 382 a 90%"[0, 5, 100, 0, 0, 50, 3, 6, 8, 10, 9, 1, 10](close)c1 = (close CROSSES OVER p1)c2 = (close CROSSES UNDER p1)IF c1 AND Not LongOnMarket THENBUY 1 CONTRACT AT MARKETENDIFIF c2 AND Not ShortOnMarket THENSELLSHORT 1 CONTRACT AT MARKETENDIFSET STOP %LOSS 1SET TARGET %PROFIT 211/08/2023 at 2:29 PM #22336811/08/2023 at 3:58 PM #223371It’s just an example. You can change it as you like.
If you post the conditions to enter Long and Short trades, to set SL and TP, I will code them.
11/12/2023 at 4:21 PM #223607From the Line 69 you can see that both Target and Stoploss are based on the Pivothigh or Pivotlow calculated with the variable xperiod that i can changed; here is the code from line 69:
123456789101112131415161718// Pivot setuppivotH = high[1]>high[2] and high[1]>high //TV Script pivotHigh = ta.pivothigh(1, 1)pivotL = low[1]<low[2] and low[1]<low //TV Script pivotLow = ta.pivotlow(1, 1)if pivotH and High[1] = Highest[xPeriod](High) then // Parametrer le nombre de candles pour le pivot, quand je l'ai mis à 3 c presque comme TV mais ce qui est bien dans prorealtime c qu'il est sorti d'une position Long perdante et à tout de suite shorté quand le paramètrage le permettaitpivotHigh=high[1]starthigh=barindex[1]pivottype=1endifif pivotL and Low[1] = Lowest[xPeriod](Low) thenpivotLow=low[1]startlow=barindex[1]pivottype=-1endifpvHighInRange = barssince(pivothigh)<countlongpvLowInRange = barssince(pivotlow)<countshort11/12/2023 at 4:49 PM #22360911/12/2023 at 4:57 PM #22361012/02/2023 at 5:12 PM #224730The indicator does not plot and does not return any value for pivots, just the bands and signals.
I coded the Pivot points inside the strategy:
12345678910111213141516171819202122232425DEFPARAM CumulateOrders = FalseONCE xPeriod = 20UpperBand,LowerBand,Sma20,signalBuy,signalSell = CALL "Projet Primo 382 a 90%"[0, 5, 100, 0, 0, 50, 3, 6, 8, 10, 9, xPeriod, 10](close)c1 = (close CROSSES OVER LowerBand) //UpperBandc2 = (close CROSSES UNDER UpperBand) //LowerBandpivotH = high[1]>high[2] and high[1]>high and High[1] = Highest[xPeriod](High)IF PivotH THENstopH = high[1]EndifpivotL = low[1]<low[2] and low[1]<low and Low[1] = Lowest[xPeriod](Low)IF PivotL THENstopL = low[1]EndifIF c1 AND not OnMarket THENBUY 1 CONTRACT AT MARKETSET STOP PRICE stopLSET TARGET PRICE close + abs(close - stopL)ENDIFIF c2 AND not OnMarket THENSELLSHORT 1 CONTRACT AT MARKETSET STOP PRICE stopHSET TARGET PRICE close - abs(close - stopH)ENDIF//graphonprice stopH coloured("Green")//graphonprice stopL coloured("Red")12/03/2023 at 1:41 PM #22475012/03/2023 at 6:35 PM #224768CALL is the instruction to get data from indicators.
Indicators receive the data to make calculations in square brackets, those data must match the number of variables declared in the indicator.
The variables to the left of the “=” (assignment operator) are the place where data RETURNed from indicator is stored (they must be in the same order order as they are written next to RETURN, though their names can be different from those in the indicator).
-
AuthorPosts
Find exclusive trading pro-tools on