How Can We Help?
STOP & TSTOP Function
The STOP or TSTOP function allows the user to easily set a cut loss or take profit signal that are based on your bought or trailing price. The syntax for both functions are the same but is computed differently:
STOP(Source, Gain/Loss, Buy Signal, Sell Signal)
Source: Where the loss or gain computation is based on, example Close
Gain/Loss: Should be in decimal form, example -5% should be written as -0.05
Buy Signal: Should be based on the strategy’s buy signal variable
Sell Signal: Should be based on the strategy’s sell signal variable
The STOP function is based on your purchase price. Meaning if you set a -5% stop loss from the closing price of the purchase day and it will stay there until it resets. You can also use STOP to target a percentage return by using a positive number; 0.15 would mean a sell will trigger once you gain 15% from purchase.
Computation of STOP as a cut loss function:
Closing Price : 100
STOP Loss Percent: -.05
STOP Loss Price: 95
Syntax:
TSTOP(Source, Loss, Buy Signal, Sell Signal)
The TSTOP function is trailing and will be based on the latest and highest price. The TSTOP should always be a negative number.
TSTOP Loss Percent: -0.5
–Day– | –Close– | –TSTOP Price– |
1 | 100 | 95 |
2 | 110 | 104.50 |
3 | 112 | 106.40 |
4 | 110 | 106.40 |
5 | 105 | Exit |
Example Script:
//Buy when RSI crosses 30 and sell if RSI crosses below 70. Cut loss of 5% from the close of the buy signal.
Set RSI = RSI(close,14)
Set Buy = crossover(RSI,30)
Set Sell = crossover(70,RSI)
Set cutloss = stop(close, -0.05, buy, sell)
Set cut = cutloss < -0.05 //This allows us to display the cut loss signal to differentiate it from a normal sell signal.
plot(cut,buy,yellow,main) //the cut or take profit signal will automatically be displayed as the same as your sell condition if you don’t explicitly plot the cut function.
plotbuysell(buy,sell,green,red,main)
plot(rsi,line,cyan,rsi)
plot(70,line,red,rsi)
plot(30,line,green,rsi)