Comment on Code your Technical Analysis strategy

Nithin Kamath commented on 04 May 2013, 10:02 AM

1 – Highest price value (price value can be open, high. low close of bars) over last n bars?

Ans:
“Will explain this with an example. Highest value among Open, High, Low, Close for a bar is obviously the High, so to calculate Highest Hugh value for say, 10 bars, the following script is recommended:
MAXOF(MAX(HIGH,9), REF(HIGH, 10))”

2 – Lowest price value (price value open, high. low close of bars) over last n bars

Ans: MINOF(MIN(LOW, 9), REF(LOW, 10))

3 – Remove excess signals (ie, if I am already in sell and again if one of my sell entry conditions is met, I do not want o be prompted to sell again – similar to exrem in AFL)

Ans: Already handled in execution, once a sell signal is acted on, the next signal will either be a Sell Exit or a Buy, not a sell again. You might have to include a REF condition to this. Like, if the close price goes above the SMA 10 line, it means in the current candle, close is greater than SMA10, but in the previous candle it was lesser than SMA. So the code would look like CLOSE > SMA (CLOSE, 10) AND REF(CLOSE, 1) < REF(SMA(CLOSE, 10), 1). In this case even if you ignore the signal, it wont generate another one because the condition wouldnt hold true then.

4 – How many bars before the current bar did the previous high of low appeared (in relation to points 1 and 2 above)
Ans: You can use LASTIF(Condition), but would need more information to provide a complete code.

5 – Can I use REF to refer back to values of indicators. If possible, how to get the previous peak value of indicator and the low value of indicator.
Ans: Need more information. An example would be useful.

6 – How to code the wait (wait 2 more bars after a condition is met before entry)
Ans:
use REF. if your condition is something like Close > Sma (Close, 10), with wait for 2 bars, the condition would look like REF (Close,2) > Ref (SMA(Close, 10), 2)

View the full comment thread »