logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
daiwa  
#1 Posted : Thursday, September 20, 2007 8:33:42 AM(UTC)
daiwa

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 8/27/2006(UTC)
Posts: 16
Location: Finland

Hello metastock programmers. A few short questions I had been struggling a few days.

1)

{ColA - ElapsedBars}
x:=C<=HHV(C,62)-LLV(C,62)*.618;
BarsSince(x);

This works fine, but I would like to put this formula showing up actualy fib correction
if it happened somewhere in the pricetick or candle where it occured and for this reason it should shows something like this, but cannot make it work. I would rather use cross instead close something like this>

x:=Cross=HHV(C,62)-LLV(C,62)*.618-HHV;

2)

What would be more efficent way to express this formula as CCI is only one change in expert advisor ?

(CCI cross between 3 and 21 days and RSI cross between 3 and 5 days)

Cross(Stoch(5,3),20)
AND
Cross(CCI(3),-100)
AND
Cross(RSI(3),30)
OR
Cross(CCI(5),-100)
AND
Cross(Stoch(5,3),20)
AND
Cross(RSI(3),30)
OR
Cross(CCI(8),-100)
AND
Cross(Stoch(5,3),20)
AND
Cross(RSI(3),30)
OR
Cross(CCI(13),-100)
AND
Cross(Stoch(5,3),20)
AND
Cross(RSI(3),30)
OR
Cross(CCI(21),-100)
AND
Cross(Stoch(5,3),20)
AND
Cross(RSI(3),30)
OR
Cross(CCI(34),-100)
AND
Cross(Stoch(5,3),20)
AND
Cross(RSI(3),30)
OR
Cross(Stoch(5,3),20)
AND
Cross(CCI(3),-100)
AND
Cross(RSI(5),30)
OR
Cross(CCI(5),-100)
AND
Cross(Stoch(5,3),20)
AND
Cross(RSI(5),30)
OR
Cross(CCI(8),-100)
AND
Cross(Stoch(5,3),20)
AND
Cross(RSI(5),30)
OR
Cross(CCI(13),-100)
AND
Cross(Stoch(5,3),20)
AND
Cross(RSI(5),30)
OR
Cross(CCI(21),-100)
AND
Cross(Stoch(5,3),20)
AND
Cross(RSI(5),30)

3)

My third question is can you determine in expert advisor that something has happened
for example "Cross(Stoch(5,3),20)", but show it only if previous candle condition is true like

"OscP(12,26,E,%) <= -3 AND ROC(OscP(12,26,E,%),5,$) = -Sum(Abs(ROC(OscP(12,26,E,%),1,$)),5)"

Which is kind of oversold condition.

Thank you in advance,

-Daiwa




amory  
#2 Posted : Thursday, September 20, 2007 5:48:43 PM(UTC)
amory

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 4/18/2007(UTC)
Posts: 99
Location: sydney australia

hello Daiwa. re your 3rd question, would the alert function be any help? as an exploration:

Cross(Stoch(5,3),20) and
Alert(OscP(12,26,E,%) <= -3 AND ROC(OscP(12,26,E,%),5,$) = -Sum(Abs(ROC(OscP(12,26,E,%),1,$)),5),5) {the alert going back 5 days}

wabbit  
#3 Posted : Thursday, September 20, 2007 7:34:46 PM(UTC)
wabbit

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)
daiwa wrote:

2)

What would be more efficent way to express this formula as CCI is only one change in expert advisor ?

(CCI cross between 3 and 21 days and RSI cross between 3 and 5 days)

Cross(Stoch(5,3),20)
AND
Cross(CCI(3),-100)
AND
Cross(RSI(3),30)
OR
Cross(CCI(5),-100)
AND
Cross(Stoch(5,3),20)
AND
Cross(RSI(3),30)
OR
Cross(CCI(8),-100)
AND
Cross(Stoch(5,3),20)
AND
Cross(RSI(3),30)
OR
Cross(CCI(13),-100)
AND
Cross(Stoch(5,3),20)
AND
Cross(RSI(3),30)
OR
Cross(CCI(21),-100)
AND
Cross(Stoch(5,3),20)
AND
Cross(RSI(3),30)
OR
Cross(CCI(34),-100)
AND
Cross(Stoch(5,3),20)
AND
Cross(RSI(3),30)
OR
Cross(Stoch(5,3),20)
AND
Cross(CCI(3),-100)
AND
Cross(RSI(5),30)
OR
Cross(CCI(5),-100)
AND
Cross(Stoch(5,3),20)
AND
Cross(RSI(5),30)
OR
Cross(CCI(8),-100)
AND
Cross(Stoch(5,3),20)
AND
Cross(RSI(5),30)
OR
Cross(CCI(13),-100)
AND
Cross(Stoch(5,3),20)
AND
Cross(RSI(5),30)
OR
Cross(CCI(21),-100)
AND
Cross(Stoch(5,3),20)
AND
Cross(RSI(5),30)



Daiwa,

To start, you should try to make the objective of the code as clear as possible.

We know the operator precedence is AND before OR so we can see what is going on more easily if you re-write the code, with judicious use of brackets too:
Code:
Cross(CCI(3),-100) AND Cross(Stoch(5,3),20) AND Cross(RSI(3),30) OR
Cross(CCI(5),-100) AND Cross(Stoch(5,3),20) AND Cross(RSI(3),30) OR
Cross(CCI(8),-100) AND Cross(Stoch(5,3),20) AND Cross(RSI(3),30) OR
Cross(CCI(13),-100) AND Cross(Stoch(5,3),20) AND Cross(RSI(3),30) OR
Cross(CCI(21),-100) AND Cross(Stoch(5,3),20) AND Cross(RSI(3),30) OR
Cross(CCI(34),-100) AND Cross(Stoch(5,3),20) AND Cross(RSI(3),30) OR
Cross(CCI(3),-100) AND Cross(Stoch(5,3),20) AND Cross(RSI(5),30) OR
Cross(CCI(5),-100) AND Cross(Stoch(5,3),20) AND Cross(RSI(5),30) OR
Cross(CCI(8),-100) AND Cross(Stoch(5,3),20) AND Cross(RSI(5),30) OR
Cross(CCI(13),-100) AND Cross(Stoch(5,3),20) AND Cross(RSI(5),30) OR
Cross(CCI(21),-100) AND Cross(Stoch(5,3),20) AND Cross(RSI(5),30)


Now we can see that each line is evaluated, and only one line has to be true for the entire function to be true.

We can also see the Cross(Stoch(5,3),20) is common to each line and is a condition that must be true if the function is true, so extract this.

Code:
Cross(Stoch(5,3),20) AND
(
Cross(CCI(3),-100) AND Cross(RSI(3),30) OR
Cross(CCI(5),-100) AND Cross(RSI(3),30) OR
Cross(CCI(8),-100) AND Cross(RSI(3),30) OR
Cross(CCI(13),-100) AND Cross(RSI(3),30) OR
Cross(CCI(21),-100) AND Cross(RSI(3),30) OR
Cross(CCI(34),-100) AND Cross(RSI(3),30) OR
Cross(CCI(3),-100) AND Cross(RSI(5),30) OR
Cross(CCI(5),-100) AND Cross(RSI(5),30) OR
Cross(CCI(8),-100) AND Cross(RSI(5),30) OR
Cross(CCI(13),-100) AND Cross(RSI(5),30) OR
Cross(CCI(21),-100) AND Cross(RSI(5),30)
)


we can now see a little more clearly?

The code now appears to be attempting to find the condition when there is a CCI cross AND the cross of either of two RSIs of their levels. This is true for all CCI lengths, except we notice there is a CCI(34) appearing in the middle of the code but not at the end. Is this an error or intentional? Lets pretend it is intentional and deal with the code as is.

Lets combine the RSI crosses against their respective CCI crosses:
Code:
Cross(Stoch(5,3),20) AND
(
Cross(CCI(3),-100) AND (Cross(RSI(3),30) OR Cross(RSI(5),30)) OR
Cross(CCI(5),-100) AND (Cross(RSI(3),30) OR Cross(RSI(5),30)) OR
Cross(CCI(8),-100) AND (Cross(RSI(3),30) OR Cross(RSI(5),30)) OR
Cross(CCI(13),-100) AND (Cross(RSI(3),30) OR Cross(RSI(5),30)) OR
Cross(CCI(21),-100) AND (Cross(RSI(3),30) OR Cross(RSI(5),30)) OR
Cross(CCI(34),-100) AND Cross(RSI(3),30)
)


which can be further simplified by isolating the (Cross(RSI(3),30) OR Cross(RSI(5),30)) expression:
Code:
Cross(Stoch(5,3),20) AND
(
(Cross(RSI(3),30) OR Cross(RSI(5),30)) AND
(
Cross(CCI(3),-100) OR
Cross(CCI(5),-100) OR
Cross(CCI(8),-100) OR
Cross(CCI(13),-100) OR
Cross(CCI(21),-100)
)
OR
(
Cross(CCI(34),-100) AND Cross(RSI(3),30)
)
)


If the final expression was an error:
Code:
Cross(Stoch(5,3),20) AND
(
(Cross(RSI(3),30) OR Cross(RSI(5),30)) AND
(
Cross(CCI(3),-100) OR
Cross(CCI(5),-100) OR
Cross(CCI(8),-100) OR
Cross(CCI(13),-100) OR
Cross(CCI(21),-100) OR
Cross(CCI(34),-100)
)
)



Hope this helps.

wabbit [:D]


wabbit  
#4 Posted : Thursday, September 20, 2007 7:53:37 PM(UTC)
wabbit

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)
daiwa wrote:
3)

My third question is can you determine in expert advisor that something has happened
for example "Cross(Stoch(5,3),20)", but show it only if previous candle condition is true like

"OscP(12,26,E,%) <= -3 AND ROC(OscP(12,26,E,%),5,$) = -Sum(Abs(ROC(OscP(12,26,E,%),1,$)),5)"

Which is kind of oversold condition.


Daiwa,

As I mentioned before, try to keep things as simple as possible. Whenever you make the same computation more than once, consider assigning this to a variable; this will keep the code neater and make it faster too!

Look at the Ref() function in the MS Users Manual. Also remember how MS deals with boolean logic, TRUE, FALSE etc, then try this:

Code:
X:=OscP(12,26,E,%);
Y:= X<=-3 AND ROC(X,5,$)=-Sum(Abs(ROC(X,1,$)),5);

Cross(Stoch(5,3),20) and Ref(Y,-1)



Hope this helps.

wabbit [:D]

daiwa  
#5 Posted : Friday, September 21, 2007 5:28:43 PM(UTC)
daiwa

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 8/27/2006(UTC)
Posts: 16
Location: Finland

Thank you wappit a lot of your response, this gave me formula examples for a long time to build and think. I don´t think I would never find the last code by myself not matter how many times reading my bible (formula primer).

I had noticed CCI-200 for both, bull and shortside is pretty good signal as extreme situatios, but CCI-100 comes more more complex where I should use and test different kind of other scenarios like RSI and Stocastic indicators. I haven´t even try yet use CCI-0 level.

If I am able to create something more usefull with these, I will present it here for further brainstorm.

-Daiwa




Users browsing this topic
Guest (Hidden)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.