ProRealCode - Trading & Coding with ProRealTime™
Hi all,
Thanks to everyone sharing valuable code on this website, I’m learning a lot from being part of this community. I’m sharing here a 1 second TF code that seem to work well in backtestig (with very little backtest data..) but not sure how it will work live/forward testing. Both short and long strategies seem to have high win rate (and it seem to work well in tamdem, when the drawdays happens in one it goes up on the other, utlimately end up in a win position), but I would like to improve the precision of entry point to reduce drawdown. Does anhyone have an idea on how to achieve this on such a short timeframe? The result from the screenshot are with 6 points spread DJI
Sorex hoyi: “With a pulse clocking in at more than a 1000 per minute, the smallest mammal in North America really needs lots of food to keep its phenomenal metabolism going. Every day it eats three times its own weight. To do so it needs to constantly eat and never sleeps for more than a few minutes. An hour without food would mean certain death.
LONG
// Definition of code parameters
DEFPARAM CumulateOrders = true // Cumulating positions deactivated
DEFPARAM preloadbars = 10000
DEFPARAM flatbefore = 090000
DEFPARAM flatafter = 220000
once spreadmode = 1 // [1]dji;[2]us500;[3]us100;[4]dax;[5]saf;[6]ftse;[7]cac40
// trailing stop atr
// 'Value 2 is nice for 1/10s with max 3. So this parameter doesn’t need to be optimised'
once trailingstoptype = 1 // trailing stop - 0 off, 1 on
once trailingstoplong = 2 // trailing stop atr relative distance
once trailingstopshort = 2 // trailing stop atr relative distance
once atrtrailingperiod = 14 // atr parameter value
once minstop = 10 // minimum trailing stop distance
//************************************************************************
//Money Management DOW
MM = 0 // = 0 for optimization
if MM = 0 then
positionsize=1
ENDIF
if MM = 1 then
ONCE startpositionsize = 1
ONCE factor = 30 // factor of 10 means margin will increase/decrease @ 10% of strategy profit; factor 20 = 5% etc
ONCE factor2 = 20 // tier 2 factor
ONCE margin = (close*.005) // tier 1 margin value of 1 contract in instrument currency; change decimal according to available leverage
ONCE margin2 = (close*.01)// tier 2 margin value of 1 contract in instrument currency; change decimal according to available leverage
ONCE tier1 = 55 // DOW €1 IG first tier margin limit
ONCE maxpositionsize = 550 // DOW €1 IG tier 2 margin limit
ONCE minpositionsize = .2 // enter minimum position allowed
IF Not OnMarket THEN
positionsize = startpositionsize + Strategyprofit/(factor*margin)
ENDIF
IF Not OnMarket THEN
IF startpositionsize + Strategyprofit/(factor*margin) > tier1 then
positionsize = (((startpositionsize + (Strategyprofit/(factor*margin))-tier1)*(factor*margin))/(factor2*margin2)) + tier1 //incorporating tier 2 margin
ENDIF
IF Not OnMarket THEN
if startpositionsize + Strategyprofit/(factor*margin) < minpositionsize THEN
positionsize = minpositionsize //keeps positionsize from going below allowed minimum
ENDIF
IF (((startpositionsize + (Strategyprofit/(factor*margin))-tier1)*(factor*margin))/(factor2*margin2)) + tier1 > maxpositionsize then
positionsize = maxpositionsize// keeps positionsize from going above IG tier 2 margin limit
ENDIF
ENDIF
ENDIF
ENDIF
//************************************************************************
//vwap code taken from Nicolas PRC_VWAP intraday indicator
//if(intradaybarindex=0) then
//sd = 0
//else
//sd = SUMMATION[d](max(abs(high-vwap),abs(vwap-low)))/d
//endif
//************************************************************************
TIMEFRAME (1 minute)
ST60 = SuperTrend[st5,st6]
l10 = close > ST60
TIMEFRAME (20 seconds)
m = Momentum[momen](close)
ST20 = SuperTrend[st1,st2]
//
//TIMEFRAME (15 seconds)
//voss1, voss2 = CALL "PRC_Voss Predictive Filter VPF"[20, 3, 0.25]
//l10 = voss1 crosses over voss2
TIMEFRAME (10 seconds)
ST10 = SuperTrend[st3,st4]
VWAP = SUMMATION[d](volume*typicalprice)/SUMMATION[d](volume)
l1 = close > close[1]
l9 = close > VWAP
//s1 = close < close[1]
TIMEFRAME (Default)
l2 = close > close[1]
l3 = m crosses over 0
l4 = close > ST10
l5 = close > ST20
// Conditions to enter long positions
IF not longonmarket and l1 and l2 and l3 and l4 and l5 and l9 and l10 THEN
BUY positionsize CONTRACT AT MARKET
ENDIF
// Conditions to enter short positions
//IF not shortonmarket and s1 and s2 and s3 and s4 and s5 and s6 THEN
//SELLSHORT positionsize CONTRACT AT MARKET
//ENDIF
//
SET STOP %LOSS 2
SET TARGET %PROFIT 2.1
//
//************************************************************************
// spread
if spreadmode=1 then // wallstreet
if time > 090000 and time <= 153000 then
spread=2.4
elsif time > 153000 and time <= 220000 then
spread=1.6
elsif time > 221500 and time <= 223000 then
spread=9.8
elsif time > 230000 and time <= 235959 then
spread=9.8
elsif time = 000000 then
spread=9.8
else
spread=3.8
endif
elsif spreadmode=2 then // us500
if time > 090000 and time <= 220000 then
spread=0.4
elsif time > 221500 and time <= 223000 then
spread=1.5
elsif time > 223000 and time <= 235959 then
spread=1.5
elsif time = 000000 then
spread=1.5
else
spread=0.6
endif
elsif spreadmode=3 then // us100
if time > 153000 and time <= 220000 then
spread=1
elsif time > 221500 and time <= 223000 then
spread=5
elsif time > 230000 and time <= 235959 then
spread=5
elsif time = 000000 then
spread=5
else
spread=2
endif
elsif spreadmode=4 then // dax
if time > 090000 and time <= 173000 then
spread=1
elsif time > 173000 and time <= 220000 then
spread=2
elsif time > 220000 and time <= 235959 then
spread=7
elsif time >= 000000 and time <= 080000 then
spread=7
elsif time > 080000 and time <= 090000 then
spread=2
endif
elsif spreadmode=5 then // south african 40
if time > 073000 and time <= 163000 then
spread=8
else
spread=30
endif
elsif spreadmode=6 then // ftse100
if time > 080000 and time <= 163000 then
spread=1
elsif time > 163000 and time <= 210000 then
spread=2
elsif time > 070000 and time <= 075000 then
spread=2
else
spread=5
endif
elsif spreadmode=7 then // cac40
if time > 090000 and time <= 173000 then
spread=1
elsif time > 173000 and time <= 220000 then
spread=2
elsif time > 220000 and time <= 235959 then
spread=5
elsif time > 000000 and time <= 080000 then
spread=5
elsif time > 080000 and time <= 090000 then
spread=2
endif
endif
spread=spread/2
//************************************************************************
//----------------------------------------------
atrtrail = averagetruerange[atrtrailingperiod]((close/10)*pipsize)/1000
tgl = round(atrtrail*trailingstoplong)
tgs = round(atrtrail*trailingstopshort)
if trailingstoptype = 1 then
//
if not onmarket or ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) then
maxprice = 0
minprice = close
newsl = 0
endif
//
if longonmarket then
maxprice = max(maxprice,close)
if maxprice-tradeprice(1)>=tgl*pointsize then
if maxprice-tradeprice(1)>=minstop then
newsl = maxprice-tgl*pointsize
else
newsl = maxprice - minstop*pointsize
endif
endif
endif
if shortonmarket then
minprice = min(minprice,close)
if tradeprice(1)-minprice>=tgs*pointsize then
if tradeprice(1)-minprice>=minstop then
newsl = minprice+tgs*pointsize
else
newsl = minprice + minstop*pointsize
endif
endif
endif
//
if longonmarket then
if newsl>0 then
sell at newsl stop
endif
if newsl>0 then
if low < newsl then
sell at market
endif
endif
endif
//
if shortonmarket then
if newsl>0 then
exitshort at newsl stop
endif
if newsl>0 then
if high > newsl then
exitshort at market
endif
endif
endif
endif
GRAPHONPRICE VWAP
// Definition of code parameters
DEFPARAM CumulateOrders = true // Cumulating positions deactivated
DEFPARAM preloadbars = 10000
DEFPARAM flatbefore = 090000
DEFPARAM flatafter = 220000
once spreadmode = 1 // [1]dji;[2]us500;[3]us100;[4]dax;[5]saf;[6]ftse;[7]cac40
// trailing stop atr
// 'Value 2 is nice for 1/10s with max 3. So this parameter doesn’t need to be optimised'
once trailingstoptype = 1 // trailing stop - 0 off, 1 on
once trailingstoplong = 2 // trailing stop atr relative distance
once trailingstopshort = 2 // trailing stop atr relative distance
once atrtrailingperiod = 14 // atr parameter value
once minstop = 10 // minimum trailing stop distance
//************************************************************************
//Money Management DOW
MM = 1 // = 0 for optimization
if MM = 0 then
positionsize=1
ENDIF
if MM = 1 then
ONCE startpositionsize = 1
ONCE factor = 30 // factor of 10 means margin will increase/decrease @ 10% of strategy profit; factor 20 = 5% etc
ONCE factor2 = 20 // tier 2 factor
ONCE margin = (close*.005) // tier 1 margin value of 1 contract in instrument currency; change decimal according to available leverage
ONCE margin2 = (close*.01)// tier 2 margin value of 1 contract in instrument currency; change decimal according to available leverage
ONCE tier1 = 55 // DOW €1 IG first tier margin limit
ONCE maxpositionsize = 550 // DOW €1 IG tier 2 margin limit
ONCE minpositionsize = .2 // enter minimum position allowed
IF Not OnMarket THEN
positionsize = startpositionsize + Strategyprofit/(factor*margin)
ENDIF
IF Not OnMarket THEN
IF startpositionsize + Strategyprofit/(factor*margin) > tier1 then
positionsize = (((startpositionsize + (Strategyprofit/(factor*margin))-tier1)*(factor*margin))/(factor2*margin2)) + tier1 //incorporating tier 2 margin
ENDIF
IF Not OnMarket THEN
if startpositionsize + Strategyprofit/(factor*margin) < minpositionsize THEN
positionsize = minpositionsize //keeps positionsize from going below allowed minimum
ENDIF
IF (((startpositionsize + (Strategyprofit/(factor*margin))-tier1)*(factor*margin))/(factor2*margin2)) + tier1 > maxpositionsize then
positionsize = maxpositionsize// keeps positionsize from going above IG tier 2 margin limit
ENDIF
ENDIF
ENDIF
ENDIF
//************************************************************************
//vwap code taken from Nicolas PRC_VWAP intraday indicator
//if(intradaybarindex=0) then
//sd = 0
//else
//sd = SUMMATION[d](max(abs(high-vwap),abs(vwap-low)))/d
//endif
//************************************************************************
TIMEFRAME (1 minute)
ST60 = SuperTrend[st5,st6]
s10 = close < ST60
TIMEFRAME (20 seconds)
m = Momentum[momen](close)
ST20 = SuperTrend[st1,st2]
//
//TIMEFRAME (15 seconds)
//voss1, voss2 = CALL "PRC_Voss Predictive Filter VPF"[20, 3, 0.25]
//l10 = voss1 crosses over voss2
TIMEFRAME (10 seconds)
ST10 = SuperTrend[st3,st4]
VWAP = SUMMATION[d](volume*typicalprice)/SUMMATION[d](volume)
s1 = close < close[1]
s9 = close < VWAP
//s1 = close < close[1]
TIMEFRAME (Default)
s2 = close < close[1]
s6 = m crosses under 0
s7 = close < ST10
s8 = close < ST20
// Conditions to enter long positions
//IF not longonmarket and l1 and l2 and l6 and l7 and l8 and l9 THEN
//BUY positionsize CONTRACT AT MARKET
//ENDIF
// Conditions to enter short positions
IF not shortonmarket and s1 and s2 and s6 and s7 and s8 and s9 and s10 THEN
SELLSHORT positionsize CONTRACT AT MARKET
ENDIF
//
SET STOP %LOSS 2
SET TARGET %PROFIT 2.1
//
//************************************************************************
// spread
if spreadmode=1 then // wallstreet
if time > 090000 and time <= 153000 then
spread=2.4
elsif time > 153000 and time <= 220000 then
spread=1.6
elsif time > 221500 and time <= 223000 then
spread=9.8
elsif time > 230000 and time <= 235959 then
spread=9.8
elsif time = 000000 then
spread=9.8
else
spread=3.8
endif
elsif spreadmode=2 then // us500
if time > 090000 and time <= 220000 then
spread=0.4
elsif time > 221500 and time <= 223000 then
spread=1.5
elsif time > 223000 and time <= 235959 then
spread=1.5
elsif time = 000000 then
spread=1.5
else
spread=0.6
endif
elsif spreadmode=3 then // us100
if time > 153000 and time <= 220000 then
spread=1
elsif time > 221500 and time <= 223000 then
spread=5
elsif time > 230000 and time <= 235959 then
spread=5
elsif time = 000000 then
spread=5
else
spread=2
endif
elsif spreadmode=4 then // dax
if time > 090000 and time <= 173000 then
spread=1
elsif time > 173000 and time <= 220000 then
spread=2
elsif time > 220000 and time <= 235959 then
spread=7
elsif time >= 000000 and time <= 080000 then
spread=7
elsif time > 080000 and time <= 090000 then
spread=2
endif
elsif spreadmode=5 then // south african 40
if time > 073000 and time <= 163000 then
spread=8
else
spread=30
endif
elsif spreadmode=6 then // ftse100
if time > 080000 and time <= 163000 then
spread=1
elsif time > 163000 and time <= 210000 then
spread=2
elsif time > 070000 and time <= 075000 then
spread=2
else
spread=5
endif
elsif spreadmode=7 then // cac40
if time > 090000 and time <= 173000 then
spread=1
elsif time > 173000 and time <= 220000 then
spread=2
elsif time > 220000 and time <= 235959 then
spread=5
elsif time > 000000 and time <= 080000 then
spread=5
elsif time > 080000 and time <= 090000 then
spread=2
endif
endif
spread=spread/2
//************************************************************************
//----------------------------------------------
atrtrail = averagetruerange[atrtrailingperiod]((close/10)*pipsize)/1000
tgl = round(atrtrail*trailingstoplong)
tgs = round(atrtrail*trailingstopshort)
if trailingstoptype = 1 then
//
if not onmarket or ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) then
maxprice = 0
minprice = close
newsl = 0
endif
//
if longonmarket then
maxprice = max(maxprice,close)
if maxprice-tradeprice(1)>=tgl*pointsize then
if maxprice-tradeprice(1)>=minstop then
newsl = maxprice-tgl*pointsize
else
newsl = maxprice - minstop*pointsize
endif
endif
endif
if shortonmarket then
minprice = min(minprice,close)
if tradeprice(1)-minprice>=tgs*pointsize then
if tradeprice(1)-minprice>=minstop then
newsl = minprice+tgs*pointsize
else
newsl = minprice + minstop*pointsize
endif
endif
endif
//
if longonmarket then
if newsl>0 then
sell at newsl stop
endif
if newsl>0 then
if low < newsl then
sell at market
endif
endif
endif
//
if shortonmarket then
if newsl>0 then
exitshort at newsl stop
endif
if newsl>0 then
if high > newsl then
exitshort at market
endif
endif
endif
endif
GRAPHONPRICE VWAP
shor and long strategy run at the same time. Is this a happy coincidence or can it be a way to minimise losses?
Thx for sharing, i will check
about TF, on my side, i use also a higher TF > 15 or 30mn in order to get the big trend (i have 1s/1mn/5mn/30mn)
did you test that ?
about TF 20 second, it’s s specific TF i think. Maybe you may have a better result with 30s which is more “standard” ? not tested..
for the entrypoint, a work around the settings of the candles could improve it
maybe you could work also an exit if TP isn’t reached.. a security if failed. It’s the most difficult with TF 1s, when to go out..
Am I missing something … you have all the spreads defined in your code, but ‘spread’ is not used anywhere to do anything (I checked only the Long System) ??
Thanks for sharing eckaw. Looks indeed that spread is not used. Regardless of using, the spread needs to be set in the backtest engine. Since your code trade specific times on which the spread is almost the same, the extra code don’t add much. In my renko version I got it removed. Can you post the variables used?
@Paul Thanks for the insight about the spread. I’m fairly new to coding in PRT so I appreciate your advice. I used spread 6pt in the backtest settings.
Variables used:
momen – 10
st1 – 18
st4 – 4
st3 – 6
st4 – 1
d – 3
st5 – 9
st6 – 2
There may be some other code that could be removed, I will look into this – if that’s the case I’ll post another version. Would be intersted to hear your thoughts on this idea, why it could work / why it won’t work.
The parameters above was for the long version. Short version has the same, apart from:
st5 – 2
st6 – 1
When I want folk to check out a System of mine on their Platform and offer improvements etc, I always post the .itf file with all the settings for variables set up in the optimiser … makes it loads easier for them .. download, import, backtest … 3 clicks of the mouse, and they can start working on it.
Alsos .itf files show as titled versions in the Attachment list at the top of every page and so it makes it loads easier to later find previous and latest versions (backup if our PC crashes even?) … they would always be available on this website.
Might you post the .itf please? 🙂
@GraHal – that makes perfect sense! Here you go.
The stoploss is too big for a 1s or 10s system for me. Changing it to 0.5% results in less profit but still good overall. But if I check when signals come and apply my reenter theory for robustness, it seems results go down too much.
I did some work on it, so I share it.
Made 2 systems into one. Can’t run long&short at the same time.
Results are the same on yours posted above.
I’m getting rejections on both versions of this – ‘division by zero’ on the original and ‘negative or zero parameter’ on Paul’s version.
Hi @eckaw thanks for sharing this hungry little shrew – seems it could have potential.
One thing I noticed though is that your Supertrend settings are miles away from the default and on such a short back test this strongly indicates a curve fit. I use Supertrend a lot but try to keep to the default settings for back tests of less than 1 year, otherwise it’s v likely that you’re bending your parameters to fit the data.
(3,10) is the most common setting and halving those values (1.5,5) is also an option. (2,7) is a good mid-way point and within the extremely limited TF, this would appear to give the best result for Sorex Hoyi.
This is not to say that your numbers won’t work, they certainly do for now, just that I fear they may not hold up in the long run.
Just a suggestion …
@nonetheless thanks for feedback. I will take a look at this and do further testing.
I just tried to launch Paul amended version with slightly different SuperTrend settings and it failed to start. There was a message “The trading sytstem was stopped because an indicator received a negative or zero parameter ex:(-10).”
It seems to work well in backtest. I’m going through the code but haven’t yet figured out yet what it could be.
Probably it happens quicker on a short timeframe those errors. Same annoying thing on renko, but I got it to work for now.
Here are few idea’s.
Use below to make sure there is data.
if barindex>1 and range>0 then
and/or
when there’s possibly no data i.e. the max function
max(abs(open - close), 0.000000001)
can also be used on an average I think, like
max(ExponentialAverage[20](close),0.000000001)
I don’t now where exactly is the cause, so in the renko version I use above a lot.
It’s definately an interesting code. Hope someone on the forum can figure out how to make it run on demo without being stopped.
Sorex hoyi scalper
This topic contains 29 replies,
has 6 voices, and was last updated by MAKSIDE
5 years, 10 months ago.
| Forum: | ProOrder: Automated Strategies & Backtesting |
| Language: | English |
| Started: | 04/12/2020 |
| Status: | Active |
| Attachments: | 7 files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.