Need help with automatic a strategy for DAX and SA40
Forums › ProRealTime English forum › ProOrder support › Need help with automatic a strategy for DAX and SA40
- This topic has 16 replies, 5 voices, and was last updated 4 years ago by Paul.
-
-
08/28/2019 at 6:06 PM #105772
Hi Lombard974
Doesn’t exactly work the way I wanted, it takes one position based on high/low from 15min bar after crossing, on the next bar, with only 1 trade a day between 9.00-9.15
Lines display the high/low from the 15min candle 845-0900. You also see your stoploss and the trailing-stops.
Your second option isn’t implemented and is perhaps not suitable for this code.
The code is a bit long, it the layout I work with. Focus on the main criteria part for adjustment and time settings.
Tested on DAX30 1 minute.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298// common rulesdefparam cumulateorders = falsedefparam preloadbars = 10000TIMEFRAME (default)// on/offonce enablesl = 1 // stoplossonce enablept = 1 // profit targetonce enablets = 1 // trailing stoponce enablebe = 0 // breakeven stop//activate graph(onprice); maximum 5 lines active !once displaysl = 1 // stop loss [1 line]once displaypt = 0 // profit target [1 line]once displayts = 1 // trailing stop [3 lines]once displaybe = 0 // breakeven stop [1 line]once displaydim = 0 // days in market [1 line]once displaypp = 0 // position performance [1 line]positionsize = 1sl = 1 // % stoplosspt = 1 // % profit target// trailingstop exit activates when positionperformance (pp)ts1=0.35 // is greater then this percentage then use trailingstop ts1switch=0.45 // is greater then this percentage then use trailingstop ts2ts2=0.25switch2=0.60 // is greater then this percentage then use trailingstop ts3ts3=0.20// breakeven exitbesg = 0.30 // % break even stop gainbesl = 0.05 // % break even stop level// used for sl/pt/ (not used for ts); not to be optimized!// forex use 0.01; securities use 1, index use 100// profittargets and stoploss have to match the lines with displaysl/tp/ts set to 1underlaying=100// day & timeonce entertime = 090000once lasttime = 091500once closetime = 210000 // greater then 23.59 means it continues position overnightonce closetimefr = 180000tradetime = (time >= entertime and time < lasttime)// reset at startif intradaybarindex=0 thenlongtradecounter=0shorttradecounter=0tradecounter=0endif// [pc] position criteria (also set a limit to the number of trades a day) (or set high for no impact)pclong = countoflongshares < 1 and longtradecounter < 1 and tradecounter < 1pcshort = countofshortshares < 1 and shorttradecounter < 1 and tradecounter < 1//[mc] main criteriaTIMEFRAME (15 minutes, updateonclose)if intradaybarindex=35 then //0845-0900 on 15 minMaxPrice = highMinPrice = lowelseMaxPrice = 0MinPrice = 0ENDIFgraphonprice MaxPrice coloured(0,200,0) as "MaxPrice"graphonprice MinPrice coloured(200,200,0) as "MinPrice"TIMEFRAME (default)if intradaybarindex=0 thenmclong=0mcshort=0endifif close crosses over MaxPrice thenmclong=1endifif close crosses under MinPrice thenmcshort=1endif// long & short entryif tradetime thenif pclong and mclong thenbuy positionsize contract at MaxPrice stoplongtradecounter=longtradecounter + 1tradecounter=tradecounter+1elsif pcshort and mcshort thensellshort positionsize contract at MinPrice stopshorttradecounter=shorttradecounter + 1tradecounter=tradecounter+1endifendif//pp=(positionperf*100)// trailing stopif enablets thentrailingstop1 = (tradeprice(1)/100)*ts1trailingstop2 = (tradeprice(1)/100)*ts2trailingstop3 = (tradeprice(1)/100)*ts3if not onmarket or ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) thenmaxprice1=0minprice1=closepriceexit1=0maxprice2=0minprice2=closepriceexit2=0maxprice3=0minprice3=closepriceexit3=0a1=0a2=0a3=0pp=0endifif onmarket thenif pp>=ts1 thena1=1endifif pp>=switch thena2=1endifif pp>=switch2 thena3=1endifendif// setup longif longonmarket thenmaxprice1=max(maxprice1,close)maxprice2=max(maxprice2,high)maxprice3=max(maxprice3,high)if a1 thenif maxprice1-tradeprice(1)>=(trailingstop1)*pointsize thenpriceexit1=maxprice1-(trailingstop1/(underlaying/100))*pointsizeendifendifif a2 thenif maxprice2-tradeprice(1)>=(trailingstop2)*pointsize thenpriceexit2=maxprice2-(trailingstop2/(underlaying/100))*pointsizeendifendifif a3 thenif maxprice3-tradeprice(1)>=(trailingstop3)*pointsize thenpriceexit3=maxprice3-(trailingstop3/(underlaying/100))*pointsizeendifendifendif// setup shortif shortonmarket thenminprice1=min(minprice1,close)minprice2=min(minprice2,low)minprice3=min(minprice3,low)if a1 thenif tradeprice(1)-minprice1>=(trailingstop1)*pointsize thenpriceexit1=minprice1+(trailingstop1/(underlaying/100))*pointsizeendifendifif a2 thenif tradeprice(1)-minprice2>=(trailingstop2)*pointsize thenpriceexit2=minprice2+(trailingstop2/(underlaying/100))*pointsizeendifendifif a3 thenif tradeprice(1)-minprice3>=(trailingstop3)*pointsize thenpriceexit3=minprice3+(trailingstop3/(underlaying/100))*pointsizeendifendifendif// exit longif longonmarket and priceexit1>0 thensell at priceexit1 stopendifif longonmarket and priceexit2>0 thensell at priceexit2 stopendifif longonmarket and priceexit3>0 thensell at priceexit3 stopendif// exit shortif shortonmarket and priceexit1>0 thenexitshort at priceexit1 stopendifif shortonmarket and priceexit2>0 thenexitshort at priceexit2 stopendifif shortonmarket and priceexit3>0 thenexitshort at priceexit3 stopendifif displayts thengraphonprice priceexit1 coloured(0,0,255,255) as "trailingstop1"graphonprice priceexit2 coloured(0,0,255,255) as "trailingstop2"graphonprice priceexit3 coloured(0,0,255,255) as "trailingstop3"endifendif// break even stopif enablebe thenif not onmarket thennewsl=0endifif ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) thennewsl=0endifif longonmarket thenif close-tradeprice(1)>=(((tradeprice(1)/100)*besg)/(underlaying/100))*pointsize thennewsl=tradeprice(1)+(((tradeprice(1)/100)*besl)/(underlaying/100))*pointsizeendifendifif shortonmarket thenif tradeprice(1)-close>=(((tradeprice(1)/100)*besg)/(underlaying/100))*pointsize thennewsl=tradeprice(1)-(((tradeprice(1)/100)*besl)/(underlaying/100))*pointsizeendifendifif longonmarket and newsl>0 thensell at newsl stopendifif shortonmarket and newsl>0 thenexitshort at newsl stopendifif displaybe then//graphonprice newsl coloured(244,102,27,255) as "breakevenstop"endifendif// set stoplossif enablesl thenif not onmarket thensloss=0elsif longonmarket thensloss=tradeprice(1)-((tradeprice(1)*sl)/underlaying)*pointsizeelsif shortonmarket thensloss=tradeprice(1)+((tradeprice(1)*sl)/underlaying)*pointsizeendifset stop %loss slif displaysl thengraphonprice sloss coloured(255,0,0,255) as "stoploss"sloss=slossendifendif// to display profittargetif enablept thenif not onmarket thenptarget=0elsif longonmarket thenptarget=tradeprice(1)+((tradeprice(1)*pt)/underlaying)*pointsizeelsif shortonmarket thenptarget=tradeprice(1)-((tradeprice(1)*pt)/underlaying)*pointsizeendifset target %profit ptif displaypt then//graphonprice ptarget coloured(121,141,35,255) as "profittarget"ptarget=ptargetendifendif// exit at closetimeif onmarket thenif time >= closetime or (currentdayofweek=5 and time>=closetimefr) thensell at open stopexitshort at open stopendifendif// display days in marketif displaydim thenif not onmarket thendim=0endifif (onmarket and not onmarket[1]) or ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) thendim=1endifif not (dayofweek=1 and hour = 1) thenif onmarket thenif openday <> openday[1] thendim = dim + 1endifendifendif//graph dim coloured(121,141,35,255) as "days in market"endifif displaypp then//graph pp coloured(0,0,0,255) as "positionperformance"endif//for trading all graph & graphonprice have to be comment out//for backtesting and to have a visual idea of exits or pp//uncomment and set displaysl and/or displaypt and/or displayts to 1//maximum of 5 can be used to display lines (graph & graphonprice combined)08/28/2019 at 6:13 PM #105773 -
AuthorPosts
Find exclusive trading pro-tools on
Similar topics: