set big line values automatically
12/02/2017 at 2:19 AM #54507
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 #54516
Hi 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 #54579
Here’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 #54585
Hi 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 #54597
Thanks 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 #54633
You 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 #54730
I 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 Level00Down
Thanks for the tips!12/05/2017 at 2:28 AM #5473112/05/2017 at 7:53 AM #54735
Thank 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 #54822
Very strange: When I’m not connected, I see that there are attachment in some of thes posts but when I’m logged, I can’t see attachments.
And that is not the case in other disscusions.
Am I the only one who have thi problem?12/05/2017 at 10:03 PM #54826
Are 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 #54850
I 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 DAX12/07/2017 at 8:31 AM #54940
Ok. 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.