# How to "Scaling In" in trading system

Hello.

I want to use scale in to increase the number of contracts over the course of trading based on the purchase price of the asset. I have the buy plus buy the increment condition. Follow the code below. Any suggestion?

``````//=============================SETUP DO HILO=======================================

//lÛgica de decis„o de qual escada usar
Hld = IIf(Close > Ref(MA(H, Mp_acima),-1),1,IIf(Close <= Ref(MA(L,Mp_baixo),-1),-1, 0));

Hlv = ValueWhen(Hld != 0, Hld, 1); /

//============================TENDÊNCIA======

MAFAST = EMA( Close, 10 );
MASLOW = EMA( Close, 300 );
//Longa = Optimize("NLonga",300,50,300,5);

downtrend = MAFAST < MASLOW;
uptrend = MAFAST > MASLOW;

// SOMENTE O CRUZAMENTO DE hlv E CONFIRMAÇÃO DAS MM

//================================SAÍDA=====================================
Sell = Cross(0,Hlv);

Sell = ExRem( Sell, Buy );

RiskPerContract = 2 * ATR( 20 );
ApplyStop( stopTypeLoss, stopModePoint, RiskPerContract, True );

//============================Position SIZE==================================

PositionRisk = 0.01;
pct = (MarginDeposit*PositionRisk*100 / (PointValue * ATR(20)));

DoScaleIn = ExRem(C > 0.5*ATR(20), Sell );

SetPositionSize( pct, spsPercentOfEquity );
SetPositionSize( pct, IIf( Buy == sigScaleIn, spsPercentOfPosition, spsNoChange ));

``````

Give us a hint: what is not working?

The Scale in is not working

The setpositionsize is not working!

The first thing I would do is add a few lines of code so that you can run this as an Exploration. Verify that what's in the Buy array and the PositionSize array are what you expect.

I believe if you are using applystop code, then:
sell=0;//it should be
Equity(1,0); //this should be there

Sorry, if I am not correct.