How Can We Help?
CONDREF Function
Store or lock in the latest value when the condition is met.
Syntax:
CONDREF(Value if true, True Condition)
or
CONDREF(Value if true, True Condition, Source Value if reset, Reset Condition)
set SMA30 = SMA(close,30)
set BuyAmount = CONDREF(Close, Close > SMA30)
or
set SMA30 = SMA(close,30)
set BuyAmount = CONDREF(Close, Close > SMA30, 0 , Close < SMA30)
–Closing Price– | –Condition 1– | –Condition 2– | –Condref Value– |
20 | True | False | 20 |
23 | True | False | 23 |
21 | True | False | 21 |
25 | False | True | 0 |
26 | False | False | 0 |
27.5 | True | False | 27.5 |
32 | True | False | 32 |
BuyAmount will be equal to the most recent close if the closing price is more than the SMA. If in the next period the condition is still true, then the value will be replaced by the new closing price. This will continue until the closing price is no longer more than the SMA, and the function will reset the BuyAmount back to zero.