Dark Theme
Light Theme
Trading Articles
Article Categories
Article Tools
Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to
register in order to view the content of the threads and start contributing to our community.
It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
MACD Cross_Above/Cross_Below in EL
Updated September 30, 2012
Top Posters
looks_one
ericbrown
with 2 posts (1 thanks)
looks_two
Bimi
with 2 posts (3 thanks)
looks_3
Quick Summary
with 1 posts (0 thanks)
looks_4
Arich
with 1 posts (0 thanks)
trending_up
7,249 views
thumb_up
4 thanks given
group
3 followers
forum
5 posts
attach_file
1 attachments
MACD Cross_Above/Cross_Below in EL
September 29th, 2012, 09:29 PM
Springfield, Missouri
Experience: Intermediate
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: EUR/USD
Posts: 28 since Sep 2012
Thanks Given: 29
Thanks Received: 5
Hello,
I'm trying to figure out how to code a crosses_above and crosses_below using a MACD in EasyLanguage .
When I try "if MyMACD crosses_above MACDAvg" I get the syntax error code 'expecting bars.' I tried just coding it as "if MyMACD > MACDAvg" and it compiles, but that doesn't have the affect that I'm shooting for. I've looked for a couple of hours for examples of how to code this but can't find any. Any help is appreciated!
p.s. This code won't compile because of this one issue.
Code
inputs:
SlowLength (26),
FastLength (12),
MACDLength (3),
Target1 (40),
Target2 (20),
Target3 (40),
StopSize (40),
BE2 (0), // 0=false 1=true
BE3 (0); // 0=false 1=true
vars:
ticksize (MinMove/PriceScale),
MyMACD (0),
MACDAvg (0),
MACDDiff (0),
t1 (Target1 * ticksize),
t2 (Target1 + Target2 *ticksize),
t3 (Target1 + Target2 + Target3 * ticksize),
st1 (0),
st2 (0),
st3 (0);
MyMACD = MACD(Close, FastLength, SlowLength);
MACDAvg = XAverage(MyMACD, MACDLength);
MACDDiff = MyMACD - MACDAvg;
// Open new Positions
if MarketPosition = 0 then begin
if MyMACD crosses_above MACDAvg and MyMACD <= 0 and MACDAvg <= 0 then begin
Buy ("Enter Long1") 100000 contract next bar at market;
Buy ("Enter Long2") 100000 contract next bar at market;
Buy ("Enter Long3") 100000 contract next bar at market;
end;
if MyMACD crosses_below MACDAvg and MyMACD >= 0 and MACDAvg >= 0 then begin
Sell ("Enter Short1") 100000 contract next bar at market;
Sell ("Enter Short2") 100000 contract next bar at market;
Sell ("Enter Short3") 100000 contract next bar at market;
end;
end;
// Manage open orders
if MarketPosition = 0 then begin
st1 = EntryPrice - (StopSize * ticksize);
st2 = iff(BE2 = 1, EntryPrice, EntryPrice - (StopSize * ticksize));
st3 = iff(BE3 = 1, EntryPrice, EntryPrice - (StopSize * ticksize));
if CurrentContracts = 100000 then begin
Sell ("Exit l3-c1 Target") 100000 Contract Next Bar at (EntryPrice + t3) Limit;
Sell ("Exit l3-c1 Stop") 100000 Contract Next Bar at st3 Stop;
end;
if CurrentContracts = 200000 then begin
Sell ("Exit l2-c2 Target") 100000 Contract Next Bar at (EntryPrice + t2) Limit;
Sell ("Exit l2-c2 Stop") 100000 Contract Next Bar at st2 Stop;
Sell ("Exit l3-c2 Target") 100000 Contract Next Bar at (EntryPrice + t3) Limit;
Sell ("Exit l3-c2 Stop") 100000 Contract Next Bar at st3 Stop;
end;
if CurrentContracts = 300000 then begin
Sell ("Exit l1-c3 Target") 100000 Contract Next Bar at (EntryPrice + t2) Limit;
Sell ("Exit l1-c3 Stop") 100000 Contract Next Bar at st1 Stop;
Sell ("Exit l2-c3 Target") 100000 Contract Next Bar at (EntryPrice + t2) Limit;
Sell ("Exit l2-c3 Stop") 100000 Contract Next Bar at st2 Stop;
Sell ("Exit l3-c3 Target") 100000 Contract Next Bar at (EntryPrice + t3) Limit;
Sell ("Exit l3-c3 Stop") 100000 Contract Next Bar at st3 Stop;
end;
end;
if MarketPosition = -1 then begin
st1 = EntryPrice + (StopSize * ticksize);
st2 = iff(BE2 = 1, EntryPrice, EntryPrice + (StopSize * ticksize));
st3 = iff(BE3 = 1, EntryPrice, EntryPrice + (StopSize * ticksize));
if CurrentContracts = -100000 then begin
BuyToCover ("Exit s3-c1 Target") 100000 Contract Next Bar at (EntryPrice - t3) Limit;
BuyToCover ("Exit s3-c1 Stop") 100000 Contract Next Bar at st3 Stop;
end;
if CurrentContracts = -200000 then begin
BuyToCover ("Exit s2-c2 Target") 100000 Contract Next Bar at (EntryPrice - t2) Limit;
BuyToCover ("Exit s2-c2 Stop") 100000 Contract Next Bar at st2 Stop;
BuyToCover ("Exit s3-c2 Target") 100000 Contract Next Bar at (EntryPrice - t3) Limit;
BuyToCover ("Exit s3-c2 Stop") 100000 Contract Next Bar at st3 Stop;
end;
if CurrentContracts = -300000 then begin
BuyToCover ("Exit s1-c3 Target") 100000 Contract Next Bar at (EntryPrice - t2) Limit;
BuyToCover ("Exit s1-c3 Stop") 100000 Contract Next Bar at st1 Stop;
BuyToCover ("Exit s2-c3 Target") 100000 Contract Next Bar at (EntryPrice - t2) Limit;
BuyToCover ("Exit s2-c3 Stop") 100000 Contract Next Bar at st2 Stop;
BuyToCover ("Exit s3-c3 Target") 100000 Contract Next Bar at (EntryPrice - t3) Limit;
BuyToCover ("Exit s3-c3 Stop") 100000 Contract Next Bar at st3 Stop;
end;
end;
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
September 29th, 2012, 10:48 PM
London
Posts: 118 since Mar 2010
Thanks Given: 42
Thanks Received: 58
Arich
Hello,
I'm trying to figure out how to code a crosses_above and crosses_below using a MACD in
EasyLanguage .
When I try "if MyMACD crosses_above MACDAvg" I get the syntax error code 'expecting bars.' I tried just coding it as "if MyMACD > MACDAvg" and it compiles, but that doesn't have the affect that I'm shooting for. I've looked for a couple of hours for examples of how to code this but can't find any.
Any help is appreciated!
p.s. This code won't compile because of this one issue.
use this instead
Code
if MyMACD > MACDAvg
and MyMACD[1] < MACDAvg[1]
...
September 30th, 2012, 12:05 AM
Tulsa, OK
Experience: Advanced
Platform: Tradestation, TOS, Python
Broker: IQFeed, Tradestation, TOS
Trading: ES, SPY, Options
Posts: 201 since Jan 2011
Thanks Given: 339
Thanks Received: 258
Arich
"if MyMACD crosses_above MACDAvg"
Why the "crosses_above"and "crosses_below" ? I've not seen this language/syntax in EL before.
Did you try "crosses over" (for crosses_above) and "crosses below" (for crosses_below)?
I just tried it out and the strat went long at a MACD Crossover. Not sure if this is the actual entry signal you wanted but it is compiling and entering. Screenshot attached.
The code I have is below.
Code
inputs:
SlowLength (26),
FastLength (12),
MACDLength (3),
Target1 (40),
Target2 (20),
Target3 (40),
StopSize (40),
BE2 (0), // 0=false 1=true
BE3 (0); // 0=false 1=true
vars:
ticksize (MinMove/PriceScale),
MyMACD (0),
MACDAvg (0),
MACDDiff (0),
t1 (Target1 * ticksize),
t2 (Target1 + Target2 *ticksize),
t3 (Target1 + Target2 + Target3 * ticksize),
st1 (0),
st2 (0),
st3 (0);
MyMACD = MACD(Close, FastLength, SlowLength);
MACDAvg = XAverage(MyMACD, MACDLength);
MACDDiff = MyMACD - MACDAvg;
// Open new Positions
if MarketPosition = 0 then begin
if MyMACD crosses over MACDAvg and MyMACD <= 0 and MACDAvg <= 0 then begin
Buy ("Enter Long1") 100000 contract next bar at market;
Buy ("Enter Long2") 100000 contract next bar at market;
Buy ("Enter Long3") 100000 contract next bar at market;
end;
if MyMACD crosses below MACDAvg and MyMACD >= 0 and MACDAvg >= 0 then begin
Sell ("Enter Short1") 100000 contract next bar at market;
Sell ("Enter Short2") 100000 contract next bar at market;
Sell ("Enter Short3") 100000 contract next bar at market;
end;
end;
// Manage open orders
if MarketPosition = 0 then begin
st1 = EntryPrice - (StopSize * ticksize);
st2 = iff(BE2 = 1, EntryPrice, EntryPrice - (StopSize * ticksize));
st3 = iff(BE3 = 1, EntryPrice, EntryPrice - (StopSize * ticksize));
if CurrentContracts = 100000 then begin
Sell ("Exit l3-c1 Target") 100000 Contract Next Bar at (EntryPrice + t3) Limit;
Sell ("Exit l3-c1 Stop") 100000 Contract Next Bar at st3 Stop;
end;
if CurrentContracts = 200000 then begin
Sell ("Exit l2-c2 Target") 100000 Contract Next Bar at (EntryPrice + t2) Limit;
Sell ("Exit l2-c2 Stop") 100000 Contract Next Bar at st2 Stop;
Sell ("Exit l3-c2 Target") 100000 Contract Next Bar at (EntryPrice + t3) Limit;
Sell ("Exit l3-c2 Stop") 100000 Contract Next Bar at st3 Stop;
end;
if CurrentContracts = 300000 then begin
Sell ("Exit l1-c3 Target") 100000 Contract Next Bar at (EntryPrice + t2) Limit;
Sell ("Exit l1-c3 Stop") 100000 Contract Next Bar at st1 Stop;
Sell ("Exit l2-c3 Target") 100000 Contract Next Bar at (EntryPrice + t2) Limit;
Sell ("Exit l2-c3 Stop") 100000 Contract Next Bar at st2 Stop;
Sell ("Exit l3-c3 Target") 100000 Contract Next Bar at (EntryPrice + t3) Limit;
Sell ("Exit l3-c3 Stop") 100000 Contract Next Bar at st3 Stop;
end;
end;
if MarketPosition = -1 then begin
st1 = EntryPrice + (StopSize * ticksize);
st2 = iff(BE2 = 1, EntryPrice, EntryPrice + (StopSize * ticksize));
st3 = iff(BE3 = 1, EntryPrice, EntryPrice + (StopSize * ticksize));
if CurrentContracts = -100000 then begin
BuyToCover ("Exit s3-c1 Target") 100000 Contract Next Bar at (EntryPrice - t3) Limit;
BuyToCover ("Exit s3-c1 Stop") 100000 Contract Next Bar at st3 Stop;
end;
if CurrentContracts = -200000 then begin
BuyToCover ("Exit s2-c2 Target") 100000 Contract Next Bar at (EntryPrice - t2) Limit;
BuyToCover ("Exit s2-c2 Stop") 100000 Contract Next Bar at st2 Stop;
BuyToCover ("Exit s3-c2 Target") 100000 Contract Next Bar at (EntryPrice - t3) Limit;
BuyToCover ("Exit s3-c2 Stop") 100000 Contract Next Bar at st3 Stop;
end;
if CurrentContracts = -300000 then begin
BuyToCover ("Exit s1-c3 Target") 100000 Contract Next Bar at (EntryPrice - t2) Limit;
BuyToCover ("Exit s1-c3 Stop") 100000 Contract Next Bar at st1 Stop;
BuyToCover ("Exit s2-c3 Target") 100000 Contract Next Bar at (EntryPrice - t2) Limit;
BuyToCover ("Exit s2-c3 Stop") 100000 Contract Next Bar at st2 Stop;
BuyToCover ("Exit s3-c3 Target") 100000 Contract Next Bar at (EntryPrice - t3) Limit;
BuyToCover ("Exit s3-c3 Stop") 100000 Contract Next Bar at st3 Stop;
end;
end;
The following user says Thank You to ericbrown for this post:
September 30th, 2012, 12:23 AM
London
Posts: 118 since Mar 2010
Thanks Given: 42
Thanks Received: 58
ericbrown
Why the "crosses_above"and "crosses_below" ? I've not seen this language/syntax in EL before.
Did you try "crosses over" (for crosses_above) and "crosses below" (for crosses_below)?
I just tried it out and the strat went long at a MACD Crossover. Not sure if this is the actual entry signal you wanted but it is compiling and entering.
Screenshot attached.
The code I have is below.
In some manuals, they were printed as "crosses_above" and "crosses_below".
They should have read: "crosses above" and "crosses below",
ie. without the underscore in between the words.
September 30th, 2012, 09:28 AM
Tulsa, OK
Experience: Advanced
Platform: Tradestation, TOS, Python
Broker: IQFeed, Tradestation, TOS
Trading: ES, SPY, Options
Posts: 201 since Jan 2011
Thanks Given: 339
Thanks Received: 258
Bimi
In some manuals, they were printed as "crosses_above" and "crosses_below".
They should have read: "crosses above" and "crosses below",
ie. without the underscore in between the words.
Gotcha..I didn't know that. Thanks!
Last Updated on September 30, 2012