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.
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?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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 ?