Issue with scale-ins

Hi,

I am including my code below. I have changed the indicators and numbers to sample names numbers such as ABCDEF, GHIJKL & MNOPQR.

When I run back-tests on this code there are certain issues with the scale-ins. The scale-ins are given preference some times and other times Buy signals are given preference. I can’t seem to identify any fixed pattern that the back-test is following.

Also, the scale-ins are being classified as Exit signals instead of Entry signals. I believe that solving this issue will also resolve the above mentioned problem.

I want scale-ins to be given preference and after these scale-in signals are taken I would like the remaining Buy signals to be ranked on the basis of the position score.

Could you help me out with this please?

[code] {
Buy = Close > ABCDEF;
BuyPrice = Close;
Sell = 0;

priceAtBuy = 0;
inposition = 0;
scaleincountA = 0;
SL1 = SL2 = SL3 = SL1a = SL2a = SL3a = priceAtBuyA = inpositionA = Null;

inrange = 1;//Status( "barinrange" );

for( i = 0; i < BarCount; i++ )
{
    scaleincount = 0;

    if( inrange[ i ] )
    {
        if( inposition )
        {
            SL2 = GHIJKL[ i ];
            SL3 = MNOPQR[ i ];
        }
        // handle exits
        if( Close[ i ] < Max( SL1, Max( SL2, SL3 ) ) )
        {
            Sell[ i ] = True;
            SL1 = SL2 = SL3 = Null;
            inposition = priceAtBuy = 0;
        }

        if( inposition == 1 AND Close[ i ] > 1.01 * priceAtBuy )
        {
            Buy[ i ] = sigScaleIn;
            BuyPrice[ i ] = Close[ i ];
            SL1 = priceAtBuy * 0.98;
            scaleincount++;
            inposition++;
        }

        if( inposition == 2 AND Close[ i ] > 1.02 * priceAtBuy )
        {
            Buy[ i ] = sigScaleIn;
            BuyPrice[ i ] = Close[ i ];
            SL1 = priceAtBuy * 0.99;
            scaleincount++;
            inposition++;
        }

        if( Buy[ i ] == 1 )
        {
            if( !inposition AND !Sell[ i ] )
            {
                inposition = 1;
                priceAtBuy = BuyPrice[ i ];
                SL1 = priceAtBuy * 0.97;
                SL2 = GHIJKL[ i ];
                SL3 = NMOPQR[ i ];
            }
            else
                Buy[ i ] = 0;
        }


        // write stops to arrays
        SL1a[ i ] = SL1;
        SL2a[ i ] = SL2;
        SL3a[ i ] = SL3;
        inpositionA[ i ] = inposition;
        priceAtBuyA[ i ] = priceAtBuy;
        scaleInCountA[ i ] = scaleincount;

    }
}
SetPositionSize( scaleInCountA * 5, IIf( Buy == sigScaleIn, spsPercentOfEquity, spsNoChange ) );

PositionScore = (Volume/EMA(Volume, 50));
} [/code]

Could anyone help out with this please?

Have you tried to debug it with the Detailed Log turned on? That will display exactly what is happening on each bar during the backtest:

1 Like