EasyLanguage SuperTrend indicator - EasyLanguage Programming | futures.io
futures.io futures trading


EasyLanguage SuperTrend indicator
Started: by Big Mike Views / Replies:50,403 / 79
Last Reply: Attachments:9

Welcome to futures.io.

Welcome, Guest!

This forum was established to help traders (especially futures traders) by openly sharing indicators, strategies, methods, trading journals and discussing the psychology of trading.

We are fundamentally different than most other trading forums:
  • We work extremely hard to keep things positive on our forums.
  • We do not tolerate rude behavior, trolling, or vendor advertising in posts.
  • We firmly believe in openness and encourage sharing. The holy grail is within you, it is not something tangible you can download.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.


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, and we will never resell your private information.

-- Big Mike

Reply
 9  
 
Thread Tools Search this Thread
 

EasyLanguage SuperTrend indicator

  #21 (permalink)
Elite Member
Dallas, Texas, USA
 
Futures Experience: Beginner
Platform: NT 6.5 & Tradestation
Favorite Futures: Equities & ES
 
Posts: 42 since Sep 2010
Thanks: 19 given, 7 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
 
  #22 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 45,652 since Jun 2009
Thanks: 29,044 given, 80,645 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

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
 
  #23 (permalink)
Elite Member
Dallas, Texas, USA
 
Futures Experience: Beginner
Platform: NT 6.5 & Tradestation
Favorite Futures: Equities & ES
 
Posts: 42 since Sep 2010
Thanks: 19 given, 7 received


Thanks much Mike. Will try this.

Reply With Quote
 
  #24 (permalink)
Trading Apprentice
vienna
 
Futures Experience: Master
Platform: MultiCharts
Favorite Futures: NQ
 
Posts: 22 since Aug 2009
Thanks: 0 given, 37 received

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

Reply With Quote
 
  #25 (permalink)
Elite Member
Nanjing, NJ
 
Futures Experience: Intermediate
Platform: CQG
Broker/Data: Optimus CQG
Favorite Futures: Flute
 
Posts: 91 since Jun 2010
Thanks: 25 given, 62 received

flag&flagh ?

Futures Edge on FIO

Which products do you trade?

 
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
 
  #26 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 45,652 since Jun 2009
Thanks: 29,044 given, 80,645 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

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
 
  #27 (permalink)
Elite Member
Nanjing, NJ
 
Futures Experience: Intermediate
Platform: CQG
Broker/Data: Optimus CQG
Favorite Futures: Flute
 
Posts: 91 since Jun 2010
Thanks: 25 given, 62 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
 
  #28 (permalink)
Elite Member
NJ
 
Futures Experience: Beginner
Platform: NinjaTrader
 
Posts: 7 since May 2010
Thanks: 2 given, 21 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 7 users say Thank You to chtangwin for this post:
 
  #29 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 45,652 since Jun 2009
Thanks: 29,044 given, 80,645 received

Nice work, we can always use some good EL programmers

Mike

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
 
  #30 (permalink)
Elite Member
NJ
 
Futures Experience: Beginner
Platform: NinjaTrader
 
Posts: 7 since May 2010
Thanks: 2 given, 21 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:

Reply



futures.io > > > > > EasyLanguage SuperTrend indicator

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

2016 True Edge Awards: Voting is open until Jan 21!

Now
 

Bookmap New Indicator Panel, Cumulative Delta, Order Flow demo

Jan 17
 

An Afternoon with FIO member Massive l

Elite only

Leo Murphy: Making sense of Technical Analysis and Random Walk

Elite only
 

FuturesTrader71: Ask Me Anything

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
EasyLanguage ADXVMA Indicator Big Mike EasyLanguage Programming 15 October 29th, 2014 10:51 PM
Error with recoded Supertrend Line for EasyLanguage DarrenH EasyLanguage Programming 3 February 5th, 2011 01:05 PM
NinjaTrader indicator SuperTrend + audio alerts ojwright NinjaTrader 6 July 29th, 2010 02:54 AM
EasyLanguage ZeroLagEMA indicator Big Mike EasyLanguage Programming 1 April 10th, 2010 02:16 PM
EasyLanguage ZeroLagWMA indicator Big Mike EasyLanguage Programming 1 April 10th, 2010 02:09 PM


All times are GMT -4. The time now is 10:58 PM.

no new posts
Page generated 2017-01-16 in 0.16 seconds with 20 queries on phoenix via your IP 54.204.95.166