Forex



Go Back   Forex Trading > Downloads > Expert Advisors - Metatrader 4
Forex Forum Register More recent Blogs Calendar Advertising Others Help






Register
Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.

From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.

Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
  • Elite Section
    Get access to private discussions, specialized support, indicators and trading systems reported every week.
  • Advanced Elite Section
    For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
See more

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 09-09-2008, 06:52 PM
MKRoxton's Avatar
Member
 
Join Date: Aug 2008
Location: Germany
Posts: 71
MKRoxton is on a distinguished road
Thumbs up How I can made a Expert Advisor of a Indicator?

Can One say me, how I can made of a Indicator a Expert Advisor (EA)?
For example on the Slope Direction Line.
When the Slope Direction Line change the colour of green to red (see Picture) then the Expert Advisor shall make a SELL-Order.
When now the colour once more become green, then closed the SELL-Order and make a new BUY-Order.
The BUY-Order shall closed when red comes again, and a new SELL-Order start now…

I hope One here can help me!

Thank you for read this message!


Here is the Code of the Indicator:


#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 LightBlue
#property indicator_color2 Tomato
//---- input parameters
extern int period=80;
extern int method=3; // MODE_SMA
extern int price=0; // PRICE_CLOSE
//---- buffers
double Uptrend[];
double Dntrend[];
double ExtMapBuffer[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(3);
SetIndexBuffer(0, Uptrend);
//ArraySetAsSeries(Uptrend, true);
SetIndexBuffer(1, Dntrend);
//ArraySetAsSeries(Dntrend, true);
SetIndexBuffer(2, ExtMapBuffer);
ArraySetAsSeries(ExtMapBuffer, true);

SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);

IndicatorShortName("Slope Direction Line("+period+")");
return(0);
}

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

//+------------------------------------------------------------------+
//| ?????????? ??????? |
//+------------------------------------------------------------------+
double WMA(int x, int p)
{
return(iMA(NULL, 0, p, 0, method, price, x));
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars = IndicatorCounted();

if(counted_bars < 0)
return(-1);

int x = 0;
int p = MathSqrt(period);
int e = Bars - counted_bars + period + 1;

double vect[], trend[];

if(e > Bars)
e = Bars;

ArrayResize(vect, e);
ArraySetAsSeries(vect, true);
ArrayResize(trend, e);
ArraySetAsSeries(trend, true);

for(x = 0; x < e; x++)
{
vect[x] = 2*WMA(x, period/2) - WMA(x, period);
// Print("Bar date/time: ", TimeToStr(Time[x]), " close: ", Close[x], " vect[", x, "] = ", vect[x], " 2*WMA(p/2) = ", 2*WMA(x, period/2), " WMA(p) = ", WMA(x, period));
}

for(x = 0; x < e-period; x++)

ExtMapBuffer[x] = iMAOnArray(vect, 0, p, 0, method, x);

for(x = e-period; x >= 0; x--)
{
trend[x] = trend[x+1];
if (ExtMapBuffer[x]> ExtMapBuffer[x+1]) trend[x] =1;
if (ExtMapBuffer[x]< ExtMapBuffer[x+1]) trend[x] =-1;

if (trend[x]>0)
{ Uptrend[x] = ExtMapBuffer[x];
if (trend[x+1]<0) Uptrend[x+1]=ExtMapBuffer[x+1];
Dntrend[x] = EMPTY_VALUE;
}
else
if (trend[x]<0)
{
Dntrend[x] = ExtMapBuffer[x];
if (trend[x+1]>0) Dntrend[x+1]=ExtMapBuffer[x+1];
Uptrend[x] = EMPTY_VALUE;
}

//Print( " trend=",trend[x]);
}

return(0);
}
Attached Images
File Type: jpg capture_09092008_191556 [150%].jpg (93.5 KB, 1154 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #2 (permalink)  
Old 09-09-2008, 07:38 PM
zupcon's Avatar
Senior Member
 
Join Date: Dec 2005
Location: Malta
Posts: 266
zupcon is on a distinguished road
The best option is probably to take a look at modifying the MACD sample EA that metatrader provides.

Alternatively you could take a look at one of the code generation tools available such as Forex Software - Gordago although in my experience you'll still need to code for these tools to be of any use.

You might get lucky and someone who's trying to learn MQL might just take a look. To get a good coder interested it helps if you can convince them that the method is something worth taking a look at, such as results from a hand back test, or results from a live forward test
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #3 (permalink)  
Old 09-09-2008, 11:22 PM
Junior Member
 
Join Date: Aug 2007
Posts: 9
dim13 is on a distinguished road
How about using the iCustom function.

sngSlope0 = NormalizeDouble(iCustom(NULL, 0, "Slope Direction Line", 80, 3, 0, 0, 0), 4);
sngSlope1 = NormalizeDouble(iCustom(NULL, 0, "Slope Direction Line", 80, 3, 0, 1, 0), 4);

if (sngSlope1>=sngSlope0) {
// Long
}
else {
// Short
}

If you have the .mq4 code for the indicator, you can use the iCustom function. I'm assuming "Slope Direction Line.mq4" is the name of the indicator you are using.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #4 (permalink)  
Old 09-10-2008, 06:21 AM
Senior Member
 
Join Date: Oct 2007
Posts: 230
Dave137 is on a distinguished road
Thumbs down

Hate to pop your idea, but the direction line repaints radically and is unstable to use in an ea (Too many false signals!).

Dave
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #5 (permalink)  
Old 09-11-2008, 05:57 PM
MKRoxton's Avatar
Member
 
Join Date: Aug 2008
Location: Germany
Posts: 71
MKRoxton is on a distinguished road
Who can write simple MQL4-Code?

Can One say me, how I can made of a Indicator a Expert Advisor (EA)?
For example on the Slope Direction Line.
When the Slope Direction Line change the colour of green to red (see Picture) then the Expert Advisor shall make a SELL-Order.
When now the colour once more become green, then closed the SELL-Order and make a new BUY-Order.
The BUY-Order shall closed when red comes again, and a new SELL-Order start now…

I hope One here can help me!

Thank you for read this message!



Here is the Picture: (capture_09092008_191556 [150%].jpg)

Here is the Code of the Indicator:






#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 LightBlue
#property indicator_color2 Tomato
//---- input parameters
extern int period=80;
extern int method=3; // MODE_SMA
extern int price=0; // PRICE_CLOSE
//---- buffers
double Uptrend[];
double Dntrend[];
double ExtMapBuffer[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(3);
SetIndexBuffer(0, Uptrend);
//ArraySetAsSeries(Uptrend, true);
SetIndexBuffer(1, Dntrend);
//ArraySetAsSeries(Dntrend, true);
SetIndexBuffer(2, ExtMapBuffer);
ArraySetAsSeries(ExtMapBuffer, true);

SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);

IndicatorShortName("Slope Direction Line("+period+")");
return(0);
}

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

//+------------------------------------------------------------------+
//| ?????????? ??????? |
//+------------------------------------------------------------------+
double WMA(int x, int p)
{
return(iMA(NULL, 0, p, 0, method, price, x));
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars = IndicatorCounted();

if(counted_bars < 0)
return(-1);

int x = 0;
int p = MathSqrt(period);
int e = Bars - counted_bars + period + 1;

double vect[], trend[];

if(e > Bars)
e = Bars;

ArrayResize(vect, e);
ArraySetAsSeries(vect, true);
ArrayResize(trend, e);
ArraySetAsSeries(trend, true);

for(x = 0; x < e; x++)
{
vect[x] = 2*WMA(x, period/2) - WMA(x, period);
// Print("Bar date/time: ", TimeToStr(Time[x]), " close: ", Close[x], " vect[", x, "] = ", vect[x], " 2*WMA(p/2) = ", 2*WMA(x, period/2), " WMA(p) = ", WMA(x, period));
}

for(x = 0; x < e-period; x++)

ExtMapBuffer[x] = iMAOnArray(vect, 0, p, 0, method, x);

for(x = e-period; x >= 0; x--)
{
trend[x] = trend[x+1];
if (ExtMapBuffer[x]> ExtMapBuffer[x+1]) trend[x] =1;
if (ExtMapBuffer[x]< ExtMapBuffer[x+1]) trend[x] =-1;

if (trend[x]>0)
{ Uptrend[x] = ExtMapBuffer[x];
if (trend[x+1]<0) Uptrend[x+1]=ExtMapBuffer[x+1];
Dntrend[x] = EMPTY_VALUE;
}
else
if (trend[x]<0)
{
Dntrend[x] = ExtMapBuffer[x];
if (trend[x+1]>0) Dntrend[x+1]=ExtMapBuffer[x+1];
Uptrend[x] = EMPTY_VALUE;
}

//Print( " trend=",trend[x]);
}

return(0);
}







ANSWERS ARE:

sngSlope0 = NormalizeDouble(iCustom(NULL, 0, "Slope Direction Line", 80, 3, 0, 0, 0), 4);
sngSlope1 = NormalizeDouble(iCustom(NULL, 0, "Slope Direction Line", 80, 3, 0, 1, 0), 4);

if (sngSlope1>=sngSlope0) {
// Long
}
else {
// Short
}


2nd Writing:

Hi!
I'am a totally beginner of MQL4 programming.
I don’t understand how I can made a Expert Advisor with Sell & Buy Signals
of Line Colored.
For example on the Slope Direction Line.
When the Slope Direction Line change the colour of green to red (see Picture) then the Expert Advisor shall make a SELL-Order.
When now the colour once more become green, then closed the SELL-Order and make a new BUY-Order.
The BUY-Order shall closed when red comes again, and a new SELL-Order start now…

I hope One here can help me!

Thank you for read this message!


Here is the Code of the Indicator:

--------------------------------------------------------------------------

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 LightBlue
#property indicator_color2 Tomato
//---- input parameters
extern int period=80;
extern int method=3; // MODE_SMA
extern int price=0; // PRICE_CLOSE
//---- buffers
double Uptrend[];
double Dntrend[];
double ExtMapBuffer[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(3);
SetIndexBuffer(0, Uptrend);
//ArraySetAsSeries(Uptrend, true);
SetIndexBuffer(1, Dntrend);
//ArraySetAsSeries(Dntrend, true);
SetIndexBuffer(2, ExtMapBuffer);
ArraySetAsSeries(ExtMapBuffer, true);

SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);

IndicatorShortName("Slope Direction Line("+period+")");
return(0);
}

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

//+------------------------------------------------------------------+
//| ?????????? ??????? |
//+------------------------------------------------------------------+
double WMA(int x, int p)
{
return(iMA(NULL, 0, p, 0, method, price, x));
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars = IndicatorCounted();

if(counted_bars < 0)
return(-1);

int x = 0;
int p = MathSqrt(period);
int e = Bars - counted_bars + period + 1;

double vect[], trend[];

if(e > Bars)
e = Bars;

ArrayResize(vect, e);
ArraySetAsSeries(vect, true);
ArrayResize(trend, e);
ArraySetAsSeries(trend, true);

for(x = 0; x < e; x++)
{
vect[x] = 2*WMA(x, period/2) - WMA(x, period);
// Print("Bar date/time: ", TimeToStr(Time[x]), " close: ", Close[x], " vect[", x, "] = ", vect[x], " 2*WMA(p/2) = ", 2*WMA(x, period/2), " WMA(p) = ", WMA(x, period));
}

for(x = 0; x < e-period; x++)

ExtMapBuffer[x] = iMAOnArray(vect, 0, p, 0, method, x);

for(x = e-period; x >= 0; x--)
{
trend[x] = trend[x+1];
if (ExtMapBuffer[x]> ExtMapBuffer[x+1]) trend[x] =1;
if (ExtMapBuffer[x]< ExtMapBuffer[x+1]) trend[x] =-1;

if (trend[x]>0)
{ Uptrend[x] = ExtMapBuffer[x];
if (trend[x+1]<0) Uptrend[x+1]=ExtMapBuffer[x+1];
Dntrend[x] = EMPTY_VALUE;
}
else
if (trend[x]<0)
{
Dntrend[x] = ExtMapBuffer[x];
if (trend[x+1]>0) Dntrend[x+1]=ExtMapBuffer[x+1];
Uptrend[x] = EMPTY_VALUE;
}

//Print( " trend=",trend[x]);
}

return(0);
}

--------------------------------------------------------------------------

I have to attempt insert this code but the Expert Advisor don`t start!

sngSlope0 = NormalizeDouble(iCustom(NULL, 0, "Slope Direction Line", 80, 3, 0, 0, 0), 4);
sngSlope1 = NormalizeDouble(iCustom(NULL, 0, "Slope Direction Line", 80, 3, 0, 1, 0), 4);

if (sngSlope1>=sngSlope0) {
// Long
}
else {
// Short
}

Have One here qualities in MQL4 programming and can help me this EA to program?
Attached Images
File Type: jpg capture_09092008_191556 [150%].jpg (93.5 KB, 1060 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #6 (permalink)  
Old 09-12-2008, 04:02 PM
Junior Member
 
Join Date: Aug 2007
Posts: 9
dim13 is on a distinguished road
Quote:
Originally Posted by The Rock View Post
--------------------------------------------------------------------------

I have to attempt insert this code but the Expert Advisor don`t start!

sngSlope0 = NormalizeDouble(iCustom(NULL, 0, "Slope Direction Line", 80, 3, 0, 0, 0), 4);
sngSlope1 = NormalizeDouble(iCustom(NULL, 0, "Slope Direction Line", 80, 3, 0, 1, 0), 4);

if (sngSlope1>=sngSlope0) {
// Long
}
else {
// Short
}

Have One here qualities in MQL4 programming and can help me this EA to program?
// Long - means place your Buy routine here. The "//" are comments.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #7 (permalink)  
Old 09-13-2008, 06:54 PM
Member
 
Join Date: Jul 2008
Posts: 43
latimeria is on a distinguished road
Hi everyone.

I have made this EA. It works.

I have not analyzed the Indicator well, but it is maybe a kind of <Heiken Ashi> or something.

Type of Trading System is like MA cross reverse entry.
It means You always have buy or sell position.

note:
1. You need Custom Indicator named "Slope Direction Line" ,of course.
2. This EA uses previous bar to judge if Trend has changed.
So it doesn't use "Future" Indicator value.
3. I added "TradeSwitch" function on this EA.
You can turn off Buy or Sell Order.
4. I added "Fake Position Sizing" function on this EA.
This algorithm decides lot size by volatility(ATR).
But remember This EA doesn't set any stoploss.
So you can't limit loss to be exact.
That's why I call it "Fake".
You can turn off the function if you don't want.
5. I recommend D1 timeframe to use this EA.
6. Don't use this EA on real money.
It will need many improvements.

enjoy.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #8 (permalink)  
Old 09-13-2008, 07:00 PM
Member
 
Join Date: Jul 2008
Posts: 43
latimeria is on a distinguished road
Sorry , I forget to attach mq4 file.
Attached Files
File Type: mq4 SlopeDirectionLine_EA.mq4 (8.4 KB, 292 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #9 (permalink)  
Old 09-13-2008, 10:44 PM
faizfakhirin's Avatar
Member
 
Join Date: Dec 2007
Posts: 32
faizfakhirin is on a distinguished road
is it has the ebook how to build EA?
__________________
Forex Technical Analysis :
http://bankami.blogspot.com
Forex Indicators :
http://indicators-forex.blogspot.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #10 (permalink)  
Old 09-14-2008, 12:04 AM
Member
 
Join Date: Jul 2008
Posts: 43
latimeria is on a distinguished road
I have added some codes to indicate current entry price on the right side (for more fun).

System Logic itself has not changed at all.

additional note:
This EA open and close trade only at the bar opening.
So you can backtest this EA by Open Price Only.

Last edited by latimeria; 09-23-2008 at 10:58 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
Reply

Bookmarks

Tags
slope direction line expert advisor, SlopeDirectionLine_v3, TrendEnvelopes_v2, slope direction, slope direction line, expert advisor, slope direction line ea, forex


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create Expert Advisor for this wonderful indicator torreseemee Setup Questions 3 07-24-2008 07:37 AM
How to make an expert advisor run other expert advisors in MQL4 activetc Metatrader 4 0 08-30-2007 05:29 AM
How to stop expert advisor from trading, when profit is made joko75 Expert Advisors - Metatrader 4 9 05-27-2007 01:16 PM
Need an indicator made hidethereal Indicators - Metatrader 4 12 09-28-2006 07:10 PM


All times are GMT. The time now is 05:54 AM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.