DRAWSEGMENT assistance
Forums › ProRealTime English forum › ProBuilder support › DRAWSEGMENT assistance
- This topic has 27 replies, 2 voices, and was last updated 3 years ago by IG_CFD_Trader.
-
-
07/09/2017 at 8:47 PM #40181
Thank you Nicolas. Your assistance is much appreciated.
07/10/2017 at 7:59 AM #40190Code looks good thank you. Now the last challenge is how to get it to draw segment lines only on the most current HiPoint and HiPoint[1] and LoPoint and LoPoint[1] and ignore all the rest of the historical Hipoints and Lopoints.
I tried introducing at the begining of the code:
DEFPARAM DRAWONLASTBARONLY = true
DEFPARAM CALCULATEONLASTBARS = 200
But this seems to work on only one of the points either Lopoint or Hipoint pending which one happens to be the most current on chart but did not draw both.
Any ideas?
07/10/2017 at 8:38 AM #40194That’s normal because we can’t never know in advance how much bars is necessary to loop in the past to find the last 2 needed points to draw a new trend line ..
So I add the “lookback” variable as an external one that can change to find the suitable one for each instrument/timeframe. Example attached on DAX 5 minutes, a lookback of 500 bars was needed in order to find the first high point above the current one!
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657DEFPARAM DRAWONLASTBARONLY = truestrength=20//lookback=100//strength*5TH=max(high,close[1])TL=min(low,close[1])r=0e=1r=strengthif high[r]>highest[r](TH) thene=1while high[r]=high[r+e] doe=e+1wendif high[r]>highest[r](TH[r+e]) thenHiPoint = high[r]HiBar = barindex[r]endifEndifif low[r]<lowest[r](TL) thene=1while low[r]=low[r+e] doe=e+1wendif low[r]<lowest[r](TL[r+e]) thenLoPoint = low[r]LoBar = barindex[r]endifendiffor i = 1 to lookback doif hibar[i]<>hibar thenif hipoint[i]>hipoint thendrawsegment(HiBar[i],HiPoint[i],HiBar,HiPoint) coloured(200,0,0)breakendifendifnextfor i = 1 to lookback doif lobar[i]<>lobar thenif lopoint[i]<lopoint thendrawsegment(loBar[i],loPoint[i],loBar,loPoint) coloured(0,200,0)breakendifendifnextreturn05/07/2021 at 5:00 AM #168996Hi Nicolas,
For example suppose I have an indicator that is returning a number on the current bar of the chart (let’s say that number for argument sake is +100 which is obviously >0).
The number +100 is continually changing increasing and decreasing depending on indicator calculation.
Now if the current number is +100 and the next (new) number is +99 then the number (although is still >0) has decreased by -1.
Is it possible to show +99 in red because it has decreased and as long as it is decreasing keep showing in red and when it increases again, show it in green.
I guess you need to be able to calculate difference between a number and itself in the same bar and show green if >0 and red if <0. Unless you have another trick to do it.
Regards,
Walid
05/07/2021 at 8:27 AM #169005I’m not sure your question is related to this topic, but anyway..
In order to compare a value between now and its previous state, during the same bar, you have to use a variable in array, which is not reset on each tick received in a bar:
example12345678910111213141516defparam drawonlastbaronly=truea = rsi[14]if a > $var[barindex] then //value now is more than before$var[barindex]=a //save RSI valuer=0 //no redg=255 //but green!elsif a < $var[barindex] then //value now is less than before$var[barindex]=a //save RSI valuer=255 //redg=0 //no green!endifdrawtext("#a#",barindex,50,dialog,bold,20) coloured(r,g,0) //text value in desired colorreturn a1 user thanked author for this post.
05/07/2021 at 2:05 PM #169042Thank you Nicolas. That’s great, it worked.
Now the challenge is how do I compute the change between a and $var[barindex] (i.e. the change between the stored “a” value and the new “a” value in the same bar.
For example to do it between the current bar and the previous bar, I would use change=(a-a[1])/a[1])*100 to get the %change.
How do I do same but in the current bar.
05/07/2021 at 2:26 PM #169045$var[barindex] is the last value you have stored, so basically your formula is:
((a-$var[barindex])/$var[barindex])*100
123456789101112131415161718defparam drawonlastbaronly=truea = rsi[14]change = round(((a-$var[barindex])/$var[barindex])*100,2)if a > $var[barindex] then //value now is more than before$var[barindex]=a //save RSI valuer=0 //no redg=255 //but green!elsif a < $var[barindex] then //value now is less than before$var[barindex]=a //save RSI valuer=255 //redg=0 //no green!endifdrawtext("#a# #change#%",barindex,50,dialog,bold,20) coloured(r,g,0) //text value in desired colorreturn a05/08/2021 at 1:46 AM #169074Thank you Nicolas. Much appreciated mate.
1 – in your email reply (plz see snapshot atatched), the expression ((a-$var[barindex])/$var[barindex])*100 seems to be included in the code and appears ABOVE the expression defparam drawonlastbaronly=true. Is this correct? In the web portal reply section above, the expression ((a-$var[barindex])/$var[barindex])*100 seems to be not included in the code. Is the expression required? and if so, where? above defparam or below it or expression not required at all?
2 – In both your email code and code in this portal above, you have Return VWAP. Is this a typo or VWAP is required after Return?
05/08/2021 at 5:15 PM #16913005/10/2021 at 12:45 AM #169216Thank you Nicolas.
By the way, how do I DRAWTEXT to the RIGHT of the current bar? Say I have 3 results which I want to drawtext the values to the right of the bar (1 result below the other) starting from (to the right of High) and listing them down in a row
05/10/2021 at 2:30 PM #16929405/11/2021 at 12:27 PM #169407Tnx mate.
If my indicator as a result of division of 2 numbers return a decimal number say 9.123 (3 decimals), is there a way I can make it return 6 decimals?
05/14/2021 at 6:12 AM #169636Hi Nicolas,
The below code resets the VWAP at the start of every trading day (say at 00:00 midnight).
d = max(1, intradaybarindex)
VWAP = SUMMATION[d](volume*typicalprice)/SUMMATION[d](volume)How do I make it reset every 2 trading days?
-
AuthorPosts