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

Notification

Icon
Error

Options
Go to last post Go to first unread
praetorian79  
#1 Posted : Sunday, July 4, 2010 12:59:36 AM(UTC)
praetorian79

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 6/27/2010(UTC)
Posts: 6

Hi I'm trying to code a system will enter long when the previous day is and inside day, and the price cross the high of the previous day . my code is as follows: LONG bar:=Inside (); (Ref(bar,-1)=Inside())=false; cross(c,Valuewhen(1,bar,ref(H,1))); STOP SELL c the result i got is that the entry always happens on the inside day itself. how can I code it to enter only when the price broke out of the previous inside day's HIGH? and exit at the same day? THANKS!
wabbit  
#2 Posted : Sunday, July 4, 2010 6:08:24 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)
Check your Ref() function on line 3. What is the purpose of line 2?


wabbit [:D]

praetorian79  
#3 Posted : Monday, July 5, 2010 6:11:27 AM(UTC)
praetorian79

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 6/27/2010(UTC)
Posts: 6

Hi wabbit, LONG bar:=Inside (); {check for inside day} (Ref(bar,-1)=Inside())=false; {check if the day before bar is an inside day) cross(c,Valuewhen(1,bar,ref(H,1))); { enter when the price crosses the high of bar} STOP SELL c { sell on the close, same day} I also saw your post regarding same day exit and was wondering how i could apply it here. Hope you can enlighten me on that Thanks!
wabbit  
#4 Posted : Monday, July 5, 2010 7:38:22 AM(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)
Well done for adding the comments, the aim of my question was to discover whether or not you knew what the code was doing.

The second line of code is never referenced here so is completely redundant. If you want to avoid the case where you might have multiple consecutive inside bars, then this will not do it, and especially since you have not AND'ed the second and third lines to call this part of your filter into play. You should consider the need to use a counter and reset to trap the multiple inside bars scenario.

The Ref() function in line 3 is looking forward, so not looking at the HIGH of the bar before the inside bar, but the bar after the inside bar.


I think might suit better?

Code:

is:=L>Ref(L,-1) AND H<Ref(H,-1); {I prefer to code my own inside function}
count:=Cum(is);
reset:=is=0;
counter:=count-ValueWhen(1,reset,count);
trigger:=counter=1 AND Ref(counter,-1)<>1;
entryPrice:=ValueWhen(1,trigger,Ref(H,-1));
entrySignal:=Cross(C,entryPrice);

{plot}
entrySignal;


Personally, I would also add an expiry condition.

As for making the EST exit on the same day as the entry, search the forum for posts by MSTT (Roy) on the subject; there is already a lot of information and examples posted.



wabbit [:D]

praetorian79  
#5 Posted : Tuesday, July 6, 2010 9:26:35 AM(UTC)
praetorian79

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 6/27/2010(UTC)
Posts: 6

Hi wabbit thanks for the coding I've plug in the code into the backtester but the results is not right. the entry got triggered on the inside day itself. i tried to include a strategic delay of 1 day but this screwed with my exit price. qns: what does the "1" do in the "trigger" line? for entrysignal, it will only trigger when the close hit my entryPrice. what if it opens at entryPrice and close above the entryPrice ? will changing entrysignal line into a stop buy order change anything? Thanks once agian and hope to learn more from you.:)
wabbit  
#6 Posted : Tuesday, July 6, 2010 8:10:13 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)
I think I know what you are trying to do...

Your system description might sound something like, "On the first instance of an inside bar, place an order to enter at the high of the reference bar. When that order is filled, exit at the close of the same bar?"

If so, you are going to need MS9 or newer (older versions don't do pending orders correctly) and learn how to use the Stop order function in the EST. Also, uncheck use realistic market prices and set the trade delay to 0 and the exit price to CLOSE to exit on the close of the same bar as entry (in this instance).

See attached doc.



wabbit [:D]

File Attachment(s):
inside.pdf (28kb) downloaded 6 time(s).
praetorian79  
#7 Posted : Wednesday, July 7, 2010 10:18:00 AM(UTC)
praetorian79

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 6/27/2010(UTC)
Posts: 6

Hi wabbit, Yes that would be a perfect description of the system I'm trying to test. Using the stop buy order, I was able to enter on the high of the reference bar(the inside day). But looking a the orders report,something is wrong . the "trigger" does not seems to be doing its job. I would get a trade that was considered way back in the jan and its was only executed in feburary. I wanted to put a GOOD FOR THE DAY order but this will cause all the trades to be not executed. (because i only wanted to enter on the day after the reference day) if i put a GOOD TILL CANCELLED order, I would get into the trade long after the signal had been invalidated... I think I should be using good for the day order but i need trick the program into thinking that my entry day is the reference bar...(god I'm contradicting myself .....) so that it wouldn't expire too soon... in the line: trigger:=counter=1 AND Ref(counter,-1)1 what does the "1" actually means?.. I'm getting there but i need some more help Thanks!
wabbit  
#8 Posted : Wednesday, July 7, 2010 6:16:47 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)
Code:
trigger:=counter=1 AND Ref(counter,-1)<>1

says, "Comparative Statement : On this bar, the counter is equal to 1 and on the previous bar it was not 1." If this statement is true a value of TRUE (1) will be assigned to the variable, FALSE (0) otherwise. If you really want to see when the trigger is firing, just plot this component on your chart and notice that it returns TRUE on the first instance of an inside bar (by whatever definition) regardless of the number of inside bars which follow.

This could have also been written:
Code:
trigger:=counter=1 AND Ref(counter,-1)=0;
or any other number of ways; my fingers were typing the logic which was running through my head at the time.

As for not executing a pending order months after the signal is given, I suggested in one of my earlier posts that you might need this, and you have never previously mentioned any criteria to "invalidate" a signal. You'll need to use a BarsSince() or a bar-index (ValueWhen(1,event,Cum(1))) to cancel the order after a period.

[edit]
and, if you decide to use a longer period after the reference bar, then you'll also need to trap the instance if a trade has already been executed since the trigger and therefore not place another pending order.


wabbit [:D]

praetorian79  
#9 Posted : Friday, July 9, 2010 4:58:34 AM(UTC)
praetorian79

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 6/27/2010(UTC)
Posts: 6

Hi wabbit, I plotted trigger indicator on my chart and i am confused all over again... isn't the tester suppose to execute the buy order only when trigger is 1? why is some of the buy execution done when trigger is 0? I've added another code : barssince(trigger=1)=1 but it seems to does nothing to change the result.... confused....
wabbit  
#10 Posted : Sunday, July 11, 2010 1:28:57 AM(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)
Have you still got your order set, "good until cancelled?" You will need to use a buy signal where the signal is held open to generate a new trade each day whilst the condition is true, with those orders, "good for day".


wabbit [:D]

praetorian79  
#11 Posted : Tuesday, July 13, 2010 8:24:34 AM(UTC)
praetorian79

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 6/27/2010(UTC)
Posts: 6

Hi wabbit, sorry for the absence..after adding the code below, the entry seems correct. I'm in the process of verifying the results and adding more code get the position sizing right. Thanks once again, you have been a great help! ES:=C>valuewhen(1,trigger,h) or H>valuewhen(1,trigger,h) or L>valuewhen(1,trigger,h); trick:=ES and ref(trigger,-1); ref(trick,1)
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.