Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers, Unverified Users Joined: 10/28/2004(UTC) Posts: 3,111 Location: Perth, Western Australia
Was thanked: 16 time(s) in 16 post(s)
|
jhughey wrote:Hello,
If you are looking for an indicator that gives the signals you want; then, try simply separating the expressions instead. This gives the buy and sell signals you are looking for.
If(Cross(RSI(14),30),1,0); If(Cross(70,RSI(14)),-1,0);
The reason that you think you see the results for the buy signal is that MS evaluates the whole OR expression. Whenever "([censored]x) OR ([censored]x)" is TRUE, the entire expression evaluates to TRUE, which is one. So with the expression below, you get the Boolean results of 1's and 0's, not the output of the IF() construct for EITHER condition, and the BUY/SELL RSI conditions appear to give a "+1" signal.
If(Cross(RSI(14),30),1,0) OR If(Cross(70,RSI(14)),-1,0); Here: If(Cross(RSI(14),30),1,0); can also be written: Cross(RSI(14),30); by letting MS take care of the return of TRUE (=1) or FALSE (=0) from the expression. We can also take a short cut in MS for x*(-1) by writing: If(Cross(70,RSI(14)),-1,0); as: -Cross(70,RSI(14)); Coders should be acutely aware of what they try to get MS to evaluate and how MS does its evaluation; being particularly cognisant of what constitutes TRUE and FALSE when using representative value. Core MS sees any positive value as TRUE and any zero or negative number as FALSE. (NOTE: some add-ins don't so you have to be even more careful using other products). So in: If(Cross(RSI(14),30),1,0) OR If(Cross(70,RSI(14)),-1,0);
Let's strip down the components and rewrite the fucntionally exact code: x:=Cross(RSI(14),30); y:=Cross(70,RSI(14));
If(x,1,0) OR If(y,-1,0); As 'x' can be evaluated as TRUE (1) or FALSE (0) so too can the first part of the expresson in the last line, so it is functionally exactly the same as just writing 'x'; but things get more interesting in the second part where the 'y' part can only have two values, -1 or 0, both of which evaluate to FALSE in core MS, so the expression 'OR If(y,-1,0)' will always be false and is therefore redundant. The code drops out some of the condition for which the trader needs for decision making.
Hope this helps. wabbit [:D]
|