Programming Examples
A parallel function is one which is written to
mimic the base system in every respect. At first this might seem simple, as one
could simply copy the entire system code and save it as a function. However,
system functions such as buy, sell, exitlong, exitshort, marketposition,
positionprofit, are not available for use in functions. You must therefore
write your function to perform as a system without the use of these extremely
useful commands.
To clarify and illustrate the usefulness of
this technique let's develop a simple breakout system and the apply the
parallel function to the system.
Our system will involve the simple breakout of
a range at a given time early in the trading day. We'll keep track of the high
and low of the day and at a given, input selectable time, we'll place a
breakout buy above the range of the day and a breakout sell below the established
range. We'll then take profit at a user selectable target and set our stop
loss, again with a user selectable value.
Base System
Here's the EasyLanguage code for our system.
I'll explain what each section and then compare the system code with that required
for the parallel function.
Inputs: Â Delay(45), Tgt(7), Stp(4);
Vars: NuHi(0), NuLo(0), Bpt(0), Spt(0);
If D<>D[1] then begin
 NuHi
= H;
 NuLo
= L;
 Bpt
= 9999999;
 Spt
= 0;
end;
If H>NuHi then NuHi = H;
If Lthen NuLo = L;
If T = CalcTime(Sess1StartTime,Delay) then begin
 Bpt = NuHi +.1;
 Spt
= NuLo - .1;
end;
If TradesToday(d) = 0 Â then begin;
 BUY Bpt stop;
Â
 SELL Spt stop;
end;
If MarketPosition = 1 then begin
 Exitlong("L_ TGT") entryprice + tgt limit;
 ExitLong("L_Stp") entryprice - Stp stop;
end;
If MarketPosition = -1 then begin
 ExitShort("S_Tgt") entryprice - tgt limit;
 ExitShort("S_Stp") entryprice + stp stop;
end;
System Code
Explanation
The first lines are the input and
variable declarations.
"Delay" refers to the
number of minutes after the open of the market that the range determination
will be made. In this example, the input is defaulted to 30, meaning the system
will buy or sell the range established 30 minutes after the open of the market.
"Tgt" is the objective of the trade, or "target" price,
expressed in points. In this example the target is two points in the S&P,
or $500.00. "Stp" is the
value of the stop loss for the system, in this example, four S&P
points.
The variables NuHi and NuLo will
track the expanding high and low for the day. The Bpt and Spt variables will
store the calculated buy and sell points for the system.
Inputs: Â Delay(30), Tgt(2), Stp(4);
Vars: NuHi(0), NuLo(0), Bpt(0), Spt(0);
Resets. The NuHi and NuLo variables,
which progressively record the high and low for the day as the range expands,
are reset to the high and low of the
first bar of the day. The buy point (Bpt) and sell point (Spt) are reset outside the range of the market to
prevent premature buy and sell signals.
If D<>D[1] then begin
 NuHi
= H;
 NuLo
= L;
 Bpt
= 9999999;
 Spt
= 0;
end;
These two
lines record the high and low for the day as the range expands and stores them
in the NuHi and NuLo variables.
If H>NuHi then NuHi = H;
If Lthen NuLo = L;
This
bracket uses the CalcTime function set the breakout time for the system using
the Delay input. The buy point and sell point are set to the high and low for
the day at that time, plus or minus 1 tick, respectively.
If T = CalcTime(Sess1StartTime,Delay) then begin
 Bpt = NuHi;
 Spt
= NuLo;
end;
This is the
area of the code which executes the buy and sell orders for the system, taking
only one trade per day. The systems issues orders to buy one tick above the
high or sell one tick below the low of the day.
If TradesToday(d) = 0 Â then begin;
 BUY Bpt stop;
Â
 SELL Spt stop;
end;
These next two brackets are the exit
routines for the system. In the first
bracket, the system exits a long position at the entry price plus the target input
in the case of a profitable trade or will exit at the entryprice - the stop
input in the case of a stopped out position.
The second bracket exits the short
positions in a similar manner, with profit being taken at the entry price minus
the target price and the system suffering a stopped out loss at the entryprice
plus the stop price.
If MarketPosition = 1 then begin
 Exitlong("L_ TGT") entryprice + tgt limit;
 ExitLong("L_Stp") entryprice - Stp stop;
end;
If MarketPosition = -1 then begin
 ExitShort("S_Tgt") entryprice - tgt limit;
 ExitShort("S_Stp") entryprice + stp stop;
end;
Category: Methods of technical analysis
|