Forex
Google
New signals service!

Go Back   Forex Trading > Metatrader Training > Metatrader 4 mql 4 - Development course > Questions


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 11-06-2005, 09:40 PM
Administrator
 
Join Date: Sep 2005
Posts: 15,947
Blog Entries: 64
newdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud of
Templates to create EAs and Indicators

Coders' Guru,

I want to ask:
May we have some templates to create Custom indicators and EAs?
It will be easy for us to start.
Later on we will have our own practics to create it and our own experience.
But the templates will help us from the beginning.

For example I found in internet some template of EA. May be it is not right template and everything is possible to program in easier way ... May be I do not know.
But it is the template I found:

Code:
#define MAGIC 10653
#include 
#include 

extern double lStopLoss = 50; //Stop Loss for BUY
extern double sStopLoss = 50; //Stop Loss for SELL
extern double lTakeProfit = 100; //Take Profit for BUY
extern double sTakeProfit = 100; //Take Profit SELL
extern double lTrailingStop = 15; //Trailing Stop for BUY
extern double sTrailingStop = 15; //Trailing Stop for SELL
extern color clOpenBuy = Blue; //Color for BUY order
extern color clCloseBuy = Aqua; //Color for BUY exit
extern color clModiBuy = Blue; //Modofication Color BUY
extern color clOpenSell = Red; //Color to open SELL
extern color clCloseSell = Violet; //Color SELL exit
extern color clModiSell = Red; //Color to open SELL
extern string Name_Expert = “ ……..”;
extern int Slippage = 3; //…..
extern bool ProfitTrailing = True; // Profit Trailing
extern int TrailingStop = 8; // 
extern int TrailingStep = 2; // 
extern bool UseSound = True; // 
extern string NameFileSound = "alert.wav"; // 
extern double Lots = 0.1;
extern bool UseHourTrade = True; // 
extern int FromHourTrade = 0; // 
extern int ToHourTrade = 23; // 
extern double mm = -1;
extern double Risk = 10;
int prevCountBars;

void deinit() {
Comment("");
}
//+-----------------------------------------------------------+
//| |
//+-----------------------------------------------------------+
int start(){
for (int i=0; i
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
TrailingPositions();
}
}
if (UseHourTrade){
if (!(Hour()>=FromHourTrade && Hour()<=ToHourTrade)) {
Comment(“Non-Trading hours!”);
return(0);
}
}

if(Bars<100){
Print("bars less than 100");
return(0);
}
if(lStopLoss<10){
Print("StopLoss less than 10");
return(0);
}
if(lTakeProfit<10){
Print("TakeProfit less than 10");
return(0);
}
if(sStopLoss<10){
Print("StopLoss less than 10");
return(0);
}
if(sTakeProfit<10){
Print("TakeProfit less than 10");
return(0);
}



double diOpen0=iOpen(NULL,0,1);
double diHigh0=iHigh(NULL,0,1);
double diLow0=iLow(NULL,0,1);
double diClose0=iClose(NULL,0,1);

double diOpen1=iOpen(NULL,0,2);
double diHigh1=iHigh(NULL,0,2);
double diLow1=iLow(NULL,0,2);
double diClose1=iClose(NULL,0,2);

double Median=((iHigh(NULL,0,1)+iLow(NULL,0,1))/2);
double Typical=((iHigh(NULL,0,0)+iLow(NULL,0,0)+iClose(NULL,0,0))/3);
double Weighted=((iHigh(NULL,0,0)+iLow(NULL,0,0)+iClose(NULL,0,0)+iClose(NULL,0,0))/4);
double diVolume=iVolume(NULL,0,0);


if (prevCountBars != Bars && prevCountBars !=0 && !ExistPositions()) {
if(AccountFreeMargin()<(1000*Lots)){
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}

if ((.........)){
OpenBuy();
return(0);
}

if ((.........)){
OpenSell();
return(0);
}

}
if (prevCountBars != Bars && prevCountBars !=0 && ExistPositions()) {
if(OrderType()==OP_BUY){

if ((valueh<0 && valuel1>0)) {
CloseBuy();
return(0);
}
}
if(OrderType()==OP_SELL){

if ((valuel>0 && valueh1<0)) {
CloseSell();
return(0);
}
}
}
TrailingPositions();
prevCountBars = Bars;
return (0);
}

bool ExistPositions() {
for (int i=0; i
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC) {
return(True);
}
} 
} 
return(false);
}
void TrailingPositions() {
double pBid, pAsk, pp;

pp = MarketInfo(OrderSymbol(), MODE_POINT);
if (OrderType()==OP_BUY) {
pBid = MarketInfo(OrderSymbol(), MODE_BID);
if (!ProfitTrailing || (pBid-OrderOpenPrice())>TrailingStop*pp) {
if (OrderStopLoss()
ModifyStopLoss(pBid-TrailingStop*pp);
return;
}
}
}
if (OrderType()==OP_SELL) {
pAsk = MarketInfo(OrderSymbol(), MODE_ASK);
if (!ProfitTrailing || OrderOpenPrice()-pAsk>TrailingStop*pp) {
if (OrderStopLoss()>pAsk+(TrailingStop+TrailingStep-1)*pp || OrderStopLoss()==0) {
ModifyStopLoss(pAsk+TrailingStop*pp);
return;
}
}
}
}

//+------------------------------------------------------------------+
//| StopLoss Modifying|
//| Parameters: |
//| ldStopLoss – StopLoss level |
//+------------------------------------------------------------------+
void ModifyStopLoss(double ldStopLoss) {
bool fm;

fm=OrderModify(OrderTicket(),OrderOpenPrice(),ldStopLoss,OrderTakeProfit(),0,CLR_NONE);
if (fm && UseSound) PlaySound(NameFileSound);
}
//+------------------------------------------------------------------+

void CloseBuy() { 
bool fc; 
fc=OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, clCloseBuy); 
if (fc && UseSound) PlaySound(NameFileSound); 
} 
void CloseSell() { 
bool fc; 
fc=OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, clCloseSell); 
if (fc && UseSound) PlaySound(NameFileSound); 
} 
void OpenBuy() { 
double ldLot, ldStop, ldTake; 
string lsComm; 
double b=0;
double balance=0;
double Ilo=0;
balance=AccountBalance();

if (mm < 0) {
Ilo = MathCeil(balance*Risk/10000)/10;
if (Ilo > 100) { 
Ilo = 100; 
}
} else {
Ilo = Lots;
}
if (mm > 0)
{
Ilo = MathCeil(balance*Risk/10000)/10;
if (Ilo > 1) 
{
Ilo = MathCeil(Ilo);
}
if (Ilo < 1)
{
Ilo = 1;
}
if (Ilo > 100) 
{ 
Ilo = 100; 
}
}
ldLot = GetSizeLot(); 
ldStop = GetStopLossBuy(); 
ldTake = GetTakeProfitBuy(); 
lsComm = GetCommentForOrder(); 
//OrderSend(Symbol(),OP_BUY,ldLot,Ask,Slippage,0,0,lsComm,MAGIC,0,clOpenBuy); 
//OrderSend(Symbol(),OP_BUY,Ilo,Ask,Slippage,ldStop,ldTake,lsComm,MAGIC,0,clOpenBuy); 
OrderSend(Symbol(),OP_BUY,ldLot,Ask,Slippage,ldStop,ldTake,lsComm,MAGIC,0,clOpenBuy); 
if (UseSound) PlaySound(NameFileSound); 
} 
void OpenSell() { 
double ldLot, ldStop, ldTake; 
string lsComm; 
double b=0;
double balance=0;
double Ilo=0;
balance=AccountBalance();

if (mm < 0) {
Ilo = MathCeil(balance*Risk/10000)/10;
if (Ilo > 100) { 
Ilo = 100; 
}
} else {
Ilo = Lots;
}
if (mm > 0)
{
Ilo = MathCeil(balance*Risk/10000)/10;
if (Ilo > 1) 
{
Ilo = MathCeil(Ilo);
}
if (Ilo < 1)
{
Ilo = 1;
}
if (Ilo > 100) 
{ 
Ilo = 100; 
}
}
ldLot = GetSizeLot(); 
ldStop = GetStopLossSell(); 
ldTake = GetTakeProfitSell(); 
lsComm = GetCommentForOrder(); 
//OrderSend(Symbol(),OP_SELL,ldLot,Bid,Slippage,0,0,lsComm,MAGIC,0,clOpenSell); 
//OrderSend(Symbol(),OP_SELL,Ilo,Bid,Slippage,ldStop,ldTake,lsComm,MAGIC,0,clOpenSell); OrderSend(Symbol(),OP_SELL,ldLot,Bid,Slippage,ldStop,ldTake,lsComm,MAGIC,0,clOpenSell); 
if (UseSound) PlaySound(NameFileSound); 
} 
string GetCommentForOrder() { return(Name_Expert); } 
double GetSizeLot() { return(Lots); } 
double GetStopLossBuy() { return (Bid-lStopLoss*Point);} 
double GetStopLossSell() { return(Ask+sStopLoss*Point); } 
double GetTakeProfitBuy() { return(Ask+lTakeProfit*Point); } 
double GetTakeProfitSell() { return(Bid-sTakeProfit*Point); }
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 11-06-2005, 09:46 PM
Administrator
 
Join Date: Sep 2005
Posts: 15,947
Blog Entries: 64
newdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud of
More useful pieces of the code

And an other suggestion.
May you create some thread in the end of the main part of our lessons or any time: most useful pieces of the code?

Some people started to ask the question about some pieces of the code already Basic questions ...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 11-06-2005, 10:33 PM
codersguru's Avatar
Senior Member
 
Join Date: Oct 2005
Posts: 987
codersguru has a spectacular aura aboutcodersguru has a spectacular aura aboutcodersguru has a spectacular aura about
Arrow New thread has been created.

Quote:
Originally Posted by newdigital
And an other suggestion.
May you create some thread in the end of the main part of our lessons or any time: most useful pieces of the code?

Some people started to ask the question about some pieces of the code already Basic questions ...
Thanks newdigital!

I've just created the new thread.
Ask!
__________________
Hope it helps !
Coders' Guru
Senior MQL programmer:
www.xpworx.com/custom.htm
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 11-07-2005, 12:07 PM
Junior Member
 
Join Date: Oct 2005
Posts: 14
quksilver is on a distinguished road
Actually, templates are a part of the MQL4 language. If you properly construct a template file, you can use the New EA Wizard to create an EA using that template. I haven't actually done it yet, but it's been rolling around my head for a while. Maybe it could be another lesson?

-lcg
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 11-07-2005, 01:28 PM
codersguru's Avatar
Senior Member
 
Join Date: Oct 2005
Posts: 987
codersguru has a spectacular aura aboutcodersguru has a spectacular aura aboutcodersguru has a spectacular aura about
Arrow Sure

Quote:
Originally Posted by quksilver
Actually, templates are a part of the MQL4 language. If you properly construct a template file, you can use the New EA Wizard to create an EA using that template. I haven't actually done it yet, but it's been rolling around my head for a while. Maybe it could be another lesson?

-lcg

Hi quksilver,

Templates are very important part of MQL4 and it will be detailed in a coming lesson. But I can't talk about templates before creating basic Custom Indicators & Expert Advisors.

Thanks for the suggestion.
__________________
Hope it helps !
Coders' Guru
Senior MQL programmer:
www.xpworx.com/custom.htm
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 11-08-2005, 11:28 AM
Senior Member
 
Join Date: Oct 2005
Location: Porto/Portugal
Posts: 257
hellkas is on a distinguished road
hi all


CodersGuru

Could you make one template for one indicator? And two?

tkx
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 11-08-2005, 11:41 AM
Administrator
 
Join Date: Sep 2005
Posts: 15,947
Blog Entries: 64
newdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud of
When I asked about template I was thinking that we should have the code of EA and indicator but codes only, with everything and all that we need just delete unnecessary lines from the code. Template is not right word for it may be.

Let's finish the indicator's lessons first. And EA's lessons.
And then we may create the templates for ourself.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 11-08-2005, 03:22 PM
codersguru's Avatar
Senior Member
 
Join Date: Oct 2005
Posts: 987
codersguru has a spectacular aura aboutcodersguru has a spectacular aura aboutcodersguru has a spectacular aura about
Thumbs up Templates in the way to you!

Quote:
Originally Posted by newdigital
Let's finish the indicator's lessons first. And EA's lessons.
And then we may create the templates for ourself.
You are right. We are going to know more about templates after finishing the indicators & EA's lessons
__________________
Hope it helps !
Coders' Guru
Senior MQL programmer:
www.xpworx.com/custom.htm

Last edited by codersguru; 11-09-2005 at 03:53 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 12-14-2005, 09:41 AM
Administrator
 
Join Date: Sep 2005
Posts: 15,947
Blog Entries: 64
newdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud of
Expert templates (templates to create EA) which I have inside my computer:

- Expert Template for MT 4.mq4 (comments in Russian) and Expert Template english.mq4 (with comments in English;

- Expert Template add-on.mq4 (almost everything).

I am keeping it in samples/ExpertSample folder and open sometimes in MetaEditor of I need to create something.
Attached Files
File Type: mq4 Expert Template for MT 4.mq4 (15.3 KB, 428 views)
File Type: mq4 Expert Template english.mq4 (15.4 KB, 747 views)
File Type: mq4 Expert Template add-on.mq4 (6.6 KB, 598 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 01-17-2006, 04:20 AM
jpsdyb's Avatar
Member
 
Join Date: Dec 2005
Posts: 73
jpsdyb is on a distinguished road
are comments or instructions like //post your comment or instruction here
allowed to be posted further down the script to give us instruction on what we can change, why and what it does? Would be more helpful in creating expert. Make sense?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

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 On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Lesson 18 - Working with templates codersguru Metatrader 4 mql 4 - Development course 13 08-03-2008 01:39 AM
EA Templates xxDavidxSxx Expert Advisors - Metatrader 4 15 01-29-2008 12:38 PM
Profitunity Templates....... Qbert006 Indicators - Metatrader 4 2 03-06-2006 07:33 PM


All times are GMT. The time now is 10:14 AM.



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