I just want to average down a stock when my open position with this particular stock is profitable. How would I have to code this?
Size:
Color:
Size:
Color:
Thanks but I'm not very familiar with coding. What I asked for shall be one condition of a multicondition group. I just want to buy more shares of a particular stock when my already open position of that stock is profitable. Could you provide me that code?
Size:
Color:
For Rule-based strategies, you have the option to add a condition from the "Position-Based" group called "Current position is profitable".
Size:
Color:
You're right. But as far as I understood it the rule takes the most recent position which is not necessarily the same stock it buys some more of. Or am I wrong?
Size:
Color:
In general [and unless you're doing something more advanced like pairs trading or symbol rotation] scripts operate on one symbol at a time. So in a script "LastPosition" will refer to the LastPosition entered for the "clicked" symbol, or the one currently running in a MSB (Multi Symbol Backtest).
Make sure you add that condition with an "OR" (or as a separate entry condition) since it requires that you have an active position already.
Size:
Color:
I'm performing MSBs and using the position sizer "Avg Down with Pct Equity Limit." The position size is 5% and the max. % of equity is 20.
When filling up a position to the 20% and buying a stock a second or third time I want the rule to do this only when this particular position is not more than X% on the negative side.
How would I have to code this? Sorry for being not precise enough in the beginning.
Size:
Color:
In this case, you have to open the code in a new Strategy window and manually edit it. By default, "Current open position is profitable" creates this code behind:
CODE:
Please log in to see this code.
I think this should do it:
CODE:
Please log in to see this code.
Where "-X" is your
X% on the negative sideUPDATE: code edited (NetProfitAsOfBar > NetProfitAsOfBarPercent), thanks Cone
Size:
Color:
Does
if (LastActivePosition.NetProfitAsOfBar(bar) >= -15)
mean not more than 15% on the negative side?
Size:
Color:
You should be using NetProfitAsOfBarPercent.
Size:
Color:
Earlier you wrote "in a script "LastPosition" will refer to the LastPosition currently running in a Multi Symbol Backtest."
What I want the script to do is to just buy more shares of a particular stock if the already bought are not more than X% on the negative side. As far as I got you the script as it is now just looks if the last position entered is not more than X% negative. Regardless what stock it is.
Let me give you a small example to make it more clear: One day the script buys AXP. On the next day it buys XOM. On the third day it attempts to buy AXP again. But this shall only be done if AXP is not more than X% negative.
Size:
Color:
If AXP is the symbol currently processed by your MSB, LastPosition refers to that symbol's last Position, i.e. AXP.
Size:
Color: