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=======================================
//SERÁ USADA UMA TENDÊNCIA DIÁRIA, BASEADA NAS MÉDIAS MÓVIES
//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;
//============================ENTRADA======================================
// SOMENTE O CRUZAMENTO DE hlv E CONFIRMAÇÃO DAS MM
Buy = Cross(Hlv,0) AND uptrend;
//================================SAÍDA=====================================
Sell = Cross(0,Hlv);
Buy = ExRem( Buy, Sell );
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 );
Buy = Buy + SigScaleIn * DoScaleIn;
SetPositionSize( pct, spsPercentOfEquity );
SetPositionSize( pct, IIf( Buy == sigScaleIn, spsPercentOfPosition, spsNoChange ));