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

Notification

Icon
Error

Options
Go to last post Go to first unread
newbie  
#1 Posted : Wednesday, October 19, 2005 12:57:56 PM(UTC)
newbie

Rank: Member

Groups: Registered, Registered Users
Joined: 10/6/2005(UTC)
Posts: 26

I was able to remove multiple buy and sell signals in Expert System using a Latch function found in the tutorial here. Basically, this is what I do to get around the problem based on the tutorial :- buy := C>mov(C,3,E); sell:=C<mov(C,3,E); buy and barssince(ref(buy,-1))> barssince(ref(sell,-1)) sell and barssince(ref(buy,-1))< barssince(ref(sell,-1)) How do I use a latch function using BUY entry, BUY exit, SELL entry and SELL exit? For example, my conditions are as follows :- buy:=C>mov(C,3,E); buyexit:=C<mov(C,3,E); shortsell:=C<sar(0.02,0.2); shortexit:=C>sar(0.02,0.2); I tried the following, but it does not seem to work properly:= buy and barssince(ref(buy,-1))> barssince(ref(sell,-1)) sell and barssince(ref(buy,-1))< barssince(ref(sell,-1)) shortsell and barssince(ref(shortsell,-1))>barssince(ref(shortexit,-1)) shortexit and barssince(ref(shortsell,-1))<barssince(ref(shortexit,-1)) Appreciate any help I could gather on this issue. TQ
Jose  
#2 Posted : Wednesday, October 19, 2005 1:54:51 PM(UTC)
Jose

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 1/19/2005(UTC)
Posts: 1,065
Location: Koh Pha-Ngan, Earth

Was thanked: 2 time(s) in 2 post(s)
Try this combined Long (+/-1) and Short (+/-0.5) signals latch code: [code:1:4865ecdc98] =========================== System Long & Short signals =========================== ---8<--------------------------- { Combined Long & Short System trade signals } { ©Copyright 2005 Jose Silva For personal use only. http://www.metastocktools.com } { Note: preference given to new entry or exit signal if simultaneous entry & exit signals on the same bar } { Reference Long signals } LE:=C>Mov(C,3,E); LX:=C<Mov(C,3,E); { Reference Short signals } SE:=C<SAR(0.02,0.2); SX:=C>SAR(0.02,0.2); { User inputs } plot:=Input("Signals: [1]Clean, [2]All, [3]Trade binary",1,3,1); delay:=Input("Entry and Exit delay",-1,5,0); { Long signals } Init:=Cum(IsDefined(LE+LX+SE))=1; entry:=LE AND (Alert(LE=0,2) OR Init); exit:=(LX OR SE) AND (Alert((LX OR SE)=0,2) OR Init); binLong:=ValueWhen(1,entry-exit<>0,entry-exit); { Short signals } Init:=Cum(IsDefined(SE+SX+LE))=1; entry:=SE AND (Alert(SE=0,2) OR Init); exit:=(SX OR LE) AND (Alert((SX OR LE)=0,2) OR Init); binShort:=ValueWhen(1,entry-exit<>0,entry-exit); { Combined Long & Short Signals } binary:=(binLong-binShort)/2; longEn:=binary>0 AND Alert(binary<1,2) OR Cum(binary>0)=1; longEx:=binary<1 AND Alert(binary>0,2); long:=longEn-longEx; shortEn:=binary<0 AND Alert(binary>-1,2) OR Cum(binary<0)=1; shortEx:=binary>-1 AND Alert(binary<0,2); short:=shortEx-shortEn; { Plot signals in own window } Ref(If(plot=1,short*.5, If(plot=2,(SX-SE)*.5,binary)),-delay); Ref(If(plot=1,long, If(plot=2,LE-LX,binary)),-delay) ---8<--------------------------- [/code:1:4865ecdc98] jose '-)
newbie  
#3 Posted : Wednesday, October 19, 2005 5:14:35 PM(UTC)
newbie

Rank: Member

Groups: Registered, Registered Users
Joined: 10/6/2005(UTC)
Posts: 26

TQ Jose. I have tried your code and checked the output against the signals given by Enhanced System tester, and they are more or less, matched. But the signals are given in the +1/-1 formats. Is there any way I could have the signal converted to buy and sell signs like the ones in Expert System?
Jose  
#4 Posted : Wednesday, October 19, 2005 5:27:07 PM(UTC)
Jose

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 1/19/2005(UTC)
Posts: 1,065
Location: Koh Pha-Ngan, Earth

Was thanked: 2 time(s) in 2 post(s)
Yes - you would have to reference the signals from the "System Long & Short signals" indicator, and assign symbols (arrows, etc) to them. jose '-)
newbie  
#5 Posted : Wednesday, October 19, 2005 5:31:17 PM(UTC)
newbie

Rank: Member

Groups: Registered, Registered Users
Joined: 10/6/2005(UTC)
Posts: 26

Jose wrote:
Yes - you would have to reference the signals from the "System Long & Short signals" indicator, and assign symbols (arrows, etc) to them. jose '-)
And how do I reference the signals from the "System Long & Short Signals" indicator and assign arrows to them? I could assign arrows to them if they are in Expert System. But I have no idea on how to reference the signals from custom-built indicators. Appreciate any help you can extend.
Jose  
#6 Posted : Wednesday, October 19, 2005 6:09:09 PM(UTC)
Jose

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 1/19/2005(UTC)
Posts: 1,065
Location: Koh Pha-Ngan, Earth

Was thanked: 2 time(s) in 2 post(s)
MetaStock -> Tools -> Expert Advisor -> New -> Symbols -> New: Symbol 1: { Long entry - Blue up arrow } FmlVar("System Long & Short signals","LONG")=1; Symbol 2: { Long exit - Red down arrow } FmlVar("System Long & Short signals","LONG")=-1; Symbol 3: { Short entry - Green down arrow } FmlVar("System Long & Short signals","SHORT")=-1; Symbol 4: { Short exit - Brown up arrow } FmlVar("System Long & Short signals","SHORT")=1; jose '-)
newbie  
#7 Posted : Thursday, October 20, 2005 8:28:21 PM(UTC)
newbie

Rank: Member

Groups: Registered, Registered Users
Joined: 10/6/2005(UTC)
Posts: 26

Some of the buying and selling signals using this latch function do not tally with the signals shown in the Enhanced System Testing. Upon manual checking, I believe the signals shown by the System Testing to be accurate. I have captured a screenshot of one of the buying signals that differs from the one generated by the System Testing. This latch buy signal differs from buy signal no. 86, and it seems that latch buy signal did not take into account the shortexit requirement of C>ref(hhv(h,3),-1). UserPostedImage Any ideas what is causing this discrepancy? TQ
Jose  
#8 Posted : Thursday, October 20, 2005 9:34:42 PM(UTC)
Jose

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 1/19/2005(UTC)
Posts: 1,065
Location: Koh Pha-Ngan, Earth

Was thanked: 2 time(s) in 2 post(s)
The latch code I've posted is accurate. You either have errors in your System Tester code, or there is a discrepancy somewhere between keyboard & seat. ;) jose '-)
newbie  
#9 Posted : Thursday, October 20, 2005 9:55:25 PM(UTC)
newbie

Rank: Member

Groups: Registered, Registered Users
Joined: 10/6/2005(UTC)
Posts: 26

Jose wrote:
The latch code I've posted is accurate. You either have errors in your System Tester code, or there is a discrepancy somewhere between keyboard & seat. ;) -)
OK. Thanks for your help. I will try to hunt down for the errors
Jose  
#10 Posted : Thursday, October 20, 2005 10:55:24 PM(UTC)
Jose

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 1/19/2005(UTC)
Posts: 1,065
Location: Koh Pha-Ngan, Earth

Was thanked: 2 time(s) in 2 post(s)
To make debugging easier, try breaking down the original formula to its core components and isolating/plotting them. Try working just on the Long side first. For example, try plotting just the entry signal (C>Linearreg(C,12) and qstick(10)>0), and see if it behaves the way you expect it to. jose '-)
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.