In Backtesting I want to exit long postion with a profit or loss of 1%. How to code it

Example i get into long position of nifty say at 8200,Now i want to square it of at 1%profit i.e at 8280 or at 1%loss i.e at 8118.

Another question ,Is there a way to use the variables declared in ‘Buyscript’ Window again in ‘exitlongscript’ window.

2 Likes

You can set with respect to price by Price Alert Indicator

https://zerodha.com/expert-advisors/code/price-alert-indicator

we need a formala to do it.
after clicking buy. it has to put 1%+ as sell price and 1% less as Stop loss

With price alert indicator we need to give the price.But my question is different,The EA runs and triggers a call at say price ‘x’,now i need a stoploss at 1% less of that price “x”.