Need tradescript code for exit


I am looking out for an exit code based on entry price for backtesting purpose.

Suppose I have some code in the “Buy Script” section of Backtest.

It will trigger buy signals as per the condition entered.

Now, how can I enter a sell signal or an exit long script which will be “1% below the buy signal price”?

Any help will be much appreciated :slight_smile:



you can use Price Gap System in tradescript on the buy script 


# for a  2% gap up in price over the previous day 

LOW > REF(HIGH,1) * 1.02

# for a  2% gap down in price over the previous day

HIGH < REF(LOW,1) * 0.98

in the same why you can use  with   (buy script condition)  * 1.01     for 1% price up

Hi AlgoGeek,
Thank you so much for you prompt reply…
I am finding it difficult to get the explanation you have given or may be there’s a confusion.
For an example, let’s say I got a buy signal for IOC at the close of the latest signal at Rs. 360.
Then, as per my question, how can I simultaneously get a Sell signal to exit the Buy at Rs. 356.4?
Basically, in real time we can always do the math for 1% (which is time consuming), but is there any mechanism by which the price will be calculated automatically and give an alert (when used in EA)? Also, I need this for backtesting.
Can you please check this and help?

Sadly, I wasn’t looking for this answer!

I have been working on exit codes as well , i have the same issue . Not able to write an exit code depending buy/sell price , because we are not storing this price anywhere in the code. I suppose we could assign a variable to store the price , then exit code is easy to write.