// Downloaded From https://www.WiseStockTrader.com
//Trend Following Code in AmiBroker
{/*DESCRIPTION
	Strategy: 	Basic Trend Following Strategy, MA cross MA
	Trades:		Long only
	Result:		Acceptable
*/}
 
{//OPTION
	SetOption("InitialEquity", 1000000);
	SetOption("MaxOpenPositions", 4);
	SetOption("MinShares", 100);
	RoundLotSize = 100;
	SetOption("CommissionMode", 1);
	SetOption("CommissionAmount", 0.16);
	SetTradeDelays(1, 1, 0, 0);
	BuyPrice = SellPrice = Open;
}
 
{//SPLIT
	C1 = Ref(C, 1);
	O1 = Ref(O, 1);
	O2 = Ref(O, 2);
	detectSplit = 0.35;
	buyAvoidSplit = !(C1/O1 < 1-detectSplit) AND !(C1/O1 > 1+detectSplit) AND
					!(O2/C1 < 1-detectSplit) AND !(O2/C1 > 1+detectSplit);
	sellAvoidSplit = (C1/O1 < 1-detectSplit) OR (C1/O1 > 1+detectSplit) OR
					(O2/C1 < 1-detectSplit) OR (O2/C1 > 1+detectSplit);	
}
 
{//SIGNAL
	//Stock Conditions
	buyCon1 = BarsSince(Cross(MA(C, 10),MA(C, 20))) < 10 AND C > 1;
	buyCon2 = ADX() > 25 AND PDI() > MDI();
	buyCon3 = MACD() > Signal();
	buyCon4 = MA(C, 20) > MA(C, 60);
	buyCon5 = C*V > Ref(HHV(C*V, 20), -1) AND C*V > 1000000;	
	sellCon1 = MACD() < Signal();
	sellCon2 = MA(C, 20) < MA(C, 60);
	//Executing Signals
	Buy = buyCon1 AND buyCon2 AND buyCon3 AND buyCon4 AND buyCon5 AND buyAvoidSplit;
	Sell = (sellCon1 AND sellCon2) OR sellAvoidSplit;	
	
	Buy = ExRem(Buy, Sell);
	Sell = ExRem(Sell, Buy);
	Short = Cover = 0;
}
 
{//POSITION
	SetPositionSize(5, spsPercentOfEquity);
	PositionScore = C*V/Ref(MA(C*V, 20), -1);
}
 
{//STOP
	ApplyStop(stopTypeLoss, stopModePercent, 10);
	ApplyStop(stopTypeProfit, stopModePercent, 25);
	ApplyStop(stopTypeTrailing, stopModePercent, 20);
}
 
{//MC
}