Criteria for a percentage from entry


New member
Hey guys im creating an indicator essentially a crossover of the 6ema and the 9sma. The entry is when the ema crosses below the sma, and i want the exit to be at a percentage in price after the entry so lets say 1%. Ill show you my code so far. This is the first code ive ever written and is unfinished. How can i write exit at at a certain percent after buy?
# By C

# Moving Average

def ema6 = MovAvgExponential(close, 6);

def SMA = SimpleMovingAvg(close, 9);

def condition1 = ema6 crosses above SMA;

def buy = condition1;

def sell = ?

AddOrder(OrderType.BUY_TO_OPEN, condition = buy, price = close,100, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = “Long”);
AddOrder(OrderType.SELL_TO_CLOSE, condition = sell, price = close,100, tickcolor = Color.Red, arrowcolor = Color.Red, name = “Exit Long“);
Last edited:


Well-known member
What "certain price" are you wanting to sell at...??? Is it an amount of profit, a percentage of profit, or something else...??? Your request is somewhat ambiguous... Whatever the criteria, the value would replace your price = close in you sell order...

For example, if you wanted to exit after a .20 profit you could use "price = EntryPrice() + .20"... But your sell condition would also need to reflect the same logic for a price point to meet... I have put a profit point in as my condition and then left out the price to make it a market order once the price reaches my profit goal...

Similar threads