Forex
Google

Go Back   Forex Trading > Metatrader Training > Metatrader 4 mql 4 - Development course > Questions
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 02-13-2006, 06:34 PM
demag demag is offline
Junior Member
 
Join Date: Jan 2006
Location: Middle Earth, UK.
Posts: 25
demag is on a distinguished road
Another question, sorry.

Hi, I think I've messed up here somewhere!

'static' - semicolon expected C:\PROGRAM FILES\METATRADER 4\experts\My_First_EA.mq4 (42, 7)

Also,

'First_time' - variable not defined C:\PROGRAM FILES\METATRADER 4\experts\My_First_EA.mq4 (50, 7)

I tried over the weekend to sort this out but went from two errors to nine! Not sure if I've got the code jumbled up somewhere. I got a bit lost in the middle of it all!

Thanks for any help.

demag.







//+------------------------------------------------------------------+
//| 5 Minute Scalper My_First_EA.mq4 |
//| Coders Guru |
//| http://www.forex-tsd.com |
//+------------------------------------------------------------------+
#property copyright "Coders Guru"
#property link "http://www.forex-tsd.com"

//---- input parameters
extern double TakeProfit=8.0;
extern double Lots=0.1;
extern double TrailingStop=10.0;
extern double StopLoss=-15.0;
extern bool UseStopLoss=true;

extern int ShortEma = 3;
extern int LongEma = 7;
extern int LongSma = 25;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

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

//----
return(0);
}

int Crossed (double line1 , double line2 , double line3)

static int last_direction = 0;
static int current_direction = 0;


// Don't work in the first load, wait for first cross!
static bool first_time = true;
if(first_time == true)
{
First_time == false;
return (0);
}
{


if(line1>line2>line3)current_direction = 1; //up
if(line1<line2<line3)current_direction = 2; //down

if(current_direction != last_direction) //changed
{
last_direction = current_direction;
return (last_direction);
}
else
{
return (0);
}
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----


int cnt, ticket, total;
double shortEma, longEma, longSma;


if(Bars<100)
{
Print("bars less than 100");
return(0);
}
if(TakeProfit<1)
{
Print("TakeProfit less than 1");
return(0); // check TakeProfit
}


shortEma = iMA(NULL,0,3,0,MODE_EMA,PRICE_CLOSE,0);
longEma = iMA(NULL,0,7,0,MODE_EMA,PRICE_CLOSE,0);
longSma = iMA (NULL,0,25,0,MODE_SMA,PRICE_CLOSE,0);

int isCrossed = Crossed (shortEma,longEma,longSma);

total = OrdersTotal();
if(total < 1)
{
if(isCrossed == 1)
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+ TakeProfit*Point,"My EA",12345,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES )) Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());
return(0);
}
if(isCrossed == 2)

// Delay action by "x" bars


{

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,"My EA",12345,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES )) Print("SELL order opened : ",OrderOpenPrice());
}
else Print("Error opening SELL order : ",GetLastError());
return(0);
}
return(0);
}
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY) // long position is opened
{
// should it be closed?
if(isCrossed == 2)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet) ; // close position
return(0); // exit
}
// check for trailing stop
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
return(0);
}
}
}
}
else // go to short position
{
// should it be closed?
if(isCrossed == 1)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet) ; // close position
return(0); // exit
}
// check for trailing stop
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Poi nt*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
}
}
return(0);
}
//+------------------------------------------------------------------+
__________________
demag
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
Question About EAs mikejody Tools and utilities 2 05-25-2007 11:59 PM
question evgeni1980 Questions 4 11-27-2006 01:32 PM
EA question yaniv_av Expert Advisors - Metatrader 4 1 11-14-2006 12:10 PM


All times are GMT. The time now is 01:44 PM.