Be-nParticipant
Average
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 :
IF close[0]>1.01*TRADEPRICE THEN
bonus=1
ELSIF close[0]>1.02*TRADEPRICE THEN
bonus=2
ELSIF close[0]>1.03*TRADEPRICE THEN
bonus=3
ELSE
bonus=0
ENDIF
At my last closing, I have an increase of 2.43% (bonus=2)
Where :
lastclose = (close-TRADEPRICE)/TRADEPRICE)*100
my 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 !
You don’t need a loop if you check the condition on each candlestick close. Just make an increment of a variable each time bonus=2 and that’s enough.
Be-nParticipant
Average
Thx Nicolas !
But if I have an increase of 1.43% ($bonus=1) the next time… and so on…
How do I get the number of occurrences where $bonus = 1 from the beginning of my strategy if $lastclose = 1.43 ? :/
Sorry, I might not understand what you want or!? Count occurrences by incrementing a variable:
IF close[0]>1.01*TRADEPRICE THEN
bonus=1
ELSIF close[0]>1.02*TRADEPRICE THEN
bonus=2
ELSIF close[0]>1.03*TRADEPRICE THEN
bonus=3
ELSE
bonus=0
ENDIF
if bonus=2 then
count=count+1
endif
Be-nParticipant
Average
No 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 :
MyRSI = RSI[14](Close)
MyBollingerDown = BollingerDown[25](Close)
MyBollingerUp = BollingerUp[25](Close)
IF MyRSI < 30 AND Close < MyBollingerDown THEN
BUY 1 SHARE AT MARKET
ENDIF
IF (MyRSI > 70 AND Close > MyBollingerUp) OR (lastclose > 1) THEN
SELL AT MARKET
ENDIF
//The last result is determined
LastClose = (close[0]-TRADEPRICE)/TRADEPRICE)*100
IF close[0]>1.01*TRADEPRICE THEN
Earnings = 1
ELSIF close[0]>1.02*TRADEPRICE THEN
Earnings = 2
ELSIF close[0]>1.03*TRADEPRICE THEN
Earnings = 3
ELSE
Earnings = 0
ENDIF
// According to the result of 'LastClose', I want to know how many times this same result has been found before ...
So I thought to make this loop :
IF LastClose >= 1 AND LastClose < 2 THEN
Result = 1
ELSIF LastClose >= 2 AND LastClose < 3 THEN
Result = 2
ELSIF LastClose >= 3 THEN
Result = 3
ELSE
Result = 0
ENDIF
IF STRATEGYPROFIT[0]<>STRATEGYPROFIT[1] THEN
MainLoop=MainLoop+1
ELSIF STRATEGYPROFIT[0]=0 THEN
MainLoop=0
ENDIF
IF MainLoop=0 THEN
Beginning=BARINDEX
ENDIF
Begin=BARINDEX-Beginning
FOR j=0 TO Begin THEN
IF Earnings(j)>Result AND Result<>0 THEN
n=n+1 // n = Number of times where 'Earnings' equals 'Result' since the start of the strategy
ENDIF
NEXT
I hope it’s clearer for you … Thanks in advance !
Ok but you confirm that the statistic is calculated with closed orders, right?
Be-nParticipant
Average
Absolutely Nicolas … If I correctly understand your question, the result (statistic?) is determined by the closing of a candle …
closed 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).
Be-nParticipant
Average
Hi Nicolas, sorry for my late answer. I thought I had a solution but no…
I wish to know how many orders achieved gain above 1%, 2% and 3% (for example) since the start of the strategy after the closure of my orders. Thx in advance ! 😉
For instance, a rough solution for 1% one (and not tested, please do):
bonus1 = summation[max(1,barindex)](strategyprofit>strategyprofit[1] and positionperf(1)>=1 and positionperf(1)<2)
Be-nParticipant
Average
Thx 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 :
bonus = summation[max(1,barindex)](strategyprofit>strategyprofit[1] and positionperf(1)=Result)
Where ‘Result‘ correspond to :
LastClose = (close[0]-TRADEPRICE)/TRADEPRICE)*100
IF LastClose >= 1 AND LastClose < 2 THEN
Result = 1
ELSIF LastClose >= 2 AND LastClose < 3 THEN
Result = 2
ELSIF LastClose >= 3 THEN
Result = 3
ELSE
Result = 0
ENDIF
But there, it doesn’t work unfortunately …
I think you understand what I want to do. A big thx for your help ! 😉
Be-nParticipant
Average
Sorry this code is better :
bonus = summation[max(1,barindex)](strategyprofit>strategyprofit[1] and Earnings=Result)
Whenever the last result (‘Result’) was equal to the same previous results (‘Earnings=Result’)
Thx !