Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 901

 
evillive:

This could not be the case, there is no way the Ask on the Kangaroo could be higher than any opening price on the Eurodollar in 2015...

And all checks for the selected order should be done after the selection, with a separate if() clause.

That's right, it couldn't. That's why it gave out Bid<openPrice orders on eu at 1.11262.

In other words, do you suggest to check for the presence of an order using the if(OrderSelect()), and then in the embedded if we already compare the chart symbol with the order symbol, open price, etc.?

 
.roman.:

That's right, it couldn't. That is why it gave out a Bid<openPrice order for the eu at 1.11262.

In other words, do you suggest to check for an order using the if(OrderSelect()), and then compare the chart symbol with the order symbol, open price, etc., in the embedded if?

Yes, exactly, first OrderSelect(), and then the next check for the rest of the parameters.
 

Dancing around will not help.

There is no difference to write order selection and check for symbol and magician in one line or divide them into 3 different lines. According to changes in new builds check conditions are checked in stages, i.e. if the first condition is not fulfilled, the following ones will not be checked. It is the same as the 3 lines. The first condition is fulfilled and the second one is checked. And only if the second condition is also fulfilled we proceed to check the third one.

The problem is probably that there is a call of a user function in the deleted part of the code where another order is selected.

 

If there had been any mention of working with orders, that would have been the first thing I noticed. But there's only calculations, not a single user function used. It's not clear what exactly causes an order to be selected from another pair. That's why I'm so puzzled by the "software environment" mentioned in the documentation and have already redone the code as evillive suggested and am ready to dance with tambourines. The next perversion will be a forced comparison with bid\ask of the required pair via marketinfo.


UPD.: Problem solved. Actually found a nested function that uses its own OrderSelect. Thanks for the idea, AlexeyVik.

 
Hi all, Can you tell me how to solve a problem, I find the bar number I want in the loop, but I also need the past bar number in the loop, how to implement this succinctly? Thank you.
for(i=limit; i>=0; i--)
{
yesterday_weekday = TimeDayOfWeek(iTime(Symbol(),0,i-1))-TimeDayOfWeek(iTime(Symbol(),0,i));
if (yesterday_weekday ==1)
yesterday_time=iTime(Symbol(),0,i);
yesterday_shift=iBarShift(Symbol(),0,yesterday_time0);//последний бар 

}
 

I have created an EA (not for work, just for practice)

If I set both parameters in IF function, if I set them one by one, everything will work fine, here's the code (Also, how do I make sure that if I already have an open Buy order the next Buy order won't open, even if all the conditions match)?

//+------------------------------------------------------------------+
//|                                                        новый.mq4 |
//|                        Copyright 2015, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
int start()

  {
  
double PC = iClose ("EURUSD", PERIOD_H1, 0);  

double MA = NormalizeDouble (iMA ("EURUSD", PERIOD_H1, 12, 0, MODE_LWMA, PRICE_MEDIAN, 0), 4); 


if (Ask == MA && PC-->MA )
OrderSend("EURUSD",OP_BUY,1,Ask,3,Ask-30*Point, Ask+30*Point);

   
return (0);





   
  }
//+------------------------------------------------------------------+
 
inuboh:

I have created an EA (not for work, just for practice)

If I set both of them one by one it works fine, i.e., the code (and if I already have an open Buy order, how do I make a Buy order not to open next one, even if all conditions are correct?)

Not that it is the source of all troubles, but purely from academic interest: why simultaneously OnInit(), OnDeinit() and then suddenly start()?

And as for the question, it is strongly not recommended that such a comparison Ask == MA, very rarely comes true on history. So, what does such an expression PC-->MA mean?

As for the permission for one Buy, we loop through all market positions and compare them with the specified criteria - symbol, type, magic number, and increase the counter by one if the sought one is found. Then, where necessary, this counter is checked.

That's the way it is:

   _ExpertOrdersB=0;
   _ExpertOrdersS=0;

   for(int z=OrdersTotal()-1; z>=0; z --)
     {
      if(!OrderSelect(z,SELECT_BY_POS))
        {
         Print(". OrderSelect("+IntegerToString(z)+", SELECT_BY_POS ) FAIL!. Error #"+IntegerToString(GetLastError()));
        }
      if((OrderMagicNumber()==magic) && OrderSymbol()==_Symbol)
        {
          switch(OrderType())
           {
            default: break;
            case 0:
               _ExpertOrdersB++;
               break;
            case 1:
               _ExpertOrdersS++;
               break;
           }
        }
     }


if (_ExpertOrdersB < 1) //если нет покупок, то пытаемся купить, при условии, что:
if (Ask == MA && PC-->MA )
OrderSend("EURUSD",OP_BUY,1,Ask,3,Ask-30*Point, Ask+30*Point); 
 
evillive:

Not that it is the source of all troubles, but purely out of academic interest: why simultaneously OnInit(), OnDeinit() and then suddenly start()??

And as for the question, it is strongly not recommended that such a comparison Ask == MA, it very rarely comes true on history. So, what does this expression PC-->MA mean?

As for the permission for one Buy, we loop through all market positions and compare them with the specified criteria - symbol, type, magic number, and increase the counter by one if the sought one is found. Then we look at the counter where necessary.

start() changed the counter out of "habit" )

Why is Ask == MA a rare event? Does the current bid price rarely touch the Moving Average line?

The PC-->MA is in my case if the previous close price is higher than the Moving Average line (I haven't figured out another way).

So, when I enable the IF function one by one with Ask == MA and then PC-->MA it works fine, but when I combine them, it does not work!

 
evillive:

Not that it is the source of all troubles, but purely out of academic interest: why simultaneously OnInit(), OnDeinit() and then suddenly start()??

And as for the question, it is strongly not recommended that such a comparison Ask == MA, very rarely comes true on history. So, what does such an expression PC-->MA mean?

As for the permission for one Buy, we loop through all market positions and compare them with the specified criteria - symbol, type, magic number, and increase the counter by one if the sought one is found. Then, where necessary, this counter is checked.

That's how it is:

My understanding is that PC-- > MA is the same as PC-1 > MA.

 
AlexeyVik:

My understanding is that PC-- > MA is the same as PC-1 > MA


So it is! But why doesn't it work in this combination?

Although, in the picture below, it all adds up.


if (PC-->MA && Ask == MA)
OrderSend("EURUSD",OP_BUY,1,Ask,3,Ask-30*Point, Ask+30*Point);
Reason: