Need strategy for backtesting of automated
Forums › ProRealTime English forum › ProOrder support › Need strategy for backtesting of automated
- This topic has 5 replies, 2 voices, and was last updated 2 days ago by cavineet.
-
-
01/12/2025 at 5:15 AM #242430
Hello,
Can I have an automated strategy for the indicator with the below conditions so that I can backtest the results?
Condition 1:
If the price close above super trend average, THEN
BUY on Blue candle OR color change from Red Candle to white (whichever comes first). SELL (Close) on color change (white or red whatever comes first)
If price close is below super trend average, THEN
SELL on Red OR color change from Blue to white (whichever comes first). BUY (Close) on color change (white or blue whichever comes first)
Attached below 3 files:
1) Code for indicator, PRC_PerfectTrendLine-2. It consists of 3 candles with colors Blue, Red and White. Blue is like green candle, and white is advance indication
2) Code for Super-Trended-Moving-Averages
3) Screenshot of conditions
Thanks for help!
01/14/2025 at 1:49 PM #242544Hi. Here you have the long trades version
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186// --- settingsSlowLength = 7 // Slow lengthFastLength = 3 // Fast length// --- end of settingsfasthigh = Highest[SlowLength](high)//[1]fastlow = Lowest[SlowLength](low)//[1]slowhigh = Highest[FastLength](high)//[1]slowlow = Lowest[FastLength](low)//[1]if high<slowhigh thenthighs=slowhighelsethighs=highendifif low>slowlow thentlows=slowlowelsetlows=lowendifif high<fasthigh thenthighf=fasthighelsethighf=highendifif low>fastlow thentlowf=fastlowelsetlowf=lowendifif close>slowln[1] thenslowln=tlowselseslowln=thighsendifif close>fastln[1] thenfastln=tlowfelsefastln=thighfendifonce trend1=-1if close<slowln and close<fastln thentrend1=1endifif close>slowln and close>fastln thentrend1=0endifif trend1<>trend[1] thenif trend1=0 thenr=30g=144b=255elser=200g=20b=60endifendifsrc = Close //Data typemav = 1 //Moving Average Value: 0=SMA, 1=EMA, 2=WMA, 3=DEMA, 4=TMA, 5=VAR, 6=WWMA, 7=ZLEMA, 8=TSF, 9=HMA, 10=T3length = 100 //Moving Average LengthPeriods = 10 //ATR periodMultiplier = 0.5 //ATR MultiplierT3a1 = 0.7 //Tillson T3 Volume Factorvalpha = 2 / (length+1)If src > src[1] then //Green candlevud1 = src - src[1] //Green profitelsevud1 = 0EndIfIf src < src[1] then //Red candlevdd1 = src[1] - src //Red Losselsevdd1=0EndIfvUD = Summation[9](vud1) //Summation [9] Green profitvDD = Summation[9](vdd1) //Summation [9] Red LossvCMO = ((vUD - vDD) / vUD + vDD) //Cumulative Market OscillatorOnce VAR = 0VAR = (valpha * Abs(vCMO) * src) + (1 - valpha * Abs(vCMO)) * VAR[1]xDEMA = 2 * ExponentialAverage[length](src) - ExponentialAverage[length](ExponentialAverage[length](src))wwalpha = 1 //LengthOnce WWMA = 0WWMA = wwalpha * src + (1 - wwalpha) * WWMA[1]If (length / 2) = Round(length / 2) then //Check even/odd length for "zero lag"zxLag = (length / 2)ElsezxLag = ((length-1) / 2)EndIfzxEMAData = src + src - src[zxLag]xZLEMA = ExponentialAverage[length](zxEMAData) //Zero Lag Exponential Averagelrc = LinearRegression[length](src)lrc1 = lrc[1]lrs = lrc - lrc1TSF = LinearRegression[length](src) + lrs //Time Series ForecastHMA = WeightedAverage[Round(SQRT(length))](2 * WeightedAverage[length/2](src) - WeightedAverage[length](src)) //Hull Moving AverageT3e1 = ExponentialAverage[length](src)T3e2 = ExponentialAverage[length](T3e1)T3e3 = ExponentialAverage[length](T3e2)T3e4 = ExponentialAverage[length](T3e3)T3e5 = ExponentialAverage[length](T3e4)T3e6 = ExponentialAverage[length](T3e5)T3c1 = -T3a1 * T3a1 * T3a1T3c2 = 3 * T3a1 * T3a1 + 3 * T3a1 * T3a1 * T3a1T3c3 = -6 * T3a1 * T3a1 - 3 * T3a1 - 3 * T3a1 * T3a1 * T3a1T3c4 = 1 + 3 * T3a1 + T3a1 * T3a1 * T3a1 + 3 * T3a1 * T3a1T3 = T3c1 * T3e6 + T3c2 * T3e5 + T3c3 * T3e4 + T3c4 * T3e3 //T3 Moving AverageOnce MA = 0If mav = 0 thenMA = Average[length,0](src) //SMAElsIf mav = 1 thenMA = Average[length,1](src) //EMAElsIf mav = 2 thenMA = Average[length,2](src) //WEMAElsIf mav = 3 thenMA = xDEMA //DEMAElsIf mav = 4 thenMA = Average[Floor(length / 2) + 1](Average[Ceil(length / 2)](src)) //TMAElsIf mav = 5 thenMA = VAR //VAR a.k.a. VIDYA Variable Index Dynamic Moving AverageElsIf mav = 6 thenMA = WWMA //WWMA Welles Wilder's Moving AverageElsIf mav = 7 thenMA = xZLEMA //ZLEMA Zero Lag Exponential Moving AverageElsIf mav = 8 thenMA = TSF //TSF Time Series ForecastElsIf mav = 9 thenMA = HMA //HMA Hull Moving AverageElsIf mav = 10 thenMA = T3 //T3 Tillson Moving AverageEndIfatr = AverageTrueRange[Periods](src)up = MA - Multiplier * atrup1 = up[1]If src[1] > up1 thenup = Max(up, up1)Elseup = upEndIfdn = MA + Multiplier * atrdn1 = dn[1]If src[1] < dn1 thendn = Min(dn, dn1)elsedn = dnEndIfOnce trend = 1If trend = -1 and Close > dn1 thentrend = 1ElsIf trend = 1 and Close < up1 thentrend = -1EndIfif not longonmarket and close>dn and ((trend1=0 and close>slowln) or (trend1=1 and close crosses over slowln)) thenbuy 1 contract at marketendifif longonmarket and (close<slowln or trend1=1) thensell at marketendifgraphonprice up as "Up trend"coloured("red")graphonprice dn as "Down trend"coloured("Red")graphonprice slowln as "slowln"coloured(200,20,60)graphonprice fastln as "fastln"coloured(30,144,255)01/14/2025 at 5:23 PM #24257501/15/2025 at 5:11 AM #242584Hi Ivan, I tried to include this for Short trade version but does not work, can you please check
Once trend = 1
If trend = -1 and Close < dn1 then
trend = 1
ElsIf trend = 1 and Close > up1 then
trend = -1
EndIf
if not shortonmarket and close < dn and ((trend1 = 0 and close < slowln) or (trend1 = 1 and close crosses under slowln)) then
sell 1 contract at market
endif
if shortonmarket and (close > slowln or trend1 = 1)then
buy at market
endif01/15/2025 at 10:13 AM #24259601/15/2025 at 6:40 PM #242656Hi Ivan thank you.
There is some issue with double arrows. After the SELL entry BUY exist is happening without the changes to colour.
Please see the attached picture which shows the incorrect exit and timelines and the entire code used. Can you please guide me refining this?
// — settings
SlowLength = 7 // Slow length
FastLength = 3 // Fast length
// — end of settingsfasthigh = Highest[SlowLength](high)//[1]
fastlow = Lowest[SlowLength](low)//[1]
slowhigh = Highest[FastLength](high)//[1]
slowlow = Lowest[FastLength](low)//[1]if high<slowhigh then
thighs=slowhigh
else
thighs=high
endif
if low>slowlow then
tlows=slowlow
else
tlows=low
endif
if high<fasthigh then
thighf=fasthigh
else
thighf=high
endif
if low>fastlow then
tlowf=fastlow
else
tlowf=low
endifif close>slowln[1] then
slowln=tlows
else
slowln=thighs
endif
if close>fastln[1] then
fastln=tlowf
else
fastln=thighf
endifonce trend1=-1
if close<slowln and close<fastln then
trend1=1
endif
if close>slowln and close>fastln then
trend1=0
endifif trend1<>trend[1] then
if trend1=0 then
r=30
g=144
b=255
else
r=200
g=20
b=60
endifendif
src = Close //Data type
mav = 1 //Moving Average Value: 0=SMA, 1=EMA, 2=WMA, 3=DEMA, 4=TMA, 5=VAR, 6=WWMA, 7=ZLEMA, 8=TSF, 9=HMA, 10=T3
length = 100 //Moving Average Length
Periods = 10 //ATR period
Multiplier = 0.5 //ATR MultiplierT3a1 = 0.7 //Tillson T3 Volume Factor
valpha = 2 / (length+1)
If src > src[1] then //Green candle
vud1 = src – src[1] //Green profit
else
vud1 = 0
EndIfIf src < src[1] then //Red candle
vdd1 = src[1] – src //Red Loss
else
vdd1=0
EndIfvUD = Summation[9](vud1) //Summation [9] Green profit
vDD = Summation[9](vdd1) //Summation [9] Red LossvCMO = ((vUD – vDD) / vUD + vDD) //Cumulative Market Oscillator
Once VAR = 0
VAR = (valpha * Abs(vCMO) * src) + (1 – valpha * Abs(vCMO)) * VAR[1]xDEMA = 2 * ExponentialAverage[length](src) – ExponentialAverage[length](ExponentialAverage[length](src))
wwalpha = 1 //Length
Once WWMA = 0
WWMA = wwalpha * src + (1 – wwalpha) * WWMA[1]If (length / 2) = Round(length / 2) then //Check even/odd length for “zero lag”
zxLag = (length / 2)
Else
zxLag = ((length-1) / 2)
EndIfzxEMAData = src + src – src[zxLag]
xZLEMA = ExponentialAverage[length](zxEMAData) //Zero Lag Exponential Averagelrc = LinearRegression[length](src)
lrc1 = lrc[1]
lrs = lrc – lrc1
TSF = LinearRegression[length](src) + lrs //Time Series ForecastHMA = WeightedAverage[Round(SQRT(length))](2 * WeightedAverage[length/2](src) – WeightedAverage[length](src)) //Hull Moving Average
T3e1 = ExponentialAverage[length](src)
T3e2 = ExponentialAverage[length](T3e1)
T3e3 = ExponentialAverage[length](T3e2)
T3e4 = ExponentialAverage[length](T3e3)
T3e5 = ExponentialAverage[length](T3e4)
T3e6 = ExponentialAverage[length](T3e5)T3c1 = -T3a1 * T3a1 * T3a1
T3c2 = 3 * T3a1 * T3a1 + 3 * T3a1 * T3a1 * T3a1
T3c3 = -6 * T3a1 * T3a1 – 3 * T3a1 – 3 * T3a1 * T3a1 * T3a1
T3c4 = 1 + 3 * T3a1 + T3a1 * T3a1 * T3a1 + 3 * T3a1 * T3a1
T3 = T3c1 * T3e6 + T3c2 * T3e5 + T3c3 * T3e4 + T3c4 * T3e3 //T3 Moving AverageOnce MA = 0
If mav = 0 then
MA = Average[length,0](src) //SMA
ElsIf mav = 1 then
MA = Average[length,1](src) //EMA
ElsIf mav = 2 then
MA = Average[length,2](src) //WEMA
ElsIf mav = 3 then
MA = xDEMA //DEMA
ElsIf mav = 4 then
MA = Average[Floor(length / 2) + 1](Average[Ceil(length / 2)](src)) //TMA
ElsIf mav = 5 then
MA = VAR //VAR a.k.a. VIDYA Variable Index Dynamic Moving Average
ElsIf mav = 6 then
MA = WWMA //WWMA Welles Wilder’s Moving Average
ElsIf mav = 7 then
MA = xZLEMA //ZLEMA Zero Lag Exponential Moving Average
ElsIf mav = 8 then
MA = TSF //TSF Time Series Forecast
ElsIf mav = 9 then
MA = HMA //HMA Hull Moving Average
ElsIf mav = 10 then
MA = T3 //T3 Tillson Moving Average
EndIfatr = AverageTrueRange[Periods](src)
up = MA – Multiplier * atr
up1 = up[1]
If src[1] > up1 then
up = Max(up, up1)
Else
up = up
EndIf
dn = MA + Multiplier * atr
dn1 = dn[1]
If src[1] < dn1 then
dn = Min(dn, dn1)
else
dn = dn
EndIfOnce trend = 1
If trend = -1 and Close > dn1 then
trend = 1
ElsIf trend = 1 and Close < up1 then
trend = -1
EndIfif not longonmarket and close>dn and((trend1=0 and close>slowln) or (trend1=1 and close crosses over slowln)) then
buy 1 contract at market
endif
if longonmarket and (close<slowln or trend1=1) then
sell at market
endifif not shortonmarket and close < dn and ((trend1 = 0 and close < slowln) or (trend1 = 1 and close crosses under slowln))then
SELLSHORT 1 contract AT MARKET
endifif shortonmarket and (close > slowln or trend1 = 1)then
exitshort at market
endifgraphonprice up as “Up trend”coloured(“red”)
graphonprice dn as “Down trend”coloured(“Red”)
graphonprice slowln as “slowln”coloured(200,20,60)
graphonprice fastln as “fastln”coloured(30,144,255) -
AuthorPosts
Find exclusive trading pro-tools on