Welcome to the Traders Laboratory Forums.
Coding Forum Collaborate, receive help, or discuss coding related issues.

Reply
Old 02-07-2009, 09:58 AM   #1

Join Date: Jan 2008
Location: San Francisco
Posts: 394
Ignore this user

Thanks: 17
Thanked 338 Times in 156 Posts

ADX Easylanguage Code Without Calling a Function

I don't really understand programming enough to know why my Open Ecry can't call the right function to calculate ADX -- so I am copying this code that imbeds the needed function calls into the indicator --- because this works for me.


inputs:
Length(14);

vars:
Counter(0),
TRange(0), MyRange(Length),
PlusDM(0),MinusDM(0),
Plus14(0),
Minus14(0),
DMIup(0),DMIdn(0),
DMI_(0),
CummDMI(0), Return(0),
ADX_(0);

{ZZZZZZZZZZZZ...DMIup/DMIdn...ZZZZZZZZZZZZZ}

if CurrentBar = 1 then begin

MyRange = Length;
DMIup = 0;
Plus14 = 0;
Minus14 = 0;
TRange = 0;

for Counter = 0 to MyRange-1 begin

if (High[Counter] - High[Counter+1] < 0) then PlusDM = 0
else
PlusDM = High[Counter] - High[Counter+1];

if (Low [Counter+1] - Low [Counter] < 0) then MinusDM = 0
else
MinusDM = Low [Counter+1] - Low [Counter];

if MinusDM >= PlusDM then PlusDM = 0;
if PlusDM >= MinusDM then MinusDM = 0;

TRange= TRange + TrueRange[Counter] ;

Plus14 = Plus14 + PlusDM ;
Minus14 = Minus14 + MinusDM ;

end;{...counter=0 to myrange-1}

if TRange <> 0 then begin
DMIup = 100 * Plus14 / TRange;
DMIdn = 100 * Minus14 / TRange;
end
else begin
DMIup = 0 ;
DMIdn = 0;
end;

end{...currentbar=1}

else if CurrentBar > 1 then begin

if High[0]-High[1] < 0 then PlusDM = 0
else
PlusDM = High[0]-High[1];

if Low [1]-Low [0] < 0 then MinusDM = 0
else
MinusDM = Low [1]-Low [0];

if MinusDM >= PlusDM then PlusDM = 0;
if PlusDM >= MinusDM then MinusDM = 0;

if MyRange > 0 then begin
TRange = TRange[1] - (TRange[1] / MyRange) + TrueRange;
Plus14 = Plus14[1] - (Plus14[1] / MyRange) + PlusDM;
Minus14 = Minus14[1] - (Minus14[1] / MyRange) + MinusDM;
end;

if TRange<>0 then begin
DMIup = 100 * Plus14 / TRange;
DMIdn = 100 * Minus14 / TRange;
end
else begin
DMIup = 0;
DMIdn = 0;
end;

end;{...currentbar>1}


{ZZZZZZZZZZZZZZZ...DMI_.. .ZZZZZZZZZZZZZZZZ}

if DMIup + DMIdn= 0 then DMI_ = 0
else
DMI_ = 100 * AbsValue(DMIup - DMIdn)
/ (DMIup + DMIdn);


{ZZZZZZZZZZZ...ADX_...ZZZ ZZZZZZZZZZ}

Return = 0 ;

if CurrentBar >= 1 and Length > 0 then begin

if CurrentBar < Length then begin
CummDMI = 0 ;
for Counter = 0 to CurrentBar - 1 begin
CummDMI = CummDMI + DMI_[Counter] ;
end ;
Return = CummDMI / CurrentBar ;
end
else
Return = (ADX_[1] * (Length - 1) + DMI_) / Length ;

end ;

ADX_ = Return ;


{ZZZZZZZZZZZZ...Plot...ZZ ZZZZZZZZZZZ}


plot1(adx_,"adx");
Frank is offline  
Reply With Quote
Old 02-08-2009, 09:39 PM   #2

Join Date: Oct 2006
Location: na
Posts: 307
Ignore this user

Thanks: 33
Thanked 89 Times in 58 Posts

Re: ADX Easylanguage Code Without Calling a Function

That seems like a lot of work. If OEC doesnt have the right function, there is a simple way to do it:

1) Find function you need. This can be done via google pretty easy.
Highlight function, select copy.

Go Back to your code in OEC:

2) Right Click in Code
3) Select, "Insert Function"
4) Type in Name of function that OEC Is looking for. ( a lot of the times it does this automatically, but wont hurt to double check)

That should add the function you need, and assuming no other errors, should compile.

Here's is what an ADX indicator's code looks like when you use the function:

Code:
inputs: 
	Length( 14 ); 
	ADXTrend( 25 ) ; 

variables: 
	oDMIPlus( 0 ), 
	oDMIMinus( 0 ), 
	oDMI( 0 ), 
	oADX( 0 ), 
	oADXR( 0 ), 
	oVolty( 0 ) ;

Value1 = DirMovement( H, L, C, Length, oDMIPlus, oDMIMinus, oDMI, oADX, oADXR, 
 oVolty ) ;

Plot1( oDMIPlus, "DMI+" ) ;
Plot2( oDMIMinus, "DMI-" ) ;
Plot3( oADX, "ADX" ) ;




#function ADX
inputs: 
	Length( numericsimple ) ; { this input assumed to be a constant >= 1 }

variables:
	oDMIPlus( 0 ), 
	oDMIMinus( 0 ), 
	oDMI( 0 ), 
	oADX( 0 ), 
	oADXR( 0 ), 
	oVolty( 0 ) ;

Value1 = DirMovement( H, L, C, Length, oDMIPlus, oDMIMinus, oDMI, oADX, oADXR, 
 oVolty ) ;

ADX = oADX ;
trader273 is offline  
Reply With Quote

Reply

Thread Tools
Display Modes Help Others By Rating This Thread
Help Others By Rating This Thread:


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can function in TS8 return array? ImXotep Technical Analysis 5 05-25-2009 02:13 AM
Calling All FX Traders brownsfan019 Forex Trading Laboratory 3 03-06-2009 04:16 PM
Breakeven function on OEC Trader popstocks Open E Cry 3 02-03-2009 12:17 PM
[Site Update] Attachment Function Updated Soultrader Announcements 2 01-05-2009 08:23 AM
Januson Function Library januson Trading Indicators 0 11-28-2008 06:19 PM

All times are GMT -4. The time now is 12:29 PM.
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
CS to VB integration by DeskLancer
©2006-2011 Traders Laboratory, All Rights Reserved.