Jump to content

Welcome to the new Traders Laboratory! Please bear with us as we finish the migration over the next few days. If you find any issues, want to leave feedback, get in touch with us, or offer suggestions please post to the Support forum here.

  • Welcome Guests

    Welcome. You are currently viewing the forum as a guest which does not give you access to all the great features at Traders Laboratory such as interacting with members, access to all forums, downloading attachments, and eligibility to win free giveaways. Registration is fast, simple and absolutely free. Create a FREE Traders Laboratory account here.

geektrading

Code ATR Ratchet in EasyLanguage

Recommended Posts

Hello,

 

would someone be interested to code the ATR Ratchet by Chuck LeBeau in EasyLanguage?

 

Full description of the exit strategy can be found here: http://www.forexmt4.com/_MT4_Systems%20Documentation/Exit%20Strategy%20ATR%20Ratchet.doc

 

If you look at google for "ATR Ratchet", you´ll find that the strategy exists for several other trading platforms already (MT4, Metastock), and also someone has coded it in Easylanguage already. However, the problem is that this is on the tradestation.com forums and I don´t have access there since I am a Multicharts user.

 

So my idea is to either code this strategy from scratch for Easylanguage, or maybe someone can get the already existing code from the tradestation.com forum, in case the author allows a distribution.

 

Thanks guys.

Share this post


Link to post
Share on other sites

Here is the code from the ELD posted by Zapisy

 

_highestAtr

type: function

[LegacyColorValue = true]; 

{
 Returns the highest ATR value from a short ATR and a longer ATR.

MAR 27 2004 : Holden Glova : Created
}

inputs:
 shortATRLength(numericSimple), longATRLength(numericSimple);

vars:
shortATRValue(0), longATRValue(0);


shortATRValue = AvgTrueRange(shortATRLength);
longATRValue  = AvgTrueRange(longATRLength);

if shortATRValue > longATRValue then begin
_highestATR = shortATRValue;
end
else begin
_highestATR = longATRValue;
end;

 

_AtrRatchetLX

type: strategy

[LegacyColorValue = true]; 

input: atrMultiplier			(0.05);
input: shortAtrLength			(4);
input: longAtrLength			(20);
input: numLowsBack				(5);
input: numAtrsToStartRatchet	(4);	
input: ______________________	(0);
input: www.linetrol.com			(0);


vars:
stopPrice(0), atrValue(0), ratchetingBarCnt(0),
hasStarted(false);


if marketPosition = 1 then begin
atrValue = _highestAtr(shortAtrLength, longAtrLength);

if C > (entryPrice(0) + (atrValue * numAtrsToStartRatchet)) and hasStarted = false then begin
	hasStarted = true;
	stopPrice  = entryPrice(0);
end;

if hasStarted then begin
	if ratchetingBarCnt > 0 then begin
		if stopPrice < Lowest(L, numLowsBack) then stopPrice = Lowest(L, numLowsBack);
		stopPrice = stopPrice + (atrValue * (atrMultiplier * ratchetingBarCnt));
	end;

	sell("Ratchet_LX") next bar at stopPrice stop;
end;

ratchetingBarCnt = ratchetingBarCnt + 1;
end;


if marketPosition <> 1 then begin
hasStarted = false;
ratchetingBarCnt = 0;
end;

 

_AtrRatchetSX

type:strategy

[LegacyColorValue = true]; 

input: atrMultiplier			(0.05);
input: shortAtrLength			(4); 
input: longAtrLength			(20);
input: numHighsBack				(5);
input: numAtrsToStartRatchet	(4);	
input: ______________________	(0);
input: www.linetrol.com			(0);


vars:
stopPrice(0), atrValue(0), ratchetingBarCnt(0),
hasStarted(false);


if marketPosition = -1 then begin
atrValue = _highestAtr(shortAtrLength, longAtrLength);

if C < (entryPrice(0) - (atrValue * numAtrsToStartRatchet)) and hasStarted = false then begin
	hasStarted = true;
	stopPrice  = entryPrice(0);
end;

if hasStarted then begin
	if ratchetingBarCnt > 0 then begin
		if stopPrice > Highest(H, numHighsBack) then stopPrice = Highest(H, numHighsBack);
		stopPrice = stopPrice - (atrValue * (atrMultiplier * ratchetingBarCnt));
	end;

	buy to cover("Ratchet_SX") next bar at stopPrice stop;
end;

ratchetingBarCnt = ratchetingBarCnt + 1;
end;


if marketPosition <> -1 then begin
hasStarted = false;
ratchetingBarCnt = 0;
end;

Share this post


Link to post
Share on other sites

ATR Ratchet is almost the same as the "Super Trend" Indicator which is already available for MT4, Ninjatrader, Esignal, Amibroker, Multicharts and Tradestation another similar indicator is "Trend Magic"

Share this post


Link to post
Share on other sites

Regarding the below listed code, would I use this code as a stop for my entry (buy or sell short) trade code? Would I use all the code you have listed below or is your code broken down into segments? Many thanks for any and all help. By the way, I am new to Easylanguage so please bear with me.

 

 

 

 

 

 

 

 

 

Here is the code from the ELD posted by Zapisy

 

_highestAtr

type: function

[LegacyColorValue = true]; 

{
 Returns the highest ATR value from a short ATR and a longer ATR.

MAR 27 2004 : Holden Glova : Created
}

inputs:
 shortATRLength(numericSimple), longATRLength(numericSimple);

vars:
shortATRValue(0), longATRValue(0);


shortATRValue = AvgTrueRange(shortATRLength);
longATRValue  = AvgTrueRange(longATRLength);

if shortATRValue > longATRValue then begin
_highestATR = shortATRValue;
end
else begin
_highestATR = longATRValue;
end;

 

_AtrRatchetLX

type: strategy

[LegacyColorValue = true]; 

input: atrMultiplier			(0.05);
input: shortAtrLength			(4);
input: longAtrLength			(20);
input: numLowsBack				(5);
input: numAtrsToStartRatchet	(4);	
input: ______________________	(0);
input: www.linetrol.com			(0);


vars:
stopPrice(0), atrValue(0), ratchetingBarCnt(0),
hasStarted(false);


if marketPosition = 1 then begin
atrValue = _highestAtr(shortAtrLength, longAtrLength);

if C > (entryPrice(0) + (atrValue * numAtrsToStartRatchet)) and hasStarted = false then begin
	hasStarted = true;
	stopPrice  = entryPrice(0);
end;

if hasStarted then begin
	if ratchetingBarCnt > 0 then begin
		if stopPrice < Lowest(L, numLowsBack) then stopPrice = Lowest(L, numLowsBack);
		stopPrice = stopPrice + (atrValue * (atrMultiplier * ratchetingBarCnt));
	end;

	sell("Ratchet_LX") next bar at stopPrice stop;
end;

ratchetingBarCnt = ratchetingBarCnt + 1;
end;


if marketPosition <> 1 then begin
hasStarted = false;
ratchetingBarCnt = 0;
end;

 

_AtrRatchetSX

type:strategy

[LegacyColorValue = true]; 

input: atrMultiplier			(0.05);
input: shortAtrLength			(4); 
input: longAtrLength			(20);
input: numHighsBack				(5);
input: numAtrsToStartRatchet	(4);	
input: ______________________	(0);
input: www.linetrol.com			(0);


vars:
stopPrice(0), atrValue(0), ratchetingBarCnt(0),
hasStarted(false);


if marketPosition = -1 then begin
atrValue = _highestAtr(shortAtrLength, longAtrLength);

if C < (entryPrice(0) - (atrValue * numAtrsToStartRatchet)) and hasStarted = false then begin
	hasStarted = true;
	stopPrice  = entryPrice(0);
end;

if hasStarted then begin
	if ratchetingBarCnt > 0 then begin
		if stopPrice > Highest(H, numHighsBack) then stopPrice = Highest(H, numHighsBack);
		stopPrice = stopPrice - (atrValue * (atrMultiplier * ratchetingBarCnt));
	end;

	buy to cover("Ratchet_SX") next bar at stopPrice stop;
end;

ratchetingBarCnt = ratchetingBarCnt + 1;
end;


if marketPosition <> -1 then begin
hasStarted = false;
ratchetingBarCnt = 0;
end;

Share this post


Link to post
Share on other sites
On 2013/6/3 at 7:52 AM, gim said:

[LegacyColorValue = true]; input: atrMultiplier (0.05); input: shortAtrLength (4); input: longAtrLength (20); input: numLowsBack (5); input: numAtrsToStartRatchet (4); input: ______________________ (0); input: www.linetrol.com (0); vars: stopPrice(0), atrValue(0), ratchetingBarCnt(0), hasStarted(false); if marketPosition = 1 then begin atrValue = _highestAtr(shortAtrLength, longAtrLength); if C > (entryPrice(0) + (atrValue * numAtrsToStartRatchet)) and hasStarted = false then begin hasStarted = true; stopPrice = entryPrice(0); end; if hasStarted then begin if ratchetingBarCnt > 0 then begin if stopPrice < Lowest(L, numLowsBack) then stopPrice = Lowest(L, numLowsBack); stopPrice = stopPrice + (atrValue * (atrMultiplier * ratchetingBarCnt)); end; sell("Ratchet_LX") next bar at stopPrice stop; end; ratchetingBarCnt = ratchetingBarCnt + 1; end; if marketPosition <> 1 then begin hasStarted = false; ratchetingBarCnt = 0; end;

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

By using this site, you agree to our Terms of Use.