Hello members,
I am newbie in Amibroker. I am having one difficulty with sigscaleout command. 
Basically, I want to exit a trade if I get 0.5% profit and subsequently at 1% 
profit. A trailing stoploss is placed at 0.5% level. I am presently backtesting 
historical intraday data of Nifty Futures. I have adapted a code published in 
the group. This setup is for intraday future trading with 10% leverage. The 
price of a share is around 4400. I was only testing the long side of the trade 
with sigscaleout option. But, I am having the following difficulty. I could not 
fix the problem in the last 2/3 days.

After the trigger of sigScaleout, whenever full exit from the trade is taking 
place, the cash is showing a negative number when I am plotting the Equity. For 
e.g., if I am starting with initial capital of 5,00,000/= the cash is becoming 
around -36,00,000. And consequently, there is no trade taking place in the 
back-tester after this. I tried Equity(1) option in my code but the sigscaleout 
will not work there.

Am I going wrong somewhere. The code is given below. Please help. Thanks.

Regards,
Santanu
 

SetOption("InitialEquity", 500000);
//SetOption("MinShares", 100);
//SetOption("NoDefaultColumns", True );
//SetOption("AllowSameBarExit", True );
//SetOption("ActivateStopsImmediately" , True );
SetOption("FuturesMode", True );
SetOption("InterestRate", 0);
SetOption("CommissionMode", 1); //$$ per trade
SetOption("CommissionAmount", 0.031); // commission is accounted for in skid
SetOption("MarginRequirement", 10);
SetTradeDelays(0,0,0,0);
RoundLotSize = 50;
TickSize = 0.05;
timestore = TimeNum();
Buy = TimeNum() <= 150000 AND Cross( EMA( C, 4 ), EMA( C, 32 ) ); 
Sell = 0;
FirstProfitTarget = 0.5; // profit 
SecondProfitTarget = 1.0; // in percent 
TrailingStop = 0.5; // also in percent 
priceatbuy=0; 
highsincebuy = 0; 
exit = 0; 
for( i = 0; i < BarCount; i++ ) 
{ 
SellPrice[i]=0;
if( priceatbuy == 0 AND Buy[i] ) {
priceatbuy = BuyPrice[i];
}
if( priceatbuy > 0 ) {
highsincebuy = Max( High[i], highsincebuy ); 
if( exit == 0 AND High[i] >= ( 1 + FirstProfitTarget * 0.01 ) * priceatbuy ) { 
// first profit target hit - scale-out 
exit = 1; 
Buy[i] = sigScaleOut;
BuyPrice[i] = Max( Open[i], ( 1 + FirstProfitTarget * 0.01 ) * priceatbuy );
} 
else { // Added ELSE here for Initial entry trail stop
if( exit == 0 AND ( timestore[i] > 152000 OR Low[ i ] <= ( 1 - TrailingStop * 
0.01 ) * highsincebuy ) ) {
// trailing stop hit - exit
exit = 3;
SellPrice[ i ] = Min( Open[ i ], ( 1 - TrailingStop * 0.01 ) * highsincebuy );
}
}
if( exit == 1 AND High[i] >= ( 1 + SecondProfitTarget * 0.01 ) * priceatbuy ) {
// second profit target hit - exit 
exit = 2; 
SellPrice[i] = Max( Open[i], ( 1 + SecondProfitTarget * 0.01 ) * priceatbuy ); 
} 
else { // Added ELSE here for trail stop on scale out parcel
if(exit == 1 AND ( timestore[i] > 152000 OR Low[ i ] <= ( 1 - TrailingStop * 
0.01 ) * highsincebuy ) ) {
exit = 3;
SellPrice[ i ] = Min( Open[ i ], ( 1 - TrailingStop * 0.01 ) * highsincebuy );
}
}
if( exit >= 2 ) {
Buy[i] = 0; 
Sell[i] = exit + 1; // mark appropriate exit code 
exit = 0; 
priceatbuy = 0; // reset price 
highsincebuy = 0;
} 
} 
}
"buy = " + WriteVal(Buy);
"sell = " + WriteVal(Sell);
"priceatbuy = " + WriteVal(priceatbuy);
"buyprice = " + WriteVal(BuyPrice);
"sellprice = " + WriteVal(SellPrice);
PlotShapes( Buy * shapeUpArrow + Sell * shapeDownArrow , IIf( Buy, colorGreen, 
colorRed ), 0, IIf( Buy, Low, High ));
//SetPositionSize( 50, spsPercentOfEquity) ; // 2% of equity
SetPositionSize( 50, spsPercentOfPosition * ( Buy == sigScaleOut ) );



      Unlimited freedom, unlimited storage. Get it now, on 
http://help.yahoo.com/l/in/yahoo/mail/yahoomail/tools/tools-08.html/

Reply via email to