SigScaleIn specyfic situation

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!

By definition Sell/Cover signal exits ENTIRE position. There is no way to do what you want to do without entering new position with appropriate accumulated size. You have to keep track of accumulated values yourself (for example using Cum)

Ok, but where can I set new value of position size?

Use SetPositionSize() as you do but the value of position when you enter it on reverse side should be calculated / accumulated size.