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

 

How do I do a loop on CLOSED orders?

I need to count how many orders are closed at Take Profit in general.

We can't work in this way:

 //+--Цикл, в котором определяется сколько ордеров закрыто по тейк-профиту--
              ValueToStopTrade=0;                                 // Предварительно обнуляем переменную
              total=OrdersTotal();
              for(cnum=0;cnum<total;cnum++)                        //Для всех ордеров
              {
                  OrderSelect(cnum, SELECT_BY_POS, MODE_HISTORY); //Выбираем ордер
                  if (OrderProfit()>0)                            //Если профит больше 0
                  {
                     ValueToStopTrade=ValueToStopTrade+1;         //Увеличиваем счетчик на 1
                  } 
              }                                                   //Конец цикла for

upd. Documentation says OrdersTotal() shows open and pending.... That's why it doesn't work.

What to do? Instead of Totals, should I simply put some number? )

 
libeadier:

How do I do a loop on CLOSED orders?

I need to count how many orders are closed at Take Profit in general.

We can't work in this way:

upd. Documentation says OrdersTotal() shows open and pending.... That's why it doesn't work.

What to do? Instead of Totals, should I simply put some number? )

That's how it should work:

 double ProfitableOrders()
 {
   double orders=0; 
   for(int i=0; i<OrdersHistoryTotal(); i++){
     if(!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))continue;
     if(OrderMagicNumber()!=Magic)continue;
     if(OrderType()>1)continue;
     if(OrderProfit()>0)orders++;
   }      
  return(orders);
 } 
 

Tough one, and I didn't see it in the documentation.....

Thank you!

charter:

That's how it should work:

 
charter:

Very often, working on the same TF, a design is used:

Question:

Isn't such an input code an obstacle for correct optimization of parameters, including SL and TP?

It seems to me that an EA working, say, on H1 and optimized/tested in the mode "by opening price" on H1 will not correctly react to the set SL and TP,

Since an EA only sees the chart once an hour, it is not able to correctly execute Stop orders, i.e. at their crossing points.

............................

As an example https://www.mql5.com/ru/code/9386, where only one parameter (SL) is optimised.

There, in PS, the author writes:

The Expert Advisor uses the model by bar opening prices. There is no point in optimizing by other models - it is a waste of time and computer resources. You can only verify the results of optimization by emulation of all ticks.

Reshettes are an exceptional original...

Look for something else for an example.

 

Does anyone know - is there an MT4 Indicator or Expert Advisor that draws "Range Bars"?

There is one - RangeBars_fromM1_time.


How to make an EA to be able to trade on a RangeBar chart?

 
Diubakin:

How can I make my Expert Advisor trade on the Range Bar chart?


A bad Expert Advisor is hindered by the chart as well.
 
Still, is it possible to make an Expert Advisor trade on a RangeBars_fromM1_time chart?...?
 
Diubakin:
Still, is it possible to make an Expert Advisor trade on a RangeBars_fromM1_time chart?...?
It is possible.
 
So... HOW DOES THAT work? if it's not a secret...
 
Hello. Trying to add a "112" Fibonacci level to the code. I added one level "top" and it worked. But I can't get it to be at the bottom. Please, take a look at what can be done. Thank you. I am waiting for answer.
Files:
1.mq4  6 kb