EasyLanguage SuperTrend indicator - futures io
futures io futures trading



EasyLanguage SuperTrend indicator


Discussion in EasyLanguage Programming

Updated July 23rd 2019 by auato
      Top Posters
    1. looks_one Big Mike with 11 posts (55 thanks)
    2. looks_two ABCTG with 9 posts (6 thanks)
    3. looks_3 chtangwin with 6 posts (23 thanks)
    4. looks_4 Sam7768 with 5 posts (2 thanks)
      Best Posters
    1. looks_one Big Mike with 5.0 thanks per post
    2. looks_two chtangwin with 3.8 thanks per post
    3. looks_3 cedar with 1.3 thanks per post
    4. looks_4 ABCTG with 0.7 thanks per post
    1. trending_up 70,765 views
    2. thumb_up 96 thanks given
    3. group 39 followers
    1. forum 84 replies
    2. attach_file 9 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 100,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
 

EasyLanguage SuperTrend indicator

(login for full post details)
  #21 (permalink)
Dallas, Texas, USA
 
Experience: Beginner
Platform: NT 6.5 & Tradestation
Trading: Equities & ES
 
Posts: 45 since Sep 2010
Thanks: 21 given, 9 received

Sure Mike. This is what I was doing...

***************
inputs:ATRLength(9), ATRMult(1), Strength(9);
Var: p(0),strend(0),st(0);

st = SuperTrend(ATRLength, ATRMult, Strength, strend);

If st cross below close then buy ("buy") next bar at market;

if st cross above close then Sell ("sell") next bar at market;

***********************

This works, except for the fact that, at times, even though close crosses supertrend (from above or below), the Supertrend does not change the side (which is a great thing). But,

because the way I coded (above), the strategy keeps buying & selling in this situations (as I posted in above pic). How do I control this / code in such a way that buy or sell happens only when the supertrend changes side and not just close crossing Supertrend.

Any help will be greatly appreciated.

Rgds,

Reply With Quote
The following user says Thank You to Sam7768 for this post:

Can you help answer these questions
from other members on futures io?
Convert NinjaTrader NT7 indicator to Tradestation EasyLanguage and RADARSCREEN
Platforms and Indicators
Issue meeting order entry conditions
Elite Automated NinjaTrader Trading
Last 5 minutes Label
ThinkOrSwim
Moving average with Lag reduction
NinjaTrader
Linux?
ThinkOrSwim
 
 
(login for full post details)
  #22 (permalink)
Site Administrator
Manta, Ecuador
 
Experience: Advanced
Platform: My own custom solution
Trading: Emini Futures
 
Big Mike's Avatar
 
Posts: 48,780 since Jun 2009
Thanks: 31,495 given, 94,177 received

Gotcha.

The strend var is the key if i remember, monitor it for a change = if I remember it is 1 for long, -1 for short, so you could do something like:

if strend = 1 and strend[1] <> 1 then buy 1 contract next bar at market;

Mike

We're here to help -- just ask

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/
Follow me on Twitter Visit my Facebook Visit my futures io Trade Journal Reply With Quote
The following user says Thank You to Big Mike for this post:
 
(login for full post details)
  #23 (permalink)
Dallas, Texas, USA
 
Experience: Beginner
Platform: NT 6.5 & Tradestation
Trading: Equities & ES
 
Posts: 45 since Sep 2010
Thanks: 21 given, 9 received


Thanks much Mike. Will try this.

Reply With Quote
 
(login for full post details)
  #24 (permalink)
vienna
 
 
Posts: 22 since Aug 2009
Thanks: 0 given, 38 received

Does somebody know which codes lines need to be changed to plot the stop as stairstep on every bar like
in this picture https://www.janarps.com/catalog/images/images_big/Arps_Triple_Trender.jpg
instead of a solid line ?

Reply With Quote
 
(login for full post details)
  #25 (permalink)
Madison, NJ
 
Experience: Intermediate
Platform: CQG/TOS
Broker: Optimus/CQG
Trading: ZN/TN/ES/NQ
 
Posts: 131 since Jun 2010
Thanks: 59 given, 106 received

flag&flagh ?

Hi Mike, I'm looking at the SuperTrend function you posted last year.

This is the part that I need some help:

if
flag = 1 then up = avg + ATR;
if
flagh = 1 then dn = avg - ATR;


1)what are flag and flagh supposed to do
?
2)you already defined "up = avg + ATR" and "dn = avg - ATR" earlier in the indicator. Why do we have to repeat it here?

Thank you.

Reply With Quote
 
(login for full post details)
  #26 (permalink)
Site Administrator
Manta, Ecuador
 
Experience: Advanced
Platform: My own custom solution
Trading: Emini Futures
 
Big Mike's Avatar
 
Posts: 48,780 since Jun 2009
Thanks: 31,495 given, 94,177 received


shzhning View Post
Hi Mike, I'm looking at the SuperTrend function you posted last year.

This is the part that I need some help:

if
flag = 1 then up = avg + ATR;
if
flagh = 1 then dn = avg - ATR;


1)what are flag and flagh supposed to do
?
2)you already defined "up = avg + ATR" and "dn = avg - ATR" earlier in the indicator. Why do we have to repeat it here?

Thank you.

Yes I think we discussed this above in the thread, it was a mistake.

Mike

We're here to help -- just ask

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/
Follow me on Twitter Visit my Facebook Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #27 (permalink)
Madison, NJ
 
Experience: Intermediate
Platform: CQG/TOS
Broker: Optimus/CQG
Trading: ZN/TN/ES/NQ
 
Posts: 131 since Jun 2010
Thanks: 59 given, 106 received

Mike, thanks for the quick reply.

Regardless of the bug, I'm still confused about:

1) the purpose of flag and flagh, and
2) why the following is repeated in the function code
up = avg + (ATR*ATRMult);
dn = avg - (ATR*ATRMult);


Thank you.

Reply With Quote
 
(login for full post details)
  #28 (permalink)
NJ
 
Experience: Beginner
Platform: NinjaTrader
 
Posts: 7 since May 2010
Thanks: 2 given, 23 received

Thanks to Mike and others. This is a great thread. SuperTrend is one of my favorite indicator. I converted the anaSuperTrendM1 indicator (also from futures.io (formerly BMT)) to Easy Language. Hope it is ok.

Please let me know if any issues.

Indicator: anaSuperTrendM1

 
Code
inputs:
	periodMedian(3),
	periodATR(3),
	multiplier(2);
	
variables:
	median(0),
	upTrend(true),
	priorUpTrend(true),
	currentUpTrend(true),
	stopDot(0),
	priorStop(0),
	newStop(0),
	offset(0);

median = 0.5 * (high + low);
if currentbar = 1 then begin
	upTrend = true;
	stopDot = close;
end
else begin
	// FirstTickOfBar
	priorUpTrend = upTrend[1];
	priorStop = stopDot[1];
	offset = averagetruerange(periodATR)[1];

	if close > priorStop then begin
		upTrend = true;
		currentUpTrend = true;
		newStop = _anaMovingMedian(median, periodMedian) - multiplier * offset;
		if priorUpTrend = false then
			stopDot = newStop
		else
			stopDot = maxlist(newStop, priorStop);
	end
	else 
	if close < priorStop then begin
		upTrend = false;
		currentUpTrend = false;
		newStop = _anaMovingMedian(median, periodMedian) + multiplier * offset;
		if priorUpTrend = true then
			stopDot = newStop
		else
			stopDot = minlist(newStop, priorStop);
	end	
	else begin
		upTrend = priorUpTrend;
		currentUpTrend = priorUpTrend;
		stopDot = priorStop;
	end;
end;

if currentUpTrend = true  then plot1(stopDot, "UpStopDot");
if currentUpTrend = false then plot2(stopDot, "DnStopDot");
Function: _anaMovingMedian

 
Code
Inputs:
	PriceValue( numericseries ), 
	Period(NumericSimple);

variables:
	medianIndex(0),
	priorIndex(0),
	even(false),
	sPeriod(0),
	idx(0),
	val(0),
	initialized(false);
	
array:
	mArray[](0);

{ OnStartUp }	
if initialized = false then begin
	initialized = true;
	array_setmaxindex(mArray, Period);
	fill_array(mArray, 0.0);
	if mod(Period, 2) = 0 then begin
		even = true;
		medianIndex = floor(Period/2);
		priorIndex = medianIndex - 1;
	end
	else begin
		even = false;
		medianIndex = floor((Period - 1)/2);
	end;
end;

{ OnUpdate }
if currentbar < Period then begin
	sPeriod = currentbar;
	for idx = 1 to sPeriod begin
		mArray[idx] = PriceValue[idx-1];
	end;
	array_sort(mArray, 1, sPeriod, true);
	if mod(sPeriod, 2) = 0 then begin
		idx = floor(sPeriod/2);
		val = 0.5 * (mArray[Period - idx] + mArray[Period - idx + 1]);
	end
	else begin
		idx = floor((1 + sPeriod)/2);
		val = mArray[Period - idx + 1];
	end;
end
else begin
	for idx = 1 to Period begin
		mArray[idx] = PriceValue[idx-1];
	end;
	array_sort(mArray, 1, Period, true);
	if even then
		val = 0.5 * (mArray[medianIndex] + mArray[priorIndex])
	else
		val = mArray[medianIndex];
end;

_anaMovingMedian = val;

Reply With Quote
The following 8 users say Thank You to chtangwin for this post:
 
(login for full post details)
  #29 (permalink)
Site Administrator
Manta, Ecuador
 
Experience: Advanced
Platform: My own custom solution
Trading: Emini Futures
 
Big Mike's Avatar
 
Posts: 48,780 since Jun 2009
Thanks: 31,495 given, 94,177 received

Nice work, we can always use some good EL programmers

Mike

We're here to help -- just ask

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/
Follow me on Twitter Visit my Facebook Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #30 (permalink)
NJ
 
Experience: Beginner
Platform: NinjaTrader
 
Posts: 7 since May 2010
Thanks: 2 given, 23 received


Thanks Mike. futures.io (formerly BMT) is the greatest forum I ever know. Certainly glad I can contribute. I am new to EL and trading. Having programming background, writing code is easy, but learning trading is hard.

Feel free to let me know if there is any programming need, could be a good exercise for me.

Reply With Quote
The following user says Thank You to chtangwin for this post:


futures io Trading Community Platforms and Indicators EasyLanguage Programming > EasyLanguage SuperTrend indicator


July 23, 2019


Upcoming Webinars and Events
 

Free BloodHound Licenses for everyone!

June
 

Every journal equals ten meals for the hungry

June
     



Copyright © 2020 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