Hi,
I want to make the positionsize depending of the strategyprofit over/under its average. With something like this:
IF STRATEGYPROFIT>AVERAGE[5000](STRATEGYPROFIT) THEN
POSITIONSIZE = 2
ELSE
POSITIONSIZE = 1
ENDIF
It doesn´t work. Trying different ways and nothing, I am getting a little crazy about it. Anybody knows why?
Could it be that when you start strategy profit = zero and you then comparing that to an average of zero?
Maybe you are right but in that case shouldn´t it affect only the first 5000 candles (the periods of the avegarage)
Anyway I will try to take that in consideration and will see
Thanks Vonasi
Try adding
graph strategyprofit
graph average[5000](strategyprofit)
to your strategy, provided you have PreLoaded enough bars.
I tried and it always shows the same value, so I guess it is not allowed, though syntax is correct!
I put this in a code and it gave me graph lines.
sp = strategyprofit
spave = Average[5000](sp)
Graph sp
graph spave
Yes, I saw it before asking and I didn´t find nothing to help me. But I see now in the replays a couple of people comment that it doens´t seem to work, Nicholas says it will take it to the PRT people. This is more than two years ago, I guess it doesn´t work yet, it´s a shame it really looked like a nice way to avoid big losses with systems go bust
I found this topic that contains other ways to get the same idea, just seemed more complicated, I liked the simplicity of the strategyprofit average 🙁
Position Size Management – Performance based increases
Try my code in post #72463. It appears the issue is having StrategyProfit in the average calculation. If it is a variable it works.
So your code should be:
sp = strategyprofit
spave = Average[5000](sp)
IF STRATEGYPROFIT > spave THEN
POSITIONSIZE = 2
ELSE
POSITIONSIZE = 1
ENDIF
Not tested yet.
You should be aware that StrategyProfit is only updated when positions are closed so if you have an accumulating positions strategy then if it starts with the equity curve above the average and then you keep adding to a losing position it will add positionsizes of 2 continually as it will not be aware that your floating equity curve is below the average of the equity curve.
I had the same idea about the variables and was trying… I had to do it a couple of times because I thought I did something wrong… no operations at all!!! It seems something is really wrong with this thing of the average/strategyprofit
No accumulated positions in this system
That is strange because I just threw it into a rubbish strategy and it works for me. Graphed line is positionsize.
…and the strategyprofit and strategyprofit average
Yes, Vonasi, you are right, using your code it seems to work.
I think I have nailed where is the key, is using a variable in the subject of the average so…
Average[5000](strategyprofit) --> NO work
Average[5000](sp) --> YES work
so we don´t need the average variable, just this seems to work…
sp = StrategyProfit
IF strategyprofit > Average[5000](sp) THEN
POSITIONSIZE = 2
ELSE
POSITIONSIZE = 1
ENDIF
Strange but the important thing is that the problem is solved
Thank you