Forex
Google

Go Back   Forex Trading > Programming > Metatrader Programming
Forex Forum Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-08-2007, 06:50 AM
dharsant dharsant is offline
Junior Member
 
Join Date: Apr 2007
Posts: 11
dharsant is on a distinguished road
Unhappy Please Help: Basic Variable Prob

Hey guys, I'm new to MQL and I'm after some help on an edit I'm doing to the Laguerre indicator.

What I'm Aiming to do, is have any value under 0.45 show up under the 0 axis at the corresponding value, as well as making the inverted color Red.......

It inverts fine......... I'm just having a problem resetting the variable.

It's pretty simple, I just can't seem to wrap my head around where I'm going wrong. Here's the code:

Quote:
Originally Posted by Laguerre Indicator
//+------------------------------------------------------------------+
//| Laguerre RSI.mq4 |
//| Copyright © 2005, David W. Thomas |
//| mailto:davidwt@usa.net |
//+------------------------------------------------------------------+
// based on http://www.mesasoftware.com/TimeWarp.doc.
#property copyright "Copyright © 2005, David W. Thomas"
#property link "mailto:davidwt@usa.net"

#property indicator_separate_window
#property indicator_level2 0.75
#property indicator_level3 0.45
#property indicator_level4 0.15
#property indicator_levelcolor DimGray
#property indicator_color1 Lime
#property indicator_color2 Red



#property indicator_minimum -1
#property indicator_maximum 1
#property indicator_buffers 1

//---- input parameters
extern double gamma=0.7;
extern color HistColor = Lime;



//---- buffers
double RSI[];
double L0[];
double L1[];
double L2[];
double L3[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(5);
//---- indicators

SetIndexDrawBegin(0, 1);
SetIndexDrawBegin(5, 1);
SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,3,HistC olor);
SetIndexLabel(0, "Laguerre RSI");
SetIndexEmptyValue(0, -0.01);
SetIndexBuffer(0, RSI);
SetIndexBuffer(1, L0);
SetIndexBuffer(2, L1);
SetIndexBuffer(3, L2);
SetIndexBuffer(4, L3);
//----
string short_name="LaguerreRSI(" + DoubleToStr(gamma, 2) + ")";
IndicatorShortName(short_name);


return(0);
}

//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars = IndicatorCounted();
double CU, CD;
//---- last counted bar will be recounted
if (counted_bars>0)
counted_bars--;
else
counted_bars = 1;
limit = Bars - counted_bars;
//---- computations for RSI
for (int i=limit; i>=0; i--)
{
L0[i] = (1.0 - gamma)*Close[i] + gamma*L0[i+1];
L1[i] = -gamma*L0[i] + L0[i+1] + gamma*L1[i+1];
L2[i] = -gamma*L1[i] + L1[i+1] + gamma*L2[i+1];
L3[i] = -gamma*L2[i] + L2[i+1] + gamma*L3[i+1];
//Print(i," Close[i]=",Close[i],", (1.0 - gamma)*Close[i]=",(1.0 - gamma)*Close[i],", gamma*L0[i+1]=",gamma*L0[i+1]);
//Print(i," L0=",L0[i],",L1=",L1[i],",L2=",L2[i],",L3=",L3[i]);

CU = 0;
CD = 0;
if (L0[i] >= L1[i])
CU = L0[i] - L1[i];
else
CD = L1[i] - L0[i];
if (L1[i] >= L2[i])
CU = CU + L1[i] - L2[i];
else
CD = CD + L2[i] - L1[i];
if (L2[i] >= L3[i])
CU = CU + L2[i] - L3[i];
else
CD = CD + L3[i] - L2[i];

if (CU + CD != 0)
RSI[i] = CU / (CU + CD);

if (RSI[i] > 0.45)
{
color HistColor = Lime;
}

if (RSI[i] <= 0.45)
{
color HistColor = Red;
RSI[i] = RSI[i] - RSI[i] - RSI[i];
}

}
return(0);
}
//+------------------------------------------------------------------+
As mentioned, I'm new to this language.... can I not just set new variable values if the expression changes? Some advice/help would be appreciated.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 10-10-2007, 03:30 AM
dharsant dharsant is offline
Junior Member
 
Join Date: Apr 2007
Posts: 11
dharsant is on a distinguished road
Resolved
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


Similar Threads
Thread Thread Starter Forum Replies Last Post
Basic questions ... cardio Questions 58 06-27-2008 03:51 PM
Basic EA template trevman Metatrader 4 8 07-07-2007 07:10 AM
MT4 (Basic) Questions stepwise Metatrader 4 2 05-21-2007 04:03 PM
channel breakout basic yossi1177 Expert Advisors - Metatrader 4 6 03-04-2007 11:24 AM


All times are GMT. The time now is 10:17 PM.