Hello Kalyan, I am no expert in metastock coding. I've been using metastock only for 4 months and I'm a baby in technical analysis too, leave alone metastock coding.
Whenever you see "if" function used, it goes like If("condition", "value of condition is true", "value of condition is false")
It is the " , " which seperates the equations.
Using this basic knowledge, you can structure the formula If(LinearReg(C,13)>PREV,If(LinearReg(C,13)-(ATR(13)*2.5)>PREV,
LinearReg(C,13)-(ATR(13)*2.5),PREV),LinearReg(C,13)); in the following way.
First IF:
Condition : LinearReg(C,13)>PREV
Value if true: If(LinearReg(C,13)-(ATR(13)*2.5)>PREV,
LinearReg(C,13)-(ATR(13)*2.5),PREV)
Value if false: LinearReg(C,13)
Now notice that the "value of main condition is true" also has an if condition attached with it. So if we break it down further using the same process.
If the first "if" function gives a true value, it could again lead to 2 results given another condition, as stated below:
Condition : LinearReg(C,13)-(ATR(13)*2.5)>PREV
Value if 2nd if is true : LinearReg(C,13)-(ATR(13)*2.5)
Value if 2nd if is false: PREV
This is a condition where A can lead to B or C. If it leads to B, then B can lead to D or E. I hope you understand the logic. Beyond this, it is only the indicator function (as in data array, periods etc for linear regression and atr) which should be taken into account.
Regarding the "Prev" function, I have come across that function in many metastock formulas but unfortunately, I do not have a proper explanation for it, since I have never used that in my formulas.I think "prev" function means the value generated in the previous bar(say if yesterdays indicator "A" gave a value of 50, and u have used a prev function in indicator A, if the prev function is triggered, I think it returns a value of 50 today also).
Just to be sure, I shall provide you with a detailed explanation of the function as soon as I get hold of it.
Good luck trading.
Oxymoron
English explanation:
----->If the 13 day linear regression indicator value is greater than previous, check if the diffference between the 13day linear regression and 2.5* 13day average true range is greater than yesterday's value (or value of the previous bar).
*** If it is true, return the current indicator value as "the difference between the 13day linear regression indicator and 2.5* 13day average true range"
***If it is false, return the current indicator value same as yesterday's value
-----> If the 13 day linear regression indicator value is lesser than yesterday's value, return the indicator value same as yesterday's indicator value.