[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 54

 
vovan-gogan:

Isn't it the same in my example? How is it different? Except that I didn't add a start function.


Better yet, it goes like this.

int start()                            // Спец. функция start
  {
    int Orders=0;
     if (MA2_2<MA1_2 && MA2_1>MA1_1)  //пересечение МА
        {
          if (OrdersTotal()>= 1) return(0);   
          SL = 30;
          TP = 12;
          S_Price = Low[1] - 1* Point;
          int ticket = OrderSend (Symbol(), OP_SELLSTOP, Lots, S_Price, 0, SL, TP, "My order", Magic);     
          if (ticket>0)              // Если ордер установлен
             while(OrderSelect(ticket,SELECT_BY_TICKET)==false)  Sleep(100); // Если ордер выбран         
          Orders++;
          Alert ("Ордер выставлен.Orders = ",Orders );
             
        }   
       Alert ("Ордеров нет. Orders = ",Orders );    
//----------------------------------------------------------------  
   return;                             // Выход из start()
  }


                 
         
      
 
vovan-gogan:

But I don't see the difference to try. Please tell me what I did wrong.

You try and write the result. The order may not be set according to your condition, due to lack of necessary checks when setting it. In addition, it would not hurt to add an error handler when it is not installed for one reason or another, slippage make > 0 - this is the first thing that immediately shows.
 
Are you referring to slippage on a pending order?
 
vovan-gogan:
Do you mean slippage on a pending order?


Don't pick on the text - just set it and that's it...Check it.

At least in the tester everything should work - if you fail to set an order due to a short distance, it will be set next time - your question was about something else - then you will finish everything else - check as it is in the tester.

 
Roman.:


Don't pick on the text - set it and that's it...Check it.

At least in the tester everything should work - if you do not set an order due to a small distance, it will be set next time - your question was about something else - then you will finish everything else - check as is, in the tester.


Thank you for wanting to help, but in this particular situation I would like you to first help me understand my mistake. If I constantly use solutions developed by others, and not realize my mistakes, I'm unlikely to grow as a programmer. I hope you agree with that
 
vovan-gogan:

Isn't it the same in my example? How is it different? Except that I haven't added the start function.


Re-read the concept of local and global variables. In addition, due to this construction

 if (OrdersTotal()>= 1) return(0);  

if a position will be opened manually or by another EA on the same trading account, the EA will not set a pending order when the trade condition triggers for setting a pending order, it will work just fine for a strategy tester.

In the general case, you need to arrange a loop by the orders opened or set by this very Expert Advisor, depending on the logic of your algorithm, in the absence of pending orders, set it and increase the counter of orders and print the information.

 
vovan-gogan:

Thank you for your willingness to help, but in this particular situation I want you to help me first of all to understand my error. If I constantly use solutions written by others, and don't realize my mistakes, I will hardly be able to grow as a programmer. I hope you agree with that


Agreed. Re-read the concept of local and global variables in the client terminal.



int start()                            // Спец. функция start
  {
    int Orders=0;    
     if (MA2_2<MA1_2 && MA2_1>MA1_1)  //пересечение МА
        {
          if (OrdersTotal()>= 1) return(0);   
          SL = 30;
          TP = 12;
          S_Price = Low[1] - 1* Point;
          int ticket = OrderSend (Symbol(), OP_SELLSTOP, Lots, S_Price, 0, SL, TP, "My order", Magic);     
          if (ticket>0)              // Если ордер установлен
             while(OrderSelect(ticket,SELECT_BY_TICKET)==false)  Sleep(100); // Если ордер выбран         
          Orders++;
          Alert ("Ордер выставлен.Orders = ",Orders );
             
        }   
         
//----------------------------------------------------------------  
   return;                             // Выход из start()
  }
 
vovan-gogan:

Thank you for your willingness to help, but in this particular situation I would like you to help me understand my mistake first.


Ask the question already... :-Р

Try the variant from my previous post.

Read the tutorial and documentation here - I haven't seen more detailed mincemeat chewed up anywhere yet.

 
Thanks for the tip about global and local variables) I'll read more)
 
Alexandr24:
Tell me why when I open a chart (real time) with M30 timeframe and apply the indicator with parameter int shift=iBarShift(NULL,PERIOD_M5,some_time); shift will be as it should be, but when I run the same indicator through the tester with period M30 shift is not calculated?

Who knows how to solve this problem?