y * Point
TakeProfit_Buy[i]=(iMA(NULL,0,15,0,MODE_EMA,PRICE_CLOSE,i)*Point)-(Ask*Point); TakeProfit_Sell[i]=(Bid*Point)-(iMA(NULL,0,15,0,MODE_EMA,PRICE_CLOSE,i)*Point);
Besides
u don't need to loop + using array
jost simple
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,iMA(NULL,0,15,0,MODE_EMA,PRICE_CLOSE,0),"Rodrigo Especulação",0002,0,Red);
y * Point
also
y not
qjol, sorry, but I didn't understand what you are trying to say.
i said why you using by this lines *Point.
TakeProfit_Buy[i]=(iMA(NULL,0,15,0,MODE_EMA,PRICE_CLOSE,i)*Point)-(Ask*Point); TakeProfit_Sell[i]=(Bid*Point)-(iMA(NULL,0,15,0,MODE_EMA,PRICE_CLOSE,i)*Point);
and why looping and use an array at all you can simple use OrderSend() like this
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,iMA(NULL,0,15,0,MODE_EMA,PRICE_CLOSE,0),"Rodrigo Especulação",0002,0,Red);
Great, you are absolutely right.
I'm beginner, I'm not a programmer. So I have a lot of questions about programming, and it results in bugs that I don´t know how to solve. But, fortunately, some guys like you has been helping me to learn faster.
Thanks again.
i said why you using by this lines *Point.
and why looping and use an array at all you can simple use OrderSend() like this
There is a problem.... It isn't doing the looping. The take profit is static at the point where were my moving average when the buy or sell event happened.
I need a recalculation for the iMA value.
There is a problem.... It isn't doing the looping. The take profit is static at the point where were my moving average when the buy or sell event happened.
I need a recalculation for the iMA value.
You want to move your TP when MA changes value? In such case you need to use OrderModify function.
I still with this problem.... I changed this part of code, but the take profit still static.
//---- Check for an exit ----// for(cnt=0;cnt<total;cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if(OrderType()<=OP_SELL && // check for opened position OrderSymbol()==Symbol()) // check for symbol { if(OrderType()==OP_BUY) // long position is opened { // should it be closed? if(Bid>=TakeProfit) { OrderModify(OrderTicket(),OrderOpenPrice(),0,TakeProfit,0,Red); // new close position which recalculate the TakeProfit based on MA //OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position ---- I took out this part return(0); // exit } } } }
//---- Check for an exit ----// void CheckForClose() { double TakeProfit = iMA(NULL,0,15,0,MODE_EMA,PRICE_CLOSE,0); //----- for(int cnt=0; cnt < OrdersTotal(); cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if(OrderType()<=OP_SELL && // check for opened position OrderSymbol()==Symbol()) // check for symbol { if(OrderType()==OP_BUY) // long position is opened { // should it be closed? if(Bid >= TakeProfit) { OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position ---- I took out this part } } if(OrderType()==OP_SELL) // short position is opened { if(Ask <= TakeProfit) { OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position ---- I took out this part } } } } }
//or u can use like this
void CheckForClose() { double TakeProfit = iMA(NULL,0,15,0,MODE_EMA,PRICE_CLOSE,0); //----- for(int cnt=0; cnt < OrdersTotal(); cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if(OrderType()<=OP_SELL && // check for opened position OrderSymbol()==Symbol()) // check for symbol { OrderModify(OrderTicket(),OrderOpenPrice(),0,TakeProfit,0,Red); // new close position which recalculate the TakeProfit based on MA } } }didn't checked i hope it's what u want
Thanks again for your help. But, there is one error message - '(' - function definition unexpected. I only replace this part of code.
One more question. Do You usually type the code, or only copy some code and make changes on it?
1) You should put this at the end of the EA after the last parentheses and u should call the function
2) I took your code & i made some changes
edit: like this
int start() { //---- your code ........ CheckForClose(); //---- return(0); } //+------------------------------------------------------------------+ void CheckForClose() { double TakeProfit = iMA(NULL,0,15,0,MODE_EMA,PRICE_CLOSE,0); //----- for(int cnt=0; cnt < OrdersTotal(); cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if(OrderType()<=OP_SELL && // check for opened position OrderSymbol()==Symbol()) // check for symbol { OrderModify(OrderTicket(),OrderOpenPrice(),0,TakeProfit,0,Red); // new close position which recalculate the TakeProfit based on MA } } } //or the other function void CheckForClose() { double TakeProfit = iMA(NULL,0,15,0,MODE_EMA,PRICE_CLOSE,0); //----- for(int cnt=0; cnt < OrdersTotal(); cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if(OrderType()<=OP_SELL && // check for opened position OrderSymbol()==Symbol()) // check for symbol { if(OrderType()==OP_BUY) // long position is opened { // should it be closed? if(Bid >= TakeProfit) { OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position ---- I took out this part } } if(OrderType()==OP_SELL) // short position is opened { if(Ask <= TakeProfit) { OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position ---- I took out this part } } } } }

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I would like to know if the function OrderSend accepts inside the field "Take Profit" a variable value.
For example: I want to close a buy order if price is greater than a moving average. I did like this:
I read that in an EA the function IndicatorCounted() is not allowed but I must do a lopping to recalculate the new take profit. So, I think that is my problem.