set big line values automatically
Forums › ProRealTime English forum › ProOrder support › set big line values automatically
- This topic has 14 replies, 4 voices, and was last updated 4 years ago by Paul.
-
-
12/02/2017 at 2:19 AM #54507
Hi,
I’am trying a strategy based on the close which crosses a big lines.
This is for the dax, but how can you calculate these big line numbers automatically and quickly, so the strategy is use-full for other markets without too much hassle? I thought about using the interval values, but it becomes messy quick. Is there a better way?
Thanks in advance.
1234567891011121314151617181920212223242526// lines for dax//sv=13100 //start value//ivm=100 //interval value medium lines//ivb=1000 //interval value big linesl1= close crosses over 13100 or close crosses over 12100 or close crosses over 11100 or close crosses over 10100 or close crosses over 9100l2= close crosses over 13200 or close crosses over 12200 or close crosses over 11200 or close crosses over 10200 or close crosses over 9200l3= close crosses over 13300 or close crosses over 12300 or close crosses over 11300 or close crosses over 10300 or close crosses over 9300l4= close crosses over 13400 or close crosses over 12400 or close crosses over 11400 or close crosses over 10400 or close crosses over 9400l5= close crosses over 13500 or close crosses over 12500 or close crosses over 11500 or close crosses over 10500 or close crosses over 9500l6= close crosses over 13600 or close crosses over 12600 or close crosses over 11600 or close crosses over 10600 or close crosses over 9600l7= close crosses over 13700 or close crosses over 12700 or close crosses over 11700 or close crosses over 10700 or close crosses over 9700l8= close crosses over 13800 or close crosses over 12800 or close crosses over 11800 or close crosses over 10800 or close crosses over 9800l9= close crosses over 13900 or close crosses over 12900 or close crosses over 11900 or close crosses over 10900 or close crosses over 9900l10=close crosses over 14000 or close crosses over 13000 or close crosses over 12000 or close crosses over 11100 or close crosses over 10000s1= close crosses under 13100 or close crosses under 12100 or close crosses under 11100 or close crosses under 10100 or close crosses under 9100s2= close crosses under 13200 or close crosses under 12200 or close crosses under 11200 or close crosses under 10200 or close crosses under 9200s3= close crosses under 13300 or close crosses under 12300 or close crosses under 11300 or close crosses under 10300 or close crosses under 9300s4= close crosses under 13400 or close crosses under 12400 or close crosses under 11400 or close crosses under 10400 or close crosses under 9400s5= close crosses under 13500 or close crosses under 12500 or close crosses under 11500 or close crosses under 10500 or close crosses under 9500s6= close crosses under 13600 or close crosses under 12600 or close crosses under 11600 or close crosses under 10600 or close crosses under 9600s7= close crosses under 13700 or close crosses under 12700 or close crosses under 11700 or close crosses under 10700 or close crosses under 9700s8= close crosses under 13800 or close crosses under 12800 or close crosses under 11800 or close crosses under 10800 or close crosses under 9800s9= close crosses under 13900 or close crosses under 12900 or close crosses under 11900 or close crosses under 10900 or close crosses under 9900s10=close crosses under 14000 or close crosses under 13000 or close crosses under 12000 or close crosses under 11000 or close crosses under 1000012/02/2017 at 10:32 AM #54516Hi Paul, The levels can be created using the mod operator, see the code example below. You might want to add some loops to store the level values.
123456789CurrentPrice = closeAboveLevell0 = CurrentPrice mod 10StartLevel = CurrentPrice - AboveLevell0Level10Up = StartLevel + 10Level20Up = StartLevel + 20 // etc.Levell0Down = StartLevel - 10Level20Down = StartLevel- 20 // etc.1 user thanked author for this post.
12/03/2017 at 1:33 AM #54579Here’s the adjusted code. The results do not match the pic. Can you see something obvious wrong ?
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116//-------------------------------------------------------------------------// Main code : Big Line Strategy//-------------------------------------------------------------------------// common rulesDEFPARAM CUMULATEORDERS = falseDEFPARAM PRELOADBARS = 10000// time rulesONCE entertime = 090000ONCE lasttime = 180000ONCE closetime = 240000 // greater then 23.59 means it continues position overnightONCE closetimefriday=180000tt1 = time >= entertimett2 = time <= lasttimetradetime = tt1 and tt2// positionsize and stopspositionsize=1sl=1 // % stoplossts=1.5 // % trailing stoppt=2.5 // % profit target// setup number of trades intradayif IntradayBarIndex = 0 thenlongtradecounter = 0Shorttradecounter = 0endif// trade criterialc = tradetime and countoflongshares < 1 and longtradecounter < 1sc = tradetime and countofshortshares < 1 and shorttradecounter < 1// lines for daxCurrentPrice = round(dclose(1))mp = 100AboveLevell0 = CurrentPrice mod mpStartLevel = CurrentPrice - AboveLevell0Level10Up = StartLevel + (1*mp)Level20Up = StartLevel + (2*mp)Level30Up = StartLevel + (3*mp)Level40Up = StartLevel + (4*mp)Level50Up = StartLevel + (5*mp)Level60Up = StartLevel + (6*mp)Level70Up = StartLevel + (7*mp)Level80Up = StartLevel + (8*mp)Level90Up = StartLevel + (9*mp)Levell0Down = StartLevel - (1*mp)Level20Down = StartLevel - (2*mp)Level30Down = StartLevel - (3*mp)Level40Down = StartLevel - (4*mp)Level50Down = StartLevel - (5*mp)Level60Down = StartLevel - (6*mp)Level70Down = StartLevel - (7*mp)Level80Down = StartLevel - (8*mp)Level90Down = StartLevel - (9*mp)l0= close crosses over StartLevell1= close crosses over Level10Upl2= close crosses over Level20Upl3= close crosses over Level30Upl4= close crosses over Level40Upl5= close crosses over Level50Upl6= close crosses over Level60Upl7= close crosses over Level70Upl8= close crosses over Level80Upl9= close crosses over Level90Ups0=close crosses under StartLevels1= close crosses under Levell0Downs2= close crosses under Level20Downs3= close crosses under Level30Downs4= close crosses under Level40Downs5= close crosses under Level50Downs6= close crosses under Level60Downs7= close crosses under Level70Downs8= close crosses under Level80Downs9= close crosses under Level90Down// extra long and short criteriaelc=high < MIN(dhigh(1),dhigh(2))esc=low > MAX(dlow(1),dlow(2))// long entryIf lc and elc and (l0 or l1 or l2 or l3 or l4 or l5 or l6 or l7 or l8 or l9) thenbuy positionsize contract at marketlongtradecounter=longtradecounter + 1endif// short entryif sc and esc and (s0 or s1 or s2 or s3 or s4 or s5 or s6 or s7 or s8 or s9) thensellshort positionsize contract at marketshorttradecounter=shorttradecounter + 1endif// exit allIf onmarket and time >= closetime thensell at marketexitshort at marketendif// exit friday at set closetimeif onmarket and (CurrentDayOfWeek=5 and time>=closetimefriday) thensell at marketexitshort at marketendif// build-in exitSET STOP %LOSS sl %TRAILING tsSET TARGET %PROFIT pt//GRAPH 0 coloured(300,0,0) AS "zeroline"//GRAPH (positionperf*100)coloured(0,0,0,255) AS "PositionPerformance"12/03/2017 at 10:11 AM #54585Hi Paul, the difference is that the fixed lines are created once and the dynamic way of doing it is creating the levels on each 5 minute bar. By creating the levels once a day e.g. if time = 080000 (any time before your start time) you will get the same result as per the previous version, actually better due to the Dhigh() and Dlow() checks you added.
12/03/2017 at 2:54 PM #54597Thanks for your response!
To check if lines were correct I created a indicator. So lines are dynamic, based on a yesterday’s high.
The index is never out of the *dynamic range*, so I thought it should be the same as fixed lines, but it isn’t.
I will try new approach.
12/04/2017 at 9:11 AM #54633You could try to make the “CurrentPrice”, the last Close and see what happens:
1CurrentPrice = round(close)Since the code is read only once per bar, the round levels should be always calculated with the Close of the current 5 minutes bar.
12/05/2017 at 2:04 AM #54730I tried your idea Nicolas. It didn’t work. Because when lines zigzag around a big line, the lines could move 1 bar. I think as a result the condition crossed was not met. Also tried the idea from AutoStrategist. But somehow it made the strategy 100x slower. But I found the cause. Somehow I overlooked I specified before only 1 part of the criteria for a big line. But a line needs 2 criteria.
1l0= close crosses over Level00Up or close crosses over Level00DownThanks for the tips!
12/05/2017 at 2:28 AM #5473112/05/2017 at 7:53 AM #54735Thank you Paul! Should be in the Library too! Do you want to post it there?
FYI I posted a new indicator to spot these round levels recently: https://www.prorealcode.com/prorealtime-indicators/sweet-spots-numbers/
12/05/2017 at 9:21 PM #5482212/05/2017 at 10:03 PM #54826Are you talking about this topic only? Or in any other topic of the forums? Because there are no attachments at all in this specific thread.
When not connected, you are browsing cached pages which may be “old” (one hour or so..), so that’s possible that you might spot some differences if you are logged or not.
12/05/2017 at 10:25 PM #54831@Nicolas: I saw this problem only in some threads.
I’m sure that there were attachments in some of the posts above. For example about 1 hour ago, in #53731 there were a picture and an itf file to download that disappeared when I logged in.
And now no attachment (log in or log out)
Thanks.
12/06/2017 at 9:12 AM #54850I understand now why these files have been deleted, while Paul send a new post in the library, he deleted its own old files.. No worry the strategy will be available in the code library today after a short review.
EDIT: the strategy is now available in the library: big line strategy for DAX
12/07/2017 at 8:31 AM #54940Ok. That’s clear Nicolas.
So thank you Paul for your code. In my opinion Dax and Nasdaq Should be the most suitable for this strategy.
I’ll try some modifications and tests and wiĺl share if it improve performance.
1 user thanked author for this post.
08/28/2019 at 3:27 PM #105751Checking out this old system. Updated a bit. Try use factor 50 or 100. It needs an extra filter, but current run is nice. On DAX30, TF 5min
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430//-------------------------------------------------------------------------// Main code : Big Line Strategy//-------------------------------------------------------------------------// common rulesdefparam cumulateorders = falsedefparam preloadbars = 10000once extracriteria = 2 // [0]off or [1]strict or [2]most strict for higher timeframesonce enablesl = 1 // stoplossonce enablept = 1 // profit targetonce enablets = 1 // trailing stoponce enablebe = 1 // breakeven stoponce timeexit = 1 // test i.e. without ts but with be//activate graph(onprice); maximum 5 lines active !once displaysl = 0 // stop loss [1 line]once displaypt = 0 // profit target [1 line]once displayts = 0 // 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]once holiday = 1once factor = 100 //i.e. action at 50 lines or 100 linespositionsize = 1sl = 1 // % stoplosspt = 1.25 // % 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// reset at startif intradaybarindex=0 thenlongtradecounter=0shorttradecounter=0tradecounter=0ecshort=1eclong=1tradeday= 1endif// holidayif holiday then// prevent trading first week in a new yearif year=2015 and month=1 and day<=4 thentradeday = 0elsif year=2016 and month=1 and day<=3 thentradeday = 0elsif year=2017 and month=1 and day<=8 thentradeday = 0elsif year=2018 and month=1 and day<=7 thentradeday = 0elsif year=2019 and month=1 and day<=6 thentradeday = 0// prevent trading yearly common holiday'selsif month=12 and day=24 then // before christmas daytradeday = 0elsif month=12 and day=25 then // christmas daytradeday = 0elsif month=12 and day=26 then // after christmas daytradeday = 0elsif month=12 and day=31 then // old years evetradeday = 0// prevent trading on a public holiday in germany; market can be openelsif year=2019 and month=4 and day=19 then // holiday in germany; good fridaytradeday = 0elsif year=2018 and month=3 and day=30 then // holiday in germany; good fridaytradeday = 0elsif year=2017 and month=4 and day=14 then // holiday in germany; good fridaytradeday = 0elsif year=2019 and month=4 and day=22 then // holiday in germany; easter mondaytradeday = 0elsif year=2018 and month=4 and day=2 then // holiday in germany; easter mondaytradeday = 0elsif year=2017 and month=4 and day=17 then // holiday in germany; easter mondaytradeday = 0elsif month=5 and day=1 then // holiday in germany; labour daytradeday = 0elsif year=2019 and month=5 and day=30 then // holiday in germany; ascension daytradeday = 0elsif year=2018 and month=5 and day=10 then // holiday in germany; ascension daytradeday = 0elsif year=2017 and month=5 and day=25 then // holiday in germany; ascension daytradeday = 0elsif year=2019 and month=6 and day=10 then // holiday in germany; whit mondaytradeday = 0elsif year=2018 and month=6 and day=21 then // holiday in germany; whit mondaytradeday = 0elsif year=2017 and month=6 and day=5 then // holiday in germany; whit mondaytradeday = 0elsif month=10 and day=3 then // holiday in germany; unity daytradeday = 0elsetradeday = 1endifendif// day & timeONCE entertime = 090000ONCE lasttime = 180000once closetime = 240000 // greater then 23.59 means it continues position overnightonce fridayclosetime = 180000tradetime = (time>=entertime and time<lasttime) and tradeday// [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 criteriaCurrentPrice = round(dclose(1))MPmod = 100Factor = FactorAboveLevel0 = CurrentPrice mod MPmodStartLevel = CurrentPrice - AboveLevel0Level00Up = StartlevelLevel10Up = StartLevel + (1*Factor)Level20Up = StartLevel + (2*Factor)Level30Up = StartLevel + (3*Factor)Level40Up = StartLevel + (4*Factor)Level50Up = StartLevel + (5*Factor)Level60Up = StartLevel + (6*Factor)Level70Up = StartLevel + (7*Factor)Level80Up = StartLevel + (8*Factor)Level90Up = StartLevel + (9*Factor)Level00Down = StartlevelLevell0Down = StartLevel - (1*Factor)Level20Down = StartLevel - (2*Factor)Level30Down = StartLevel - (3*Factor)Level40Down = StartLevel - (4*Factor)Level50Down = StartLevel - (5*Factor)Level60Down = StartLevel - (6*Factor)Level70Down = StartLevel - (7*Factor)Level80Down = StartLevel - (8*Factor)Level90Down = StartLevel - (9*Factor)l0= close crosses over Level00Up or close crosses over Level00Downl1= close crosses over Level10Up or close crosses over Levell0Downl2= close crosses over Level20Up or close crosses over Level20Downl3= close crosses over Level30Up or close crosses over Level30Downl4= close crosses over Level40Up or close crosses over Level40Downl5= close crosses over Level50Up or close crosses over Level50Downl6= close crosses over Level60Up or close crosses over Level60Downl7= close crosses over Level70Up or close crosses over Level70Downl8= close crosses over Level80Up or close crosses over Level80Downl9= close crosses over Level90Up or close crosses over Level90Downs0= close crosses under Level00Down or close crosses under Level00Ups1= close crosses under Levell0Down or close crosses under Level10Ups2= close crosses under Level20Down or close crosses under Level20Ups3= close crosses under Level30Down or close crosses under Level30Ups4= close crosses under Level40Down or close crosses under Level40Ups5= close crosses under Level50Down or close crosses under Level50Ups6= close crosses under Level60Down or close crosses under Level60Ups7= close crosses under Level70Down or close crosses under Level70Ups8= close crosses under Level80Down or close crosses under Level80Ups9= close crosses under Level90Down or close crosses under Level90Upmclong=(l0 or l1 or l2 or l3 or l4 or l5 or l6 or l7 or l8 or l9)mcshort=(s0 or s1 or s2 or s3 or s4 or s5 or s6 or s7 or s8 or s9)// [ec] extra criteriaif extracriteria theneclong = high < dhigh(1)ecshort = low > dlow(1)elsif extracriteria=2 thenmin1 = min(dhigh(0),dhigh(1))min2 = min(dhigh(1),dhigh(2))max1 = max(dlow(0),dlow(1))max2 = max(dlow(1),dlow(2))eclong = high < min(min1,min2)ecshort =low > max(max1,max2)endif// long entryif tradetime thenIf pclong and mclong and eclong thenbuy positionsize contract at marketlongtradecounter=longtradecounter + 1tradecounter=tradecounter+1endif// short entryif pcshort and mcshort and ecshort thensellshort positionsize contract at marketshorttradecounter=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 then//graphonprice 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 then//graphonprice 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>=fridayclosetime) thensell at open stopexitshort at open stopendifendif//timeexitif timeexit thenif (hour=14 and minute=00) and pp>0 thensell at marketexitshort at marketelsif hour=23 thensell at marketexitshort at marketendifendifif onmarket thenif currentdayofweek=5 and time=fridayclosetime thensell at marketexitshort at marketendifendif// 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)1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on