NexusFi: Find Your Edge


Home Menu

 





MACD Cross_Above/Cross_Below in EL


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one ericbrown with 2 posts (1 thanks)
    2. looks_two Bimi with 2 posts (3 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 Arich with 1 posts (0 thanks)
    1. trending_up 7,249 views
    2. thumb_up 4 thanks given
    3. group 3 followers
    1. forum 5 posts
    2. attach_file 1 attachments




 
Search this Thread

MACD Cross_Above/Cross_Below in EL

  #1 (permalink)
 Arich 
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;

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
ZombieSqueeze
Platforms and Indicators
NexusFi Journal Challenge - April 2024
Feedback and Announcements
Request for MACD with option to use different MAs for fa …
NinjaTrader
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Retail Trading As An Industry
67 thanks
NexusFi site changelog and issues/problem reporting
47 thanks
Battlestations: Show us your trading desks!
43 thanks
GFIs1 1 DAX trade per day journal
32 thanks
What percentage per day is possible? [Poll]
31 thanks

  #3 (permalink)
Bimi
London
 
Posts: 118 since Mar 2010
Thanks Given: 42
Thanks Received: 58



Arich View Post
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] 
...

Reply With Quote
  #4 (permalink)
 
ericbrown's Avatar
 ericbrown 
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 View Post
"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;

Attached Thumbnails
Click image for larger version

Name:	TradeStation 9.1 - laptop - Comm_of_traders - [Chart Analysis - SPY Daily [ARCX]_2012-09-29_23-0.png
Views:	286
Size:	59.8 KB
ID:	90637  
Follow me on Twitter Reply With Quote
The following user says Thank You to ericbrown for this post:
  #5 (permalink)
Bimi
London
 
Posts: 118 since Mar 2010
Thanks Given: 42
Thanks Received: 58


ericbrown View Post
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.

Reply With Quote
  #6 (permalink)
 
ericbrown's Avatar
 ericbrown 
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 View Post
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!

Follow me on Twitter Reply With Quote





Last Updated on September 30, 2012


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts