Summation with for to next loop
Forums › ProRealTime English forum › ProBuilder support › Summation with for to next loop
- This topic has 16 replies, 5 voices, and was last updated 4 years ago by VN.
-
-
08/13/2018 at 6:53 PM #78095123DEFPARAM DRAWONLASTBARONLY=TRUELFC=summation[5](close)
I’d like to achieve the same result with the following simple ‘for next loop’instead using ‘summation’ but there is no output using the ‘for next loop’
12345for i=1 to 5 doLFC=close[i]+LFCnextreturn LFC08/13/2018 at 7:05 PM #78097The last 5 bars are 0-4, not 1-5 (these are the previous 5 bars).
The problem could be the value returned by LFC, too big to be displayed.
On DAX that would be about 62000 (5 * 12400), but your are not resetting it to 0 at the beginning, so within a few bars that could become a huge number!
08/13/2018 at 7:18 PM #7809808/13/2018 at 8:11 PM #78101Vagus_Lux – please use the ‘Insert PRT Code’ button when putting code in your posts to make it more readable for others. I have tidied up your posts for you. 🙂
I am guessing that Robert is posting from his phone otherwise he would have done the same!
08/13/2018 at 8:22 PM #78103AhAhAh…. I am indeed posting from my phone!
11/09/2018 at 7:22 PM #84509I have a quick question there.
In the example code below, I do have the following query
12345for i=8 to 20 doLFC=close[i]+close[28]nextreturn LFCis close[28] inside the for statement 28 candles from close[0] or 28 candles from “i” or “close[i]” ?
Kind Regards,
11/09/2018 at 7:30 PM #84510From CLOSE[0], it is constant through the loop.
To be from i you’ll have to write 28+i within brackets.
1 user thanked author for this post.
03/11/2020 at 5:13 PM #121845Hi Roberto, I am trying to count the total number of times an event took place in a given timeframe of my chart.
For example I am counting the number of times RSI crossed above 70 and I want that calculation to be applied to any timeframe so from the beginning of time to end of time loaded.
I don’t know how to set the beginning and end of time in a FOR NEXT loop.
Any eloquent way that this can be achieved?
03/11/2020 at 6:33 PM #121864The beginning is always BARINDEX=0.
BARINDEX is the progressive numeber of bars, so you need to do is, from current bar to zero:
1234567Count = 0FOR i = BarIndex DOWNTO 0IF Rsi[14](close)[i] CROSSES OVER 70 THENCount = Count + 1ENDIFNEXTRETURN Count AS "Count"But… all the above is not necessary, since any indicator ALWAYS starts from the beginning, so all you want to do is to sum any occurrence of the event:
12345ONCE Count = 0IF Rsi[14](close) CROSSES OVER 70 THENCount = Count + 1ENDIFRETURN Count AS "Count"1 user thanked author for this post.
05/18/2020 at 3:59 PM #13216505/18/2020 at 4:08 PM #132166There you go:
1x = summation[31](Rsi[14](close) crosses over 70)X will retain the value you are looking for.
from current bar [0] up to 30 bars ago [30], it’s 31 bars.
There’s not need to use loops here.
05/18/2020 at 4:32 PM #132173thanks Roberto! I did not think of using summation in this context, but that works nicely!
I used this code to also count the number of times the current close was less than prior close, but that doesn’t return the right answer.
1x = summation[31](close < close[1])Have i done something wrong?
05/18/2020 at 4:45 PM #132177What you have coded will compare the current close to the previous close and then the 2nd to last close to the one before that and then the third to last close to the one before that…. and so on and so on.
If you want to compare the latest close to the 30 previous candles then you will need a loop.
123456x = 0for a = 1 to 30if close < close[a] thenx = x + 1endifnext05/18/2020 at 5:26 PM #132183thanks vonasi..
the above is part of a wider problem i am trying to code, but with not much success.
I am trying to count the number of times the price changed direction in a specified period e.g. last 10 candles, in other words the number of times the candle colour changed in the last 10 candles.
so for example, if the first 3 candles were green, but the forth was red, then the counter = 1 as that is the 1st time the close went below prior close.
then candle 5 and 6 were both green then the counter = 2 since the close at candle 5 reversed from red (4th candle) to green (5th candle). I don’t want to count the candles when the colour is same, only when they reverse.
05/18/2020 at 5:31 PM #1321841234Bullish = close > openBearish = close < openChange = (Bullish AND Bearish[1]) OR (Bullish[1] AND Bearish)x = summation[10](Change)There you go.
-
AuthorPosts
Find exclusive trading pro-tools on