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)
|
Asish,
Now I have a better understanding of what you are trying to achieve. Again I must caution you against using the hindsight indicators.
Anyway...
My interpretation your trading system is this. This is your short entry signal?
a:=Peak(2,Zig(H,.75,$),.1);
b:= Peak(1,Zig(H,.75,$),.1);
m:=a>b;
You are looking for the most recent peak to be lower than the preceeding peak. Have a look at Jose's site again. He has some excellent code in his divergence indicators to find higher/lower peaks/troughs that aren't using these lookback indicators.
The m:=a>b; produces regions where this is true or false. Although the value of 'm' changing from zero to one will trigger the system tester to enter the short trade, it would be neater to have a single signal generated:
m:=a>b;
ShortEntry:=m AND Alert(m=0,2);
which is the same as:
m:=a> b;
ShortEntry:=m AND Ref(m,-1)=0;
whichever you use is up to you.
You are also going to be missing out on a lot of action in "younger" stocks, as the Zig() function has to generate the required number of peaks and troughs for your system to have its signals. Hard coding the peak-finding and trough-finding code might present you with more tradable signals.
--
Consider using variables to make your code easier to read and edit.
z:=Zig(H,.75,$);
a:=Peak(2,z,1);
b:= Peak(1,z,1);
m:=a> b;
Now you can change the effect in both the a and b variable just by editing the z variable. Its much easier. Also, as the Zig() function rockets to the peak and then plummets down the other side, you can actually use quite large values of change in the Peak(Zig()) functions.
Whilst we're at it, one day you might want to write a really long indicator and be struggling to fit all the code in the limited space MS allows. Get used to writing abbreviated code, as required by the circumstances:
z:=Zig(H,.75,$);
m:=Peak(2,z,1)>Peak(1,z,1);
SE:=m AND Alert(m=0,2);
This is neat, easily edited and still very readable.
--
A “Buy to cover order” is just a 'tecchie' way of saying Short Exit (well it is to me!)
z:=Zig(H,.75,$);
m:=Peak(2,z,1)>Peak(1,z,1);
n:= Trough(1,z,1)> Ref(Trough(1,z,1),-1);
BarsSince(m AND n)
The first lines of code are from above, however the last two (the parts that are going to actually trigger the short exit need some refinement)
--
Although you are going to be working on IntraDay data, all bars (EOD or intraday) form patterns. You and I do not trade the same exchanges, so I cannot easily demonstrate the next part, so I am going to use the Dow Jones Industrials Index as an example. Hopefully you get this index and can look at the same plot as me.
I have modified the code slightly from the code above for demonstration purposes:
z:=Zig(H,5,%); {a 5% swing is required to form a new peak/trough}
m:=Peak(2,z,1)>Peak(1,z,1);
n:=Trough(1,z,1)>Ref(Trough(1,z,1),-1);
x:=BarsSince(m AND n);
{plots}
m;n;{x throws out the scaling too much!}
Also plot Zig(H,5,%) directly on the chart so you can see the Zig() from which the Peak() and Trough() functions are created.
If you plot the criteria you are looking for on the chart of the Dow, you will notice that rarely is the 'n' variable formed inside the region of 'm' This means that when short, you are going to be holding this losing position for a loooong time. This isn't true only for the Dow, plot these indicators on any chart and yo will see the same effects. Without even using the system tester I can see that your system will only end in dispair.
This is of course in addition to the exit trigger not being fired until the Trough() has been formed which will be a number of days AFTER the local-bottom of the market. This is the dynamic nature of the Zig(). Again, Jose has some excellent examples that I strongly urge you to look at.
--
Why must 'n' be fired only when 'm' is true? What I think you really meant was for the system to be latched to exit the short trade on the first 'n' after the first time 'm' was true? If this is the case then all you need to do is have a look at Roy Larsen's awesome latching code, or even more simply, get the forum.dll which has a latch function built in. If you don't need the latch, then I fail to understand the intent of your code. Sorry.
--
I have written a rather lengthy post. I will leave you some time to look over it. Please have a look at the indicators on the EOD chart of the Dow. If you use this chart as a template, then we can work on building the system simultaneously. It might also be worthwhile you posting the chart (with your interpretation of the indicators and comments)
wabbit :D
|