Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers, Unverified Users Joined: 1/25/2010(UTC) Posts: 44 Location: Rome, IT
|
Hi,
I try to test a simple trading system but I've this problem.
when I write my buy signal:
myIndicator>=value1 AND H>Ref(H,-1){breakout previous bar} AND Ref(H,-1)>Ref(H,-2) AND Ref(L,-1)>Ref(L,-2)
the indicator/expert/system test return every bar with this condition, but I want obtain only the first bar of the expression.
At the same, when I want sell after the buy:
H<Ref(H,-1) AND Ref(H,-1)>Ref(H,-2) {my sell pattern}
Metastock result even the patterns when there isn't a buy signal first.
However, I noticed even signal when the condition doesn't satisfied. It's evident who I committed various errors.
Someone can help me to resolve this question?
Thanks
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers Joined: 7/25/2005(UTC) Posts: 1,042
Was thanked: 57 time(s) in 54 post(s)
|
Hi Leverage
An easy way to separate an initial TRUE signal from those that follow is to test the current value for TRUE and the previous value for FALSE. This can be done using either the Ref() function or the Alert() function as shown in the two examples below. The ValueWhen() function can also be used as to create a signal delay of 1 or more bars.
Signal:= myIndicator>=value1 AND H>Ref(H,-1) AND Ref(H,-1)>Ref(H,-2) AND Ref(L,-1)>Ref(L,-2);
Signal:= Signal=TRUE AND Ref(Signal,-1)=FALSE;
Signal;
Signal:= myIndicator>=value1 AND H>Ref(H,-1) AND Ref(H,-1)>Ref(H,-2) AND Ref(L,-1)>Ref(L,-2);
Signal:= Signal=TRUE AND Alert(Signal=FALSE,2);
Signal;
You haven't defined "myIndicator" or "value1" so it's not possible for me to provide code that will work as soon as it's pasted into MetaStock. However, the principle of identifying the current value of a signal (variable) as TRUE and the previous value (of that variable) as FALSE is easy to grasp and apply.
The two lots of code I've added can be shortened in a number of ways as follows.
Signal:= Signal AND Ref(Signal,-1)=0;
Signal;
Signal:= Signal AND Alert(Signal=0,2);
Signal;
Signal:= Signal * Ref(Signal,-1)=0;
Signal;
Signal:= Signal * Alert(Signal=0,2);
Signal;
Roy
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers, Unverified Users Joined: 1/25/2010(UTC) Posts: 44 Location: Rome, IT
|
Thank you so much Roy!
Fortunately MS can help a non-programmer like me to realize a lot of personalized indicator, however, for some things, a little difficulty can occur.
Even so, the condition, is the following:
myBuySignal:= RSI(C,14)>=50 AND H>Ref(H,-1) AND Ref(H,-1)>Ref(H,-2) AND Ref(L,-1)>Ref(L,-2);
using Ref() or Alert() function like your indication I should be able to test my simple system. The same thing is for my sell pattern, right? Or Ref()/Alert() create a condition to wait the sell signal?
The last thing (so can i test more ideas):
if I want to sell at 10PM (22:00 in 24 hours mode) or at the end of day... how does it code?
Thank you for support Roy
Max
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers, Unverified Users Joined: 1/25/2010(UTC) Posts: 44 Location: Rome, IT
|
Originally Posted by: Leverage Thank you so much Roy!
Fortunately MS can help a non-programmer like me to realize a lot of personalized indicator, however, for some things, a little difficulty can occur.
Even so, the condition, is the following:
myBuySignal:= RSI(C,14)>=50 AND H>Ref(H,-1) AND Ref(H,-1)>Ref(H,-2) AND Ref(L,-1)>Ref(L,-2);
using Ref() or Alert() function like your indication I should be able to test my simple system. The same thing is for my sell pattern, right? Or Ref()/Alert() create a condition to wait the sell signal?
The last thing (so can i test more ideas):
if I want to sell at 10PM (22:00 in 24 hours mode) or at the end of day... how does it code?
Thank you for support Roy
Max
Hi Roy...your suggest code work right!!
Can you help me for the question in the quote?
Max
|
|
|
|
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.