Hi,
Is there a function to compare two dataseries like in metastock?
HILOB,HILOM and TRIGGER are SMA series.
If(HILOB>=Ref(HILOB,-1) AND HILOM>TRIGGER AND (H-L)>0.2 AND C>=Ref(C,-1),1,0)
x>1
And also how can i implement ValueWhen(x,...) in wealthlab? I couldn't find any function.
Size:
Color:
Size:
Color:
Re: ValueWhen
To return the most recent bar where a DataSeries crossed above/below another DataSeries -- a typical ValueWhen usage pattern -- the following functions from Community.Indicators can be used:
CrossOverBarCrossOverValueBarCrossUnderBarCrossUnderValueBarIf you need to return the most recent value at the bar when a defined expression was true (another typical ValueWhen usage), just program it using if/then statements and a boolean condition.
Size:
Color:
Thanks for quick reply.
:( again community.*
Is translating from metastock to wealthlab really hard?
Most used functions don't have direct mappings in wealthlab. That is making translation difficult.
What is your advice?
Size:
Color:
Manual translation. May seem difficult at first but practice makes perfect.
Size:
Color:
I have a metastock code block like below
QUOTE:
period:=12;
period2:=3;
period3:=3;
period4:=6;
period5:=170;
period6:=17;
HILOmomentum:=(Mov(LLV(L, period2),period3, S)-Mov(LLV(L, period), period3, S))-(Mov(HHV(H, period), period3, S)-
Mov(HHV(H, period2),period3, S));
TRIGGER:=Mov(HILOmomentum,period4,S);
HILObigmom:=(LLV(L, period6)-LLV(L, period5))-(HHV(H, period5)-HHV(H, period6));
OP:=If(C>ValueWhen(1,Cross(HILOmomentum,TRIGGER),H), If(HILObigmom>=Ref(HILObigmom,-1) AND HILOmomentum>TRIGGER AND (H-L)>0.2 AND C>=Ref(C,-1),1,0), 0);
OP:=1 OR C>REF(HHV(H,12),-1)
And here my code in C#. I have own indicator named HILOMomentum. I am using it in this strategy. But I am getting index range error.
CODE:
Please log in to see this code.
Size:
Color:
Index was out of range, as you can assure by visiting the Wiki link, could happen (in this case) for two reasons: accessing the data at an invalid bar number or accessing the data that does not exist.
Even though your HILOMomentum implementation is mystery to us, but the rest of the code, everything what's below, I think, will not work as intended. It's pretty clear why it was designed so: Metastock hides the loop from you, so traders have to follow different coding conventions when dealing with MSFL.
The main loop is missing, your code is doing excessive looping (in fact, only 1 loop is required in this case), and the "i" (i.e.
bar) might correspond to a very different, unpredictable bar in each of those loops. Try getting rid of those loops, replacing them with one to synchronize the "i", or you'll end with
IsHiloBig valid at bar 22,
IsCloseHBig triggering at bar 33 etc.
Size:
Color:
Here is my latest code. It looks OK. But, new problem is when testing all trades are lost.
There will be op2 condition for sell. Close[bar] values are equal High[bar] most of time (Close[bar] > High[bar]).
CODE:
Please log in to see this code.
Size:
Color:
Thank you for saying thank you, first of all.
CODE:
Please log in to see this code.
There's no need for ternary operator here. Simplify these lines:
CODE:
Please log in to see this code.
Shouldn't be in a loop; move the DataSeries definition before the start of the loop:
CODE:
Please log in to see this code.
I don't know what did you mean by this comparison but it will never work properly, severely peeks into the future; you're comparing the Close value at a bar e.g. bar #200 with the Close at the very LAST bar i.e. .Count-1, which is fixed. It should be something different than [highDS.Count - 1] but I leave it up to you to decide (am not familiar with the algorithm/rules).
CODE:
Please log in to see this code.
Incorrect. Peeking into the future. Replace with "bar+1":
CODE:
Please log in to see this code.
Further reading:
Wiki:
Introductory | Bars, Loops, and Bar + 1Wiki:
Peeking | The Dangers of Looking Ahead in Trading System DevelopmentWealthScript Programming Guide: Programming Trading Strategies > Peeking
Size:
Color:
Sorry. Thanks very much for your patience and quick replies..
CODE:
Please log in to see this code.
I tried to convert
QUOTE:
C>REF(HHV(H,12),-1)
sentence to wealthlab code above. How can i convert that, please?
I corrected others, thanks.
Size:
Color:
OK. Here's it:
CODE:
Please log in to see this code.
If you don't need the
highDS series later in the code (and it seems to be the case), you can skip defining it (
DataSeries highDS...). The
Bars.Cache property will do its job anyway.
Size:
Color: