Hello, I try to code something like this:
- Every year I start with one share.
- On each bar, as long as the condition is met, I add 1 share.
- On a reverse signal, I start with the number of shares from the previous direction plus 1 additional share.
I am attaching a sample code, but in it, each direction is reset to the initial number of shares, which is 1 share:
indicator=MA( Close, 10 );
signalLong = Close > indicator;
signalShort = Close < indicator;
for( i = 1; i < BarCount; i++ )
{
if( signalLong[i] )
{
Cover[i] = 1;
Buy[ i ] = sigScaleIn;
BuyPrice[i] = CoverPrice[i] = Close[i];
}
else
if( signalShort[i] )
{
Sell[i] = 1;
Short[ i ] = sigScaleIn;
SellPrice[i] = ShortPrice[i] = Close[i];
}
}
SetPositionSize( 1, spsShares );
PlotShapes( cover * shapeUpTriangle, colorbrightGreen, 0, Low , -50 );
PlotShapes( Sell * shapeDownTriangle, colorRed, 0, High , -50 );
Plot(indicator,"",colorYellow,styleDots);
Plot(Close,"",colorwhite,stylecandle);
thanks for your help!