[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 901

 

hint, because I'm confused.

I have found the price of the last open order.

I want the last open order to close at:

if((Ask - цена последнего открытого ордера) >= 30 * Point)  OrderClose;
 

Good morning !

Can you please tell me if it is possible to close all pending orders in special function deinit() (to close all pending orders in case of internet failure) ? My EA only closes part of them. Maybe, it has not managed to do it in time (I have tried up to 7 pending orders)? Or, it has some kind of error and all orders should be closed irrespective of their number? On the remaining pending orders, the Expert Advisor just does not enter the close condition "yes", although it is -

if (OrderSelect(i-1,SELECT_BY_POS)==true)

- is fulfilled and should enter... It skips to "no" on all remaining orders and therefore doesn't close them. We may close them differently, i.e., three orders out of five or 4 orders out of 7, or 1 order out of 7. What could be wrong ?

 
sanyooooook:
Determine line time via ObjectGet and find the bar number via iBarShift

Thank you. but could you also explain how to convert the number of seconds to datetime correctly?
 
volshebnik:

Good morning !

Can you please advise whether it is possible to close all pending orders in the special function deinit() (to close all pending orders in case of internet failure)? My EA only closes part of them. Maybe, it has not managed to do it in time (I have tried up to 7 pending orders)? Or, it has some kind of error and all orders should be closed irrespective of their number? If there are other pending orders, the Expert Advisor just does not enter the close 'yes' condition, despite the fact that this condition

if (OrderSelect(i-1,SELECT_BY_POS)==true)

- and it should enter it ... It skips to 'no' on all remaining orders and therefore does not close them. It closes differently - three out of five, or 4 out of 7, or 1 out of 7. What could be wrong ?


There are no miracles. But the cycle I would do is like this:

for (int i=OrdersTotal()-1;i>=0;i--)

It would be different then.

 

Hello.

How do I write a condition to open a trade with the first ticks of a new bar and close it with the last ticks of the bar?

if (????)

 
Hello! A request from a dummy for knowledgeable people! I would like to make an alert for the metro indicator. Need a signal when the value of the slow line, but not at the closure of the bar, and at the beginning of changing the value! Who is not difficult, please write, or help write such a function! Thanks in advance!
 
Vinin:


There are no miracles. But I would loop like this:

for (int i=OrdersTotal()-1;i>=0;i--)

It would be different then.

Vinin: Thank you very much ! Everything closes now when the EA is switched off or the terminal is closed, but.... If I switch off the internet and do not switch off the terminal, and switch it on again after more than a minute - the advisor does not close and orders, respectively, also. Is there any way to automatically close the EA if the internet connection is lost?
 
volshebnik:
Vinin: Thank you very much ! Everything closes now when EA is switched off or terminal is closed, but.... If I switch off the internet and do not switch off the terminal, and switch it on again after more than a minute - the EA does not close and the orders, respectively, also. Is there any way to automatically close the EA if the internet connection is lost ?


There are no miracles. To close a position, you need a connection (must have internet), a primary or backup connection.

I would advise to use VPS only.

 

Good day, if you can help,

//+------------------------------------------------------------------+
//| Dimon's Borders .mq4 |
//| Copyright © 2010, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"

//+------------------------------------------------------------------+
//| expert initialisation function |
//+------------------------------------------------------------------+
extern int BandsPeriod=20,i=1 ;extern int BandsShift=0;
extern double BandsDeviations=2.0;
extern double Lots=0.1,TakeProfit=50,stoploss=10;
int init()
{
//----

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

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{double Average,Verhnyayaghranytsa,Nyzhnyayaghranytsa,newres,sum,deviation;

Average=iMA(NULL,0,BandsPeriod,BandsShift,MODE_SMA,PRICE_CLOSE,i);
//----
newres=Close[i]-Average;
sum=newres*newres;


deviation=BandsDeviations*MathSqrt(sum/BandsPeriod);
Verhnyayaghranytsa=Average+deviation;
Nyzhnyayaghranytsa=Average-deviation;
//----
if (Verhnyayaghranytsa<Close[i])
{ Comment(" buoy! ",Verhnyayaghranytsa );
OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid-stoploss*Point,Ask+TakeProfit*Point, "macd sample",16384,0,Green);

}


if (Nyzhnyayaghranytsa>Close[i])
{ Comment(" Sell! ",Nyzhnyayaghranytsa );

OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Ask+stoploss*Point,Bid-TakeProfit*Point, "macd sample",16384,0,Red);
}
return(0);
}
//+------------------------------------------------------------------+

Indicator smiles, writes sell or buoy, but no trade as such, maybe I prescribed OrderSend wrong, or I do not know.If you can, help!!!

 
Here.
Reason: