//+----------------------------------------------------------------------------+ //| Returns the bar number of the last position opened or -1. | //| Parameters: | //| sym - instrument name ("" - current symbol) | //| tf - timeframe ( 0 - current timeframe) | //| op - operation (-1 - any position) | //| mn - MagicNumber (-1 - any magik) | //+----------------------------------------------------------------------------+ int NumberOfBarOpenLastPos(string sym="", int tf=0, int op=-1, int mn=-1) { datetime oot; int i, k=OrdersTotal();
if (sym=="") sym=Symbol(); for (i=0; i<k; i++) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol()==sym) { if (OrderType()==OP_BUY || OrderType()==OP_SELL) { if (op<0 || OrderType()==op) { if (mn<0 || OrderMagicNumber()==mn) { if (oot<OrderOpenTime()) oot=OrderOpenTime(); } } } } } } return(iBarShift(sym, tf, oot, True)); }
GetLastError() returns 0 while an order is open and the order does not open. The help text "ERR_NO_ERROR - 0 - No error". Maybe I do not understand something, but if there is no error, the order should be opened. Explain what is wrong!!!
why scoop buys and does not close, no errors during commisioning
Either make ticket static or take definition out of start.
...
int init()
{
count=Bars;
return(0);
}
...
int start()
{
if(OrdersTotal()==0 && NumberOfBarOpenLastPos()!=0 && count<Bars )
{
//open orders
}
...
//+----------------------------------------------------------------------------+
//| Returns the bar number of the last position opened or -1. |
//| Parameters: |
//| sym - instrument name ("" - current symbol) |
//| tf - timeframe ( 0 - current timeframe) |
//| op - operation (-1 - any position) |
//| mn - MagicNumber (-1 - any magik) |
//+----------------------------------------------------------------------------+
int NumberOfBarOpenLastPos(string sym="", int tf=0, int op=-1, int mn=-1) {
datetime oot;
int i, k=OrdersTotal();
if (sym=="") sym=Symbol();
for (i=0; i<k; i++) {
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol()==sym) {
if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
if (op<0 || OrderType()==op) {
if (mn<0 || OrderMagicNumber()==mn) {
if (oot<OrderOpenTime()) oot=OrderOpenTime();
}
}
}
}
}
}
return(iBarShift(sym, tf, oot, True));
}
Yes, indeed. There are times when this technique
NumberOfBarOpenLastPos()!=0 does not work.
And only when the Expert Advisor works with ALL TICKETS.
But in the mode by TICK, this function works quite well in this variant !
I do not know why it does that.
Try to put this function in the comment and trace its work directly on the chart.
Maybe the experts will tell you a better way to check it ?
Please tell me what the logbook entry means:
Red circle and
2009.04.23 11:03:41 Old tick GBPJPYFXF60 142.58000/142.63000
(position did not open)
Please tell me what the logbook entry means:
Red circle and
2009.04.23 11:03:41 Old tick GBPJPYFXF60 142.58000/142.63000
(position did not open)
RefreshRates(); before an order is opened
RefreshRates(); before opening an order will help
That's right. Those were the requotes.
>> Thank you.
That's right. Those were requotes.
They're not requotes.
RefreshRates();
ticket = OrderSend(Symbol(),OP_BUY,GetLots(100),Ask,maxSlippage,0,0, "Long",Magic,0,Green);
if (NeedScreenShot) WindowScreenShot(Symbol() + Period() + "_" + Hour() + Minute() + "_.gif",1024,768);
if (NeedAlert) Alert(Symbol() + " " + Period() + ": Going Long");
if (ticket > 0) break;
lasterror = GetLastError();
if ((lasterror == 0) || (lasterror == 2) || (lasterror == 4) || (lasterror == 6) || (lasterror == 8) || (lasterror == 9) || (lasterror == 64) || (lasterror == 128) || (lasterror == 132) || (lasterror == 133) || (lasterror == 137) || (lasterror == 139) || (lasterror == 141) || (lasterror == 146))
{
Sleep(10);
circle red 2009.04.23 14:08:08 Old tick GBPJPYFXF30 142.95000/143.00999
All I got is red circles, I dont dont buy, I have ten requests in a row for one and the same price,
Help please, or maybe autotrading is disabled on the server? Forex.com I don't understand.