how can i put functions into ordersend ?

 

can i do something like this : or do i have to set the takeprofit to 0 then use mondify orders to check for profit then insert them in ?

int start()  { 
int ema =     iMA(Symbol(),PERIOD_D1,13,0,MODE_SMMA,PRICE_CLOSE,0);
int ema2 =     iMA(Symbol(),PERIOD_D1,50,0,MODE_SMMA,PRICE_CLOSE,0);
int i = 0;
//calculate  for takeprofit
int check( int a, int b)
{
if (ema< ema2 )
{  
OrderSend(NULL,OP_SELL,lot, Bid,3,0,0);
a = 1
}

// buy then look for sell order from above
if ( em2< Close[i] && ema > Close[i] )
{
OrderSend(NULL,OP_BUY,lot,Ask,3,Bid-50*Point, a /*try to put the above cumstom function into the takeprofit*/ );}      
return(0);
 

You can use a custom function in orderSend but it has to return a value. The function needs to be outside of the start(){}.

 
jmca wrote >>

You can use a custom function in orderSend but it has to return a value. The function needs to be outside of the start(){}.

can you give me an example ? if i move my check() function out of start() it would say variable not defined for ema and ema2 inside the start()

//calculate  for takeprofit
int check( int a, int b)
{
if (ema< ema2 )
{  
OrderSend(NULL,OP_SELL,lot, Bid,3,0,0);
a = 1;
}

int start()  { 
int ema =     iMA(Symbol(),PERIOD_D1,13,0,MODE_SMMA,PRICE_CLOSE,0);
int ema2 =     iMA(Symbol(),PERIOD_D1,50,0,MODE_SMMA,PRICE_CLOSE,0);
int i = 0;
// buy then look for sell order from above
if ( em2< Close[i] && ema > Close[i] )
{
OrderSend(NULL,OP_BUY,lot,Ask,3,Bid-50*Point, a /*try to put the above cumstom function into the takeprofit*/ );}      
return(0);
 

ema and ema2 supposed to be double, not int.

 
the problem is not that either int or double, is that if i move ema and ema2 out of a function that function will not work
 

put ema,ema2 declarations at source file global scope = outside ANY function.

eg:

int ema;

int ema2;

int start() {
ema = iMA(Symbol(),PERIOD_D1,13,0,MODE_SMMA,PRICE_CLOSE,0);

ema2 = iMA(Symbol(),PERIOD_D1,50,0,MODE_SMMA,PRICE_CLOSE,0);

that will satisfy check() references of ema,ema2

and please do take note, as Roger stated, iMA() is type double and if you assign double --> int, value is truncated so that the decimal part of iMA() return()'d value is lost

then when you compare with Close[] the results will be not how you imagined ...

btw, have you read the MQL4 Programming Book?

 
thank you fbj, I found an ea similar to what i want to be done for my ea, to your question about the book : yes i did read the book but not clear everything it said inside thats why i need help
 
good you found what needed. yes, we all need help at times and I not implying that just because one reads 'the book' that all is a-ok, far from it... I for one seem to be always dueling with MT but it does get such that I generally win (so I'd like to think ;)