Mascapitalllctrader
New member
Hello everyone, I'm seeking assistance with my current strategy. Currently, both the short entry profit/stop loss and the long entry profit/stop loss are displayed whenever an entry is executed. I'm looking for help to configure it in a way that only shows the profit and stop loss levels based on whether it's a short or long entry. Appreciate any guidance on this matter. see code below
short entry code
input contracts = 1;
def rsi = RSI(length = rsi_length);
def atr = ATR(length = atr_length);
def condition = (rsi > 80);
# Short
AddOrder(tickcolor = Color.GREEN, arrowcolor = Color.RED, name = "Short", tradeSize = contracts, condition = condition, type = OrderType.SELL_TO_OPEN);
# Profit
def target = EntryPrice() - ATR() * profit_mult;
AddOrder(type = OrderType.BUY_TO_CLOSE, low[-1] <= target, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "Target", price = target);
# Trailing stop
def stop = EntryPrice() + ATR() * stop_mult;
AddOrder(OrderType.BUY_TO_CLOSE, high[-1] >= stop, tickcolor = Color.GRAY, arrowcolor = Color.CYAN, name = "Stop", tradeSize = contracts);
plot Profit = target;
Profit.SetPaintingStrategy(PaintingStrategy.Horizontal);
Profit.SetDefaultColor(Color.BLUE);
plot loss= stop;
loss.SetPaintingStrategy(PaintingStrategy.Horizontal);
loss.SetDefaultColor(Color.MAGENTA);
here is my long entry code.
input contracts = 1;
def rsi = RSI(length = rsi_length);
def atr = ATR(length = atr_length);
def condition = (rsi < 30);
# Long
AddOrder(tickcolor = Color.GREEN, arrowcolor = Color.RED, name = "Long", tradeSize = contracts, condition = condition, type = OrderType.BUY_TO_OPEN);
# Profit
def target = EntryPrice() + ATR() * profit_mult;
AddOrder(type = OrderType.SELL_TO_CLOSE, high[-1] >= target, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "Target", price = target);
# Trailing stop
def stop = EntryPrice() - ATR() * stop_mult;
AddOrder(OrderType.SELL_TO_CLOSE, low[-1] <= stop, tickcolor = Color.GRAY, arrowcolor = Color.GRAY, name = "Stop", tradeSize = contracts);
plot ProfitTarget = target;
ProfitTarget.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ProfitTarget.SetDefaultColor(Color.GREEN);
plot stoploss = stop;
stoploss.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
stoploss.SetDefaultColor(Color.YELLOW);
short entry code
input contracts = 1;
def rsi = RSI(length = rsi_length);
def atr = ATR(length = atr_length);
def condition = (rsi > 80);
# Short
AddOrder(tickcolor = Color.GREEN, arrowcolor = Color.RED, name = "Short", tradeSize = contracts, condition = condition, type = OrderType.SELL_TO_OPEN);
# Profit
def target = EntryPrice() - ATR() * profit_mult;
AddOrder(type = OrderType.BUY_TO_CLOSE, low[-1] <= target, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "Target", price = target);
# Trailing stop
def stop = EntryPrice() + ATR() * stop_mult;
AddOrder(OrderType.BUY_TO_CLOSE, high[-1] >= stop, tickcolor = Color.GRAY, arrowcolor = Color.CYAN, name = "Stop", tradeSize = contracts);
plot Profit = target;
Profit.SetPaintingStrategy(PaintingStrategy.Horizontal);
Profit.SetDefaultColor(Color.BLUE);
plot loss= stop;
loss.SetPaintingStrategy(PaintingStrategy.Horizontal);
loss.SetDefaultColor(Color.MAGENTA);
here is my long entry code.
input contracts = 1;
def rsi = RSI(length = rsi_length);
def atr = ATR(length = atr_length);
def condition = (rsi < 30);
# Long
AddOrder(tickcolor = Color.GREEN, arrowcolor = Color.RED, name = "Long", tradeSize = contracts, condition = condition, type = OrderType.BUY_TO_OPEN);
# Profit
def target = EntryPrice() + ATR() * profit_mult;
AddOrder(type = OrderType.SELL_TO_CLOSE, high[-1] >= target, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "Target", price = target);
# Trailing stop
def stop = EntryPrice() - ATR() * stop_mult;
AddOrder(OrderType.SELL_TO_CLOSE, low[-1] <= stop, tickcolor = Color.GRAY, arrowcolor = Color.GRAY, name = "Stop", tradeSize = contracts);
plot ProfitTarget = target;
ProfitTarget.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ProfitTarget.SetDefaultColor(Color.GREEN);
plot stoploss = stop;
stoploss.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
stoploss.SetDefaultColor(Color.YELLOW);