MACD Cross_Above/Cross_Below in EL - futures io
futures io futures trading



MACD Cross_Above/Cross_Below in EL


Discussion in EasyLanguage Programming

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




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • 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 and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

MACD Cross_Above/Cross_Below in EL

(login for full post details)
  #1 (permalink)
Springfield, Missouri
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: EUR/USD
 
Posts: 28 since Sep 2012
Thanks: 29 given, 5 received

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 futures io?
Which kind of Blockvolume is visible? - order processing
Emini and Emicro Index
ZigZag with Depth and Backstep
EasyLanguage Programming
COTbase for quant trading?
Elite Algorithmic NinjaTrader Trading
Short Interest Ratio indicator?
ThinkOrSwim
Webinar: Finding your own way in trading w/Adam Grimes
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on futures io
Selling Options on Futures?
109 thanks
Battlestations: Show us your trading desks!
108 thanks
Rank your Futures vs Stocks trading priority
55 thanks
Want your NinjaTrader indicator created, free?
27 thanks
Whats this confusion with margins?
21 thanks
 
(login for full post details)
  #3 (permalink)
London
 
 
Posts: 118 since Mar 2010
Thanks: 42 given, 58 received



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
 
(login for full post details)
  #4 (permalink)
Tulsa, OK
 
Experience: Advanced
Platform: Tradestation, TOS, Python
Broker: IQFeed, Tradestation, TOS
Trading: ES, SPY, Options
 
ericbrown's Avatar
 
Posts: 201 since Jan 2011
Thanks: 339 given, 253 received


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:	141
Size:	59.8 KB
ID:	90637  
Follow me on Twitter Reply With Quote
The following user says Thank You to ericbrown for this post:
 
(login for full post details)
  #5 (permalink)
London
 
 
Posts: 118 since Mar 2010
Thanks: 42 given, 58 received


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
 
(login for full post details)
  #6 (permalink)
Tulsa, OK
 
Experience: Advanced
Platform: Tradestation, TOS, Python
Broker: IQFeed, Tradestation, TOS
Trading: ES, SPY, Options
 
ericbrown's Avatar
 
Posts: 201 since Jan 2011
Thanks: 339 given, 253 received


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


futures io Trading Community Platforms and Indicators EasyLanguage Programming > MACD Cross_Above/Cross_Below in EL


Last Updated on September 30, 2012


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Battlestations! Show us your trading desk - $1,500 in prizes!

March
 

Importance of Finding Your Own Way w/Adam Grimes

Elite only
 

Journal Challenge w/Jigsaw

April
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts