# Can SL or Profit price point be kept as constant in PI backtesting code?

SET SL = REF(LOW,1)
SET profit = Ref(high,1) + ((Ref(high,1) + Ref (low,1) * 2)
Crossover(Low, SL) = True or
Crossover(High, profit) = True

In the above code of PI, the SL and Profit are changing according to the candle which has been worked out by the script.

How to create or SET a constant value for a variable until a new trade is triggered? I have kept the SL as the low of the candle at which the buy signal was triggered and the Profit is twice the size of that candle. But the above code keeps changing the SL and profit values to subsequent candles.

Pls suggest me how to code correctly or give me hints to where to find the correct approach
Tagged:
• edited October 2019
i cant get heads and tails of this code..
If you are looking for some solutions to keep your SL and profit as "constant" then apply % to variables.Lets say you want to trigger sell when your script goes down by 2% and same for profit .
• Oops. Let me explain a bit more. The above code is basically belong to exit long.

I want to keep my SL at the low of previous bar for the longs which I entered at the current bar.

I want to exit at profit when the price crosses 2 times the length of the said previous bar.

But the first line of the code does not keep the SL always at the low of intended bar. It keeps moving the SL to the every next bar’s low.

Hence my question - how to keep it constant until either triggering the SL or the profit.

Hope iam clear now
• Please assign the intended low bar's value to a variable and keep it constant,
to secure your losses you can also feedback an extra conditional statement in % range(of current value) to avoid huge drops.
• More confusion ! Here is the code piece for Exit Long

SET SL = REF(LOW, 1)
SET profit = REF(HIGH, 1) + ((REF(HIGH, 1) + REF(LOW, 1)) * 2)
SET A = SL
SET A = IF(LOW < A, SL, A)
CROSSOVER(A, LOW) = TRUE OR
CROSSOVER(HIGH, profit) = TRUE

1. In the first line, setting SL as the previous bar low. But iam not sure whether the script will take the first bar after a trade is triggered as per the Buy script OR it starts from the first bar?
2. These scenarios can be covered in traditionally using IF ELSE THEN or CASE in other languages but iam not sure how these are handled here
3. How to get a value displayed? Suppose I want to get the values of SL displayed in the result set, not sure how to write script for that
4. Is the tradescript help pdf provided by zerodha is all we have got or else do we have any more documentation to explore more? If yes, pls help me with the source
• @nbala75,
This forum is dedicated only to Kite Connect related platforms. If you have a query regarding any other platform then I suggest using the support portal.
• @nbala75,
This forum is dedicated only to Kite Connect related platforms. If you have a query regarding any other platform then I suggest using the support portal.