[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Help with Amibroker Stops



PureBytes Links

Trading Reference Links

Hi All,


I am trying to develop a system using Ami and wrote the code (see 
below).   Unfortunately the stops do not work.  I would 
appreciate if someone can help me to identify what is wrong with the 
code or whether there are alternative means of getting 
these stops to work.

Thanks in advance.



System
=========


ENTRY CONDITIONS  = IF close price crosses up thru most recent peak 
enter
	



TRAILING PROFIT STOP = Exit IF Close < 3ATR (30) falls below Highest 
H since Entry

INITIAL TRAILING STOP = 3ATR over 30 periods - (Use Max. $500 and PS 
of $5,000)

Max Stop Loss = 25%



CODE
===========

TimeFrameSet(inWeekly);
SetOption("MaxOpenPositions", 100 ); 
SetChartOptions( 0, chartShowDates | chartShowArrows);
/*=================================================================*/
   

Plot( C, "Close", colorBlack, styleBar ) ; 

/*=================================================================*/

// PrevPreak calculation
Previous_Peak_Period = Param("Previous_Peak_Period",32,5,60,1);
PrevPreakLine = HHV(H,Previous_Peak_Period);

Plot(PrevPreakLine ,"PrevPreakLine ",colorBlue, styleLine | 
styleStaircase);

/*=================================================================*/
// Buy and Sell Signals  

Buy= Cross(C,Ref(PrevPreakLine ,-1)) ;




Plot((PrevPreakLine - 3*ATR(30)),"Sell Line", colorRed, styleLine | 
styleStaircase);

Sell = ApplyStop(stopTypeTrailing, stopModePoint, 3*ATR(30), True, 
True ); /* single-line implementation of Chandelier exit */
// Note: if Sell = 0; and then Applystop, no signals are 
generated !!!



 
Buy = ExRem(Buy,Sell);           
Sell = ExRem(Sell,Buy);   


/*=================================================================*/
 
/*  Van Tharp's ATR-based position sizing technique & trailing stop 
loss */ 
 
MMATRperiod=Param("MonManATRPeriod", 30, 5, 52, 1);       
MMATRMUL = Param("MonManATRMUL", 3, 2, 10, 0.1);       

  
ATRTrailStopAmount = MMATRMUL * MA(ATR(1),MMATRperiod );
       
Risk1= Param("Dollar_Risk ", 500, 1, 25000, 50);  
PS = (Risk1/ATRTrailStopAmount )*BuyPrice;  
PSLimit = Param("PSlimit",5000,1000,50000,500);
PositionSize = IIf(PS<PSLimit ,PS,PSLimit );


Capital = Param("Start Capital ",50000, 25000, 1000000,2500); 
SetOption("InitialEquity", Capital ); /* starting capital */

  
ApplyStop( stopTypeLoss, stopModePoint, ATRTrailStopAmount , 0, 
False ); // implement money man stop

/*=================================================================*/
 
/* max loss stop */ 
  
MaxStopLoss = Param( "max. loss stop level", 25, 2, 40, 1 ); 
ApplyStop(stopTypeLoss,  stopModePercent, MaxStopLoss , 0, False );  
  
/*=================================================================*/