//------------------------------------------------------ // // Formula Name: Stop Loss Illustraton // Author/Uploader: Trading Tuitions // E-mail: support@tradingtuitions.com // Website: www.tradingtuitions.com //------------------------------------------------------ _SECTION_BEGIN("Stop Loss Illustraton"); // Define inputs SetTradeDelays( 0, 0, 0, 0 ); // No trade delays SetOption("InitialEquity", 100000); // Set initial equity to 100,000 SetOption("MinShares", 1); // Minimum shares to trade SetOption("CommissionMode", 0.02); // Commission rate // Define strategy Buy = Cross( MACD(), Signal() ); // Buy when MACD crosses above Signal Sell = Cross( Signal(), MACD() ); // Sell when MACD crosses below Signal // Define stop loss types StopLossPercent = 1.0; // Define a stop loss as a percentage of the entry price StopLossATR = 2.0; // Define a stop loss as a multiple of the Average True Range StopLossTrailing = 3.0; // Define a trailing stop loss as a multiple of the Average True Range // Define stop loss conditions StopLossPercentCondition = BuyPrice * ( 1 - StopLossPercent/100 ); // Define stop loss as a percentage of the entry price StopLossATRCondition = BuyPrice - StopLossATR * ATR(14); // Define stop loss as a multiple of the Average True Range StopLossTrailingCondition = HHV( High, 10 ) - StopLossTrailing * ATR(14); // Define trailing stop loss as a multiple of the Average True Range // Apply stop loss conditions ApplyStop( stopTypeLoss, stopModePercent, StopLossPercentCondition ); // Apply percentage stop loss ApplyStop( stopTypeLoss, stopModePoint, StopLossATRCondition ); // Apply ATR stop loss ApplyStop( stopTypeNBar, stopModePoint, StopLossTrailingCondition ); // Apply trailing stop loss