PureBytes Links
Trading Reference Links
|
Hi List!
Here are 2 strategies; I need some help in solving a
problem in Code #2 when a Profit Target and Stop Loss
exit
is attached to it.
P:S If you want to see this request with the Embedded
charts in a WEB format, please click below
http://www.fea.com.br/coding_help.htm
----------------------xxxxxxxxxxxx--------------------------
{Code #1:}
Inputs: Price(Close), { series to perform
analysis on }
Len1(3), { fast MA length }
Len2(21); { slow MA length }
Variables: FMA(0),SMA(0);
FMA=Average(Price,Len1); {Fast Moving Average}
SMA=Average(Price,Len2); {Slow Moving Average}
{==== Entry Orders ===}
if FMA crosses above SMA and close > SMA then
Buy("cross buy") This Bar on Close;
if FMA crosses below SMA and close < SMA then Sell
short("cross sell") This Bar on Close;
----------------------xxxxxxxxxxxx--------------------------
{Code #2:}
Inputs: Price(Close), { series to perform
analysis on }
Len1(3), { fast MA length }
Len2(21); { slow MA length }
Variables: FMA(0),SMA(0);
FMA=Average(Price,Len1); {Fast Moving Average}
SMA=Average(Price,Len2); {Slow Moving Average}
{==== Entry Orders ===}
if FMA > SMA and close > SMA then Buy("cross buy")
This Bar on Close;
if FMA < SMA and close < SMA then Sell short("cross
sell") This Bar on Close;
----------------------xxxxxxxxxxxx--------------------------
Their signals at each cross can be seen in the
following links:
Figure #1 http://www.fea.com.br/Coding/Figure_01.gif
Figure #2 http://www.fea.com.br/Coding/Figure_02.gif
The Code#1 has the following rules:
A long trade is be triggered when the Fast Moving
Average {FMA} crosses "above" the Slow Moving Average
{SMA} and if the "close" of this same price bar is
"greater" than the value of Slow Moving Average {SMA}
A short trade will is triggered when the Fast Moving
Average {FMA} crosses "below" the Slow Moving Average
{SMA} and if the "close" of this same price bar is
"smaller" than the value of Slow Moving Average {SMA}
A trade will not be triggered if one of the 2 rules do
not happen within the same bar, i.e., if we have a
cross of
the FMA above the SMA, but in that same bar it closing
price is smaller or equal to the Slow Moving Average
{SMA}, a trade will not be triggered.
The Code#2 has the following rules:
A long trade is triggered if the Fast Moving Average
{FMA} "is higher than" the Slow Moving Average {SMA}
and
when the "close" of this same price bar is "greater"
than the value of Slow Moving Average {SMA}
A short trade is triggered when the Fast Moving
Average {FMA} "is lower than" the Slow Moving Average
{SMA}
and when the "close" of this same price bar is
"smaller" than the value of Slow Moving Average {SMA}
So Code # 1 catches some of the crossing points,
missing others, while Code #2 catches all the crosses
that it
was supposed to.
The change in code #2 that enabled every cross, even
if it did not occurred in the same price bar was
achieved
by simply modifying the first line of buy and sell
instruction:
When I modified the first rule from: "crosses
above/below" to ">/<" in both buy;
From: f FMA crosses above SMA and close
> SMA then Buy("………….
To: if FMA > SMA and close > SMA
then Buy("……………..
and sell signals
From: if FMA crosses below SMA and close
< SMA then Sell short("…………..
To: if FMA < SMA and close < SMA
then Sell short("
I achieved what I wanted in terms of getting signals
at every cross, Figure #2
http://www.fea.com.br/Coding/Figure_02.gif
So here is where my problem starts. When I apply 2
simple money management rules to the codes I have
shown
above, I get very different responses from within
EasyLanguage.
Lets assume I apply the same 2 money management
strategies to both strategies, a "Profit Target" exit
equal
to 100 dollars or 2 ES point and a "Stop Loss" exit
equal to 100 dollars as well.
Their signals can be seen in the following links
Figure #3 http://www.fea.com.br/Coding/Figure_03.gif
is related to Money Mngt Applied to Code#1
Figure #4 http://www.fea.com.br/Coding/Figure_04.gif
is related to Money Mngt Applied to Code#2
As one can see in Figure #3 after each valid cross
signal I get only one trade when money is applied, and
in
Figure #4, once a Profit Target and or a Stop Loss
rule is applied to the code #2, I may have more than
one
trade in the same direction of the original signal
depending on how large is the movement of the
underlying
instrument, and a reverse trade with the opposite
signal is only generated at the cross in the opposite
direction.
What I need from the List is help in solving this
problem of multiple entries of the same direction of
the signal, so
I can have a single trade per cross in Code #2 when
money management is applied. So I can use the
Tradestation optimization procedure to find a 2
optimal values, one for "Profit Target", and the other
for "Stop
Loss" amount.
I believe I need some type a flag in order to control
what is going on inside Code #2, but I have no clue on
how
to do this in terms of ELZ coding.
Any help is truly appreciated
EJM
Click below to
To download the ELS code
http://www.fea.com.br/coding/EM_Cross.orw
To download the sample workspace for TS 2000i
http://www.fea.com.br/coding/EM_Cross.els
|