[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 483

 
Sepulca:


Not always like this...

"" Incorrect bid or ask price, possibly non-normalised price. You need to refresh the data after a delay of 5 seconds or more using the RefreshRates function and try again. If the error persists, it is necessary to stop all trading attempts and change the program logic."" "FROM DOCUMENTATION".

If on demo or real - it will not work. You very often try to open two orders in a row. This will work in the Strategy Tester. Put a delay between open orders.

What does "not always" mean? The code must be UNIVERSAL, i.e. it must work with ANY brokerage company (regardless of the number of digits in the quotes and all sorts of tricks of the brokerage company server to refuse the timely execution of trade orders)!
 
And there's something wrong with the opiators ifs!!!
 
Dimka-novitsek:

Thank you!!! Put in the normalisation... And damn-what the hell is going on at all!!!!!! My head's on fire. Seems easier than high school geometry.



You don't need normalisation for ASK and BID, you need Sleep(Shh1sec-5secs);
 

Got it! Here's the thing! Let me get this straight... Thank you very much for your participation, for your help. I don't understand it myself. Pay attention to the above code. There's a condition

 if (strela1<strela2&&SELL==0&&BUY!=0
  ){ udalenie ();

If... and if... and if there are no buy orders. I mean, there are! They are not zero. As you can see on the screenshot, the code has just begun to work and there are no buy orders! Well, no! And the condition is fulfilled, though it shouldn't be!

This can be seen from the message of the printer in the Expert Advisors window. By the way, the order was perfectly set when the condition was fulfilled, i.e., it was set!

It turns out that I misspelled the condition?

Of course, the next condition in the code was triggered,

if (strela1<strela2&&BUY==0&&SELL==0){

which is the one that should have been triggered under the circumstances!

What's wrong!!!?

What's wrong with the logical condition?!?

How the hell is it that they're both executed at once???

 

Watching, I don't understand... That's two conditions being met at once!!! Maybe I'm an idiot... But I don't get it. This is ridiculous. I guess I don't know how to write an if operator!

Man, the whole code.

//+------------------------------------------------------------------+
//|                                                     советник.mq4 |
//|                        Copyright 2012, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#include <WinUser32.mqh>
  extern double  lot=1;                          
  extern int taymfreym=0 ;                           
  extern double  stoplos=200 ;                          
  extern double  takeprofit=500 ; 
  extern double  magicnumber=350 ;                          


void BreakPoint(){//if (!IsVisualMode()) return(0);
keybd_event(19,0,0,0);
Sleep(10);
keybd_event(19,0,2,0);}

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   Print (   "  НачалоНачал " ); 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int i;
int start()
  {Print (   "  Начало " ); 
//----
for( int A=0; A<100 ; A++){
            
            double strela1 = iCustom(NULL, taymfreym, "индикатор", 2, A);
            double strela2 = iCustom(NULL, taymfreym, "индикатор", 3, A);
            
            int BUY=0,SELL=0;int ticket; 
            Print ( A,  "  strela1 " , strela1 , "    strela2  " , strela2 ); 
            
    
            
            for(int i=1; i<=OrdersTotal(); i++) {  
            if (OrderSelect(i-1,SELECT_BY_POS)==true) // Если есть следующий
        {                                       // Анализ ордеров:
         if (OrderSymbol()!=Symbol( ) )continue;      // Не наш фин. инструм
         if (OrderMagicNumber( ) !=magicnumber)continue;
         if (OrderType()==0){ BUY++; ticket=OrderTicket( );Print( "BUY++   " , BUY  ,"  ticket ",ticket);}
         if (OrderType()==1) {SELL++;ticket=OrderTicket( );Print( "SELL++   " , SELL  ,"  ticket ",ticket);}    } }
         
  
  if (strela1<strela2&&SELL==0&&BUY!=0
  ){ udalenie ();
              
   OrderSend(Symbol( ), OP_BUY, lot,NormalizeDouble(Ask, Digits), 3*Point, NormalizeDouble( Bid- (stoplos*Point),Digits),   NormalizeDouble( Ask+( takeprofit*Point),Digits), NULL, magicnumber, 0, CLR_NONE);           
      Print( "strela1<strela2&&BUY==0&&SELL!=0 " , GetLastError()); }
            
  if (strela1>strela2){ udalenie ();
                
   OrderSend(Symbol( ), OP_SELL, lot,NormalizeDouble( Bid, Digits), 3*Point, NormalizeDouble( Ask+ (stoplos*Point),Digits),   NormalizeDouble( Ask-( takeprofit*Point),Digits), NULL, magicnumber, 0, CLR_NONE) ; 
        Print( "strela1>strela2&&SELL==0&&BUY!=0 " , GetLastError()); }
      
    if (strela1<strela2&&BUY==0&&SELL==0){    
            
           OrderSend( Symbol( ), OP_BUY, lot, NormalizeDouble(Ask, Digits), 3*Point, NormalizeDouble( Bid- (stoplos*Point),Digits),   NormalizeDouble( Ask+( takeprofit*Point),Digits), NULL, magicnumber, 0, CLR_NONE);  
            Print( "strela1>strela2&&BUY==0&&SELL==0   " , GetLastError()  ,"  Ask ",Ask,"   stoplos= NormalizeDouble( Bid- (stoplos*Point),Digits)  ",
 NormalizeDouble( Bid- (stoplos*Point),Digits),"    takeprofit= NormalizeDouble( Ask+( takeprofit*Point),Digits) ", NormalizeDouble( Ask+( takeprofit*Point),Digits)); }
           
   if (strela1>strela2&&BUY==0&&SELL==0){  
   
            OrderSend( Symbol( ), OP_SELL, lot,NormalizeDouble( Bid, Digits), 3*Point, NormalizeDouble( Ask+ (stoplos*Point),Digits),   NormalizeDouble( Ask-( takeprofit*Point),Digits), NULL, magicnumber, 0, CLR_NONE) ; 
            Print( "strela1>strela2&& OP_SELL  " , GetLastError()   ,"  Bid ",Bid,"    stoplos=   NormalizeDouble( Ask- (stoplos*Point),Digits)  ",
 NormalizeDouble( Ask- (stoplos*Point),Digits),"    takeprofit= NormalizeDouble( Bid+( takeprofit*Point),Digits) ", NormalizeDouble(Ask+( takeprofit*Point),Digits));
            Print( "strela1>strela2&& OP_SELL   " , GetLastError()  ," (stoplos*Point) ",(stoplos*Point),"   Point  ", Point,"   Digits  ", Digits); }
               
    
   
   
     } Print (   "  Конец " ); BreakPoint();     
//----
   return(0);
  }
//+------------------------------------------------------------------+

void udalenie (){ int total = OrdersTotal();
  for(i=total-1;i>=0;i--)
    {
    OrderSelect(i, SELECT_BY_POS);
   int type   = OrderType();  bool result = false;
    switch(type)
          { 
          case OP_BUY       : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 3*Point, CLR_NONE ); break;
          case OP_SELL      : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 3*Point, CLR_NONE ); break; 
          }
    if(!result)
      {
      int error =  GetLastError(); 
      string errorcomment = "Неудалось закрыть ордер №" + OrderTicket() + " " + Symbol() + " " + OrderType() + " " + error; 
      Print(errorcomment);
      }  
    }       
   }

Explanation, just to make it easier... The standard order picking, as I see it. Separate open orders are read in BUY++, SELL++ variables.

Then these variables are involved in logical conditions. The rest does not seem to be of any importance, although who knows.

Actually, it is clear what I've seen in the prints.

 
aedu:
I downloaded an EA for work in "one click", compiled - no errors, but except "face" in the corner does not show anything. Help !!!!!!!!!!!!!
McTrader_"+Symbol()+"_command.dat" file, I think it needs something like a script with commands for the EA. It does not create it by itself. Therefore, please contact the developer for explanations.
 
Dimka-novitsek:

Watching, I don't understand... That's two conditions being met at once!!! Maybe I'm an idiot... But I don't get it. This is ridiculous. I guess I don't know how to write an if operator!

Man, the whole code.

Explanation, just to make it easier... The standard order picking, as I see it. Selling separately open orders in BUY++, SELL++ variables.

Then these variables are involved in logical conditions. The rest does not seem to be of any importance, although who knows.

Actually, it is clear what I've seen in the prints.

can you give me an "indicator"?

although don't

 

What's the big shot, why is he getting so worked up?
 
Dimka-novitsek:

Watching, I don't understand... That's two conditions being met at once!!! Maybe I'm an idiot... But I don't get it. That's ridiculous. I guess I don't know how to write an if operator!

Man, the whole code.

Explanation, just to make it easier... The standard order picking, as I see it. Separate open orders are read in BUY++, SELL++ variables.

Then these variables are involved in logical conditions. The rest does not seem to be of any importance, although who knows.

Actually, it is clear what I've seen in the prints.

Lots of logical and technical errors. The logic of opening orders is not traceable (I had to use my imagination). You need to learn by yourself, picking your own sloppy code (until it "straightens out") OR study other people's codes. I did your code for you. - Will it help you?

P.S. As I said before, you don't need to normalize prices for a tester. But one of the possible reasons for the "Wrong price" error when executing a trade order may be the Slippage, which you have 3 * Point (when converted to int) = 0.

Files:
rcjipewc.mq4  6 kb
 
Thank you!!!!!