Rank: Member
Groups: Registered, Registered Users, Subscribers Joined: 8/21/2006(UTC) Posts: 23
|
The following code generates Buy and Sell signals for Forex currency pairs to go long:
Buy:
Ref(Cross(MACD(),Mov(MACD(),9,E)),-2)
Sell:
bc:=Cross(MACD(),Mov(MACD(),9,E)); x:=H>=ValueWhen(1,bc,C+.0009); y:=L<=ValueWhen(1,bc,C-.0050); x OR BarsSince(bc) > 30 AND (Ref(C,-30) - C)>.0020 OR y
So i would like to buy when MACD crossed the Moving Average 2 timeperiods ago. And i'd like to sell when a target of 9 pips is reached OR when after 30 timeperiods the close is 20 pips lower then the initial close OR when it is at anytime 50 pips lower. (so the last 2 sellfunctions are in fact stoplosses)
This code is not exactly what i want. I would like to implement a function that enables me to be in a "free trade" after a certain piptarget is reached. For instance, when 5 pips are gained i want to set the stoploss to the openingprice. So when it moves back from 5 pips to 0 exit the trade. (sell)
What i also would like to have is the following: Right now the Buy is waiting until 2 timeperiods are passed after the cross occured. This means, that when a sellsignal occurs in between (after 1 timeperiod after the Buysignal) it is to early and therfore incorrect. It is not necessarily a problem because i will wait when a second sell signal occurs after the Buy is realised. But it is ofcourse not a neat solution. It would be better if a Sellsignal only occurs after the the realised Buysignal.
The third problem is how to relate the Sellsignal to the FIRST Buysignal that occured in the past. Sometimes there are up to 5 Buysignals in a row. The first following SellSignal should respond to that first Buysignal as i have now the idea that it responds to the last.
Any help with these 3 problems is very welcome :-]
|
|
|
|
Rank: Member
Groups: Registered, Registered Users, Subscribers Joined: 8/21/2006(UTC) Posts: 23
|
Allright, i've now installed the forum.dll file so i can use the latch function. I'm a little bit stuck here as i do not quite understand how the latch functions operates:
I am using an expert that defines an Enter Long and Exit Long. I assume i've to insert the same code twice to get two different signals plotted on my chart? (an up-arrow and down-arrow). Anyway this is the code i'm using:
bc:=Cross(MACD(),Mov(MACD(),9,E)); x:=H>=ValueWhen(1,bc,C+.0009); y:=L<=ValueWhen(1,bc,C-.0050); c1:=MACD(); c2:=Mov(MACD(),9,E); LE:=Ref(Cross(c1,c2),-2); LX:=x OR BarsSince(bc) > 30 AND (Ref(C,-30) - C)>.0020 OR y; Z:= ExtFml("forum.Latch",LE,LX,0,0); EnterLong:=Z = 1 AND Ref(Z,-1) <> 1; ExitLong:=Z = 0 AND Ref(Z,-1) = 1; EnterLong-ExitLong;
Well this gives very strange results. I think the problem starts with defining the LX variable. When LX is true i want to exit the long, that's the idea. But on my chart the Exit Long seems to be based on totally different variables. It looks like it plots an Exit Long when the c2 is crossing c1 again, while i didn't define it that way.
The Enter Long is working properly. When triggered it indeed waits until an Exit is realised before another Enter is established. But i can't get my head around the Exit Long based on my variables (as i've defined LX right now). Not to speak about how to get the first Exit Long to be AFTER the two time periods it takes to establish the Buy after the Enter Long signal is generated.
Who can help me out?
|
|
|
|
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)
|
Raymond,
From what I can see the code is executing just like it should!
I think the problm lies in the VERY LIMITED price action you allow after the entry criteria:
x:=H>=ValueWhen(1,bc,C+.0009); y:=L<=ValueWhen(1,bc,C-.0050); ... LX:=x OR BarsSince(bc) > 30 AND (Ref(C,-30) - C)>.0020 OR y;
Lets pretend the entry happens on the bc day (I know it doesn't, but just pretend) the exit will be triggered when the prices move outside the range specified by x and y. You do not allow the price to move at all on anything except the smallest 'penny-dreadfuls' and your currency market (but not all currency markets are the same!) Instead of using absolute values here, use a percentage expression? or allow greater freedom of movement? There is also a problem whereby the bc condition is set on every MACD cross, even those crosses made after the trade entry. You need to trap the price at entry and use this in your computation instead.
As you actually enter two days after the MACD cross, the price might already be outside this range which is set on the day of the cross, and will immediately exit you from the trade.
If you free up the range dictated by the x and y conditions and fix the bc condition to the time of entry, you will see you get quite different results.
Hope this helps.
wabbit [:D]
BTW: I am testing using EOD on the smalles company price I have in ASX.
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers Joined: 9/8/2004(UTC) Posts: 2,266
Was thanked: 1 time(s) in 1 post(s)
|
Also 1 pip is not always equal to 0.0001 ... Unless you only trade the EURUSD ... But you may have to create a little more code to figure out that value then multiply it by 9 or 50 or whatever ...
The next problem you will run into is that the simulation will not be valid if you are not using tick data and even then I would not trust the results much ...
|
|
|
|
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)
|
|
|
|
|
Rank: Member
Groups: Registered, Registered Users, Subscribers Joined: 8/21/2006(UTC) Posts: 23
|
Quote: There is also a problem whereby the bc condition
is set on every MACD cross, even those crosses made after the trade
entry. You need to trap the price at entry and use this in your
computation instead.
Well the price-action maybe limited but from my experience not necessarily a problem. Anyway in fact you pointed out the my biggest problem. Do you have any suggestions how to make sure that the first Exit that occurs after a series of Entersignals is related to the first Enter (the first macd cross)?
|
|
|
|
Rank: Member
Groups: Registered, Registered Users, Subscribers Joined: 8/21/2006(UTC) Posts: 23
|
Quote: Also 1 pip is not always equal to 0.0001 ... Unless you only trade the
EURUSD ... But you may have to create a little more code to figure out
that value then multiply it by 9 or 50 or whatever ...
The
next problem you will run into is that the simulation will not be valid
if you are not using tick data and even then I would not trust the
results much ...
1) I'm aware of this, but i'm scalping only eur/usd at the moment. 2) You mean that the simulation is not able to tell on a 5 min. data the right moment to enter/exit because it will only have the low/high of a timeperiod to base its decision upon? Or do you mean something else? Does anyone know if TradeSim is able to perform a backtest on a 5min. timeperiod where the enter/exits will be executed based on tickdata within that 5 min. period? Quote:
This indicator from MetaStockTools.com may be useful here:
Pip detector - detects the smallest traded price movement (pip) on a chart.
jose '-)
This gives me a flat 0 horizontal line?
|
|
|
|
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)
|
Raymond, plot the Pip detector indicator on its own window below a chart, and take note of its last value.
It's unlikely that it would plot 0.
On my 1-min charts, it finds all the correct pips:
Euro-USD: 0.0001
GBP-SWF: 0.0001
USD-Yen: 0.001
etc...
jose '-)
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers Joined: 9/8/2004(UTC) Posts: 2,266
Was thanked: 1 time(s) in 1 post(s)
|
Raymond wrote: You mean that the simulation is not able to tell on a 5 min. data the right moment to enter/exit because it will only have the low/high of a timeperiod to base its decision upon?
That is exactly what I mean ... Unless MetaStock has upgraded their System Tester to enter at any other price than open high low close with a delay of 0 or more ...
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 4/27/2005(UTC) Posts: 130
|
Jose,
Rraymond appears to be correct your Pip Detector doesn't plot a value other then 0 in it own window. I would plot you a jpeg but I don't know how this new forum is still to new for me. Anyway I dropped your design on a 5 min forex chart GBPUSD and it plotted a 0.
Does the paste function even work in this forum?
Hey this is my very first post on the new forum!
|
|
|
|
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 Pip detector code works fine on any non-padded data chart, except possibly on tick charts.
It finds the smallest historical difference between High/Low/Close for today and yesterday. It finds all correct pips on my intraday charts.
Here's Raymond's example:
http://www.zoekdit.nl/pipdetector.jpg
As you can see, it finds the correct 0.0001 pip value in his Eur-USD chart.
Once you have this correct pip value, it can be referenced in other indicators.
As an example for correct x pip stop calculations:
pipNr:= 60; { number of pips for stops }
pip:= Fml("Pip detector");
stopProfit:= EntryPrice+pipNr*pip;
stopLoss:= EntryPrice-pipNr*pip;
stopProfit;stopLoss;
jose '-)
|
|
|
|
Rank: Member
Groups: Registered, Registered Users, Subscribers Joined: 8/21/2006(UTC) Posts: 23
|
Indeed, it works fine. The line represents the actual pip value, which is very close to 0 ...
Do you have any suggestions how to make sure that the first Exit that
occurs after a series of Entersignals is related to the first Enter
(the first macd cross)?
|
|
|
|
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)
|
Raymond wrote:Do you have any suggestions how to make sure that the first Exit that occurs after a series of Entersignals is related to the first Enter (the first macd cross)?
Huh?
|
|
|
|
Rank: Member
Groups: Registered, Registered Users, Subscribers Joined: 8/21/2006(UTC) Posts: 23
|
hehe, i'm sorry for the confusion. That remark had nothing to do with the pipdetector. I was refering to my post where i quoted Wabbit. I still have this problem. Quote: There is also a problem whereby the bc condition
is set on every MACD cross, even those crosses made after the trade
entry. You need to trap the price at entry and use this in your
computation instead.
|
|
|
|
Rank: Member
Groups: Registered, Registered Users, Subscribers Joined: 8/21/2006(UTC) Posts: 23
|
Is there anyone that can help me trap the entryprice on the first cross? I've really no idea how i can accomplish this.
|
|
|
|
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.