The code below is about scale in/scale out in backtest function.
I study how to scale in/out from this link http://www.amibroker.com/members/library/formula.php?id=1380
and simplify it more easily as the basic requirement.
SetOption ("InitialEquity", 100000);
SetOption ("MaxOpenPositions", 1);
SetOption ("MinShares", 100);
RoundLotSize=100;
FirstBuy = Cross( EMA( C, 10 ), eMA( C, 200 ) );
Buy2=Cross( EMA( C, 25 ), eMA( C, 200 ) );
Buy3=Cross( EMA( C, 50 ), eMA( C, 200 ) );
Sell1=Cross( EMA( C, 25 ), eMA( C, 10 ) );
Sell2=Cross( EMA( C, 50 ), eMA( C, 10 ) );
InitialEntry=FirstBuy;
ScaleInentry=Buy2 OR Buy3;
ScaleOutExExit=Sell1;
Buy= IIf(InitialEntry,1, IIf(ScaleInentry ,sigScaleIn,IIf(Sell1,sigScaleOut,0)));
Sell=Sell2;
FirstEntryPosSize=50; //buy 50%
ScaleEntryPosSize2=30; // buy 30%
ScaleEntryPosSize3=20; //buy 20%
ScaleExit1=50; //first Sell 50% with scale out
PosSize=(FirstBuy*FirstEntryPosSize)+(Buy2*ScaleEntryPosSize2)+(Buy3*ScaleEntryPosSize3)+(Sell1*ScaleExit1);
SetPositionSize(PosSize,spsPercentOfEquity);
My question is the following.
- Can I apply sigScaleIn sigScaleOut in Automated Trading With Amibroker such as IB
I would like to see sample code to implement in the real world rather than just BackTest.
- For more requirementm I try to change from cross function to ">" "<" operator instead cross function as below
FirstBuy = EMA( C, 10 )> EMA( C, 200 );
Buy2=EMA( C, 25 )> EMA( C, 200 );
Buy3=EMA( C, 50 )> EMA( C, 200 ) ;
Sell1=EMA( C, 10 )< EMA( C,250 ) ;
Sell2=EMA( C, 10 ) < EMA( C, 50 ) ;
Unfortunately, The result isn't the same as the first one.
I understand that ExRem/Flip function may help me to complete the second code but I don't sure what step to place these code to my code , pleas guide a bit for applying ExRem/Flip to the above code
- What level for scale in /out to need to use CBI programming? my sample may be unnecessary.
Thank you in advance.
Pongthorn