Trading Indicator & Parameter: super trend with period 10 and multiplier 3,
Rule: buy/sell based on the color change of the super trend,
Target Points: 10,
StopLoss Points: 20
———— START CODE ————
Inputs:
SuperTrendPeriod(10),
SuperTrendMultiplier(3),
Target(10),
StopLoss(20);
Variables:
SuperTrend(0),
TradeEntryPrice(0),
TradeExitPrice(0),
TradeProfit(0),
TradeStopLoss(0),
TradeActive(false);
SuperTrend = SuperTrend(SuperTrendPeriod, SuperTrendMultiplier);
// Buy when SuperTrend turns from red to green
if SuperTrend crosses above close and not TradeActive then
Buy next bar at close;
TradeEntryPrice = close;
TradeStopLoss = close – StopLoss * MinMove;
TradeActive = true;
// Sell when SuperTrend turns from green to red
if SuperTrend crosses below close and not TradeActive then
Sell short next bar at close;
TradeEntryPrice = close;
TradeStopLoss = close + StopLoss * MinMove;
TradeActive = true;
// Check for exit conditions
if TradeActive then
// Exit on target
if MarketPosition = 1 and close >= TradeEntryPrice + Target * MinMove then
Sell next bar at close;
TradeExitPrice = close;
TradeProfit = (TradeExitPrice – TradeEntryPrice) * BigPointValue;
TradeActive = false;
if MarketPosition = -1 and close <= TradeEntryPrice – Target * MinMove then
Buy to cover next bar at close;
TradeExitPrice = close;
TradeProfit = (TradeEntryPrice – TradeExitPrice) * BigPointValue;
TradeActive = false;
// Exit on stop loss
if MarketPosition = 1 and close <= TradeStopLoss then
Sell next bar at close;
TradeExitPrice = close;
TradeProfit = (TradeExitPrice – TradeEntryPrice) * BigPointValue;
TradeActive = false;
if MarketPosition = -1 and close >= TradeStopLoss then
Buy to cover next bar at close;
TradeExitPrice = close;
TradeProfit = (TradeEntryPrice – TradeExitPrice) * BigPointValue;
TradeActive = false;
—————— END CODE ——————
This code defines input parameters for the SuperTrendPeriod, SuperTrendMultiplier, Target, and StopLoss values. It then defines variables to keep track of the SuperTrend value, trade entry price, trade exit price, trade profit, trade stop loss, and whether a trade is currently active.
The SuperTrend indicator is calculated using the input parameters, and the code enters a long trade when the SuperTrend turns from red to green and a short trade when the SuperTrend turns from green to red. The code also sets the trade entry price and stop loss based on the input parameters.
The code then checks for exit conditions, which are either hitting the target or the stop loss. If the target or stop loss is hit, the code exits the trade and calculates the trade profit.
The input parameters are defined using the Inputs keyword, and they can be modified later. The code includes comments throughout to explain what each section does and how it works.
Sign in to your account