count an occurrence relative to the last value
Forums › ProRealTime English forum › ProOrder support › count an occurrence relative to the last value
- This topic has 11 replies, 2 voices, and was last updated 6 years ago by
Be-n.
-
-
09/25/2019 at 4:58 PM #108459
Hello everybody !
I have a puzzle to submit to you. Here is my problem :
Whenever a closing is strictly greater than a certain percentage since my last position, I indicate it on my graph as follows :
123456789IF close[0]>1.01*TRADEPRICE THENbonus=1ELSIF close[0]>1.02*TRADEPRICE THENbonus=2ELSIF close[0]>1.03*TRADEPRICE THENbonus=3ELSEbonus=0ENDIFAt my last closing, I have an increase of 2.43% (bonus=2)
Where :
1lastclose = (close-TRADEPRICE)/TRADEPRICE)*100my question :
How to know how many times lastclose was greater than 2% (that is to say bonus=2) ? Let’s say this case (bonus = 2) has occurred 10 times since the start of my strategy.
I imagine that a loop is necessary …
Thx in advance for your time and explanations … and sorry for my english !
09/25/2019 at 5:02 PM #10846109/25/2019 at 5:09 PM #10846209/25/2019 at 5:45 PM #108465Sorry, I might not understand what you want or!? Count occurrences by incrementing a variable:
12345678910111213IF close[0]>1.01*TRADEPRICE THENbonus=1ELSIF close[0]>1.02*TRADEPRICE THENbonus=2ELSIF close[0]>1.03*TRADEPRICE THENbonus=3ELSEbonus=0ENDIFif bonus=2 thencount=count+1endif09/25/2019 at 9:06 PM #108482No problem Nicolas. I misspoke. I replaced ‘Bonus‘ by ‘Earnings‘ for more readability.
I would like my last result (‘LastClose‘ = 1.43) determine how many times this same result was found previously in my strategy. I attach to my example a picture of my board.
In this example, if (‘LastClose‘ = 1.43), I would like to determine how many times this result has already been found 7 times previously (‘Earnings‘ = 1) since the beginning of my strategy (red sticks).
In this example, if (‘LastClose‘ = 2.14), I would like to determine how many times this result has already been found 4 times previously (‘Earnings‘ = 2) since the beginning of my strategy (red sticks).
And so on…
Here is a very simple strategy in order to know where I want to go :
1234567891011121314151617181920212223242526MyRSI = RSI[14](Close)MyBollingerDown = BollingerDown[25](Close)MyBollingerUp = BollingerUp[25](Close)IF MyRSI < 30 AND Close < MyBollingerDown THENBUY 1 SHARE AT MARKETENDIFIF (MyRSI > 70 AND Close > MyBollingerUp) OR (lastclose > 1) THENSELL AT MARKETENDIF//The last result is determinedLastClose = (close[0]-TRADEPRICE)/TRADEPRICE)*100IF close[0]>1.01*TRADEPRICE THENEarnings = 1ELSIF close[0]>1.02*TRADEPRICE THENEarnings = 2ELSIF close[0]>1.03*TRADEPRICE THENEarnings = 3ELSEEarnings = 0ENDIF<em>// According to the result of 'LastClose', I want to know how many times this same result has been found before ...</em>So I thought to make this loop :
123456789101112131415161718192021222324252627IF LastClose >= 1 AND LastClose < 2 THENResult = 1ELSIF LastClose >= 2 AND LastClose < 3 THENResult = 2ELSIF LastClose >= 3 THENResult = 3ELSEResult = 0ENDIFIF STRATEGYPROFIT[0]<>STRATEGYPROFIT[1] THENMainLoop=MainLoop+1ELSIF STRATEGYPROFIT[0]=0 THENMainLoop=0ENDIFIF MainLoop=0 THENBeginning=BARINDEXENDIFBegin=BARINDEX-BeginningFOR j=0 TO Begin THENIF Earnings(j)>Result AND Result<>0 THENn=n+1 <em>// n = Number of times where 'Earnings' equals 'Result' since the start of the strategy</em>ENDIFNEXTI hope it’s clearer for you … Thanks in advance !
09/26/2019 at 9:13 AM #10850809/26/2019 at 9:24 AM #10851009/26/2019 at 9:32 AM #108512closed orders = orders not at market anymore.
To make it shorter: you want to know how many orders achieved gain above 1%, 2% and 3% since the start of the strategy? But only after their closure? (or while they were opened? = at market).
09/27/2019 at 4:00 PM #10867809/27/2019 at 4:55 PM #10868209/27/2019 at 6:34 PM #108688Thx Nicolas ! The SUMMATION function seems a good way !
On the other hand, it requires to enter a fixed value, (1 in your example). In this case, it works perfectly. However, this value changes during my strategy. In my example, this value can be 1 or 2 or 3 but potentially more. The idea would be to use a variable. In this case, it would give :
code :
1bonus = summation[max(1,barindex)](strategyprofit>strategyprofit[1] and positionperf(1)=Result)Where ‘Result‘ correspond to :
1234567891011LastClose = (close[0]-TRADEPRICE)/TRADEPRICE)*100IF LastClose >= 1 AND LastClose < 2 THENResult = 1ELSIF LastClose >= 2 AND LastClose < 3 THENResult = 2ELSIF LastClose >= 3 THENResult = 3ELSEResult = 0ENDIFBut there, it doesn’t work unfortunately …
I think you understand what I want to do. A big thx for your help ! 😉
09/27/2019 at 6:52 PM #108690 -
AuthorPosts
Find exclusive trading pro-tools on