Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1951

 
Andrei Sokolov #:

Not that I know of, and haven't seen it described.

No, that's right, past warrant data is in the details.

 
Andrei Sokolov #:

As far as I understand it, it depends on the price at which the loss and profit are needed, the price that is in the terminal at the time of the opening request, or the price at which it will actually open.

The question is about the error percentage and speed of execution. The error probability is lower with lower parameters, but the 2 operations logically take more time. But how in reality, we need to measure. Maybe someone has already measured it.

 

I interject :)

There is a DAX30 index = quoted from 9 to 22

What is the way to find out how many bars in a session on Timeframe M15, H1 etc.

 
Vitaly Muzichenko #:

I interject :)

There is a DAX30 index = quoted from 9 to 22

What is the way to find out how many bars in a session on Timeframe M15, H1 etc.

(22*3600-9*3600)/PeriodSeconds(M15)

but this is ideally "this many bars should be between 9:00 and 22:00".

The smaller is the timeframe, the greater is the error, in reality it is almost always less. You can't count "every N bars - next session" from the history

 
Valeriy Yastremskiy #:

The question is generally about error rates and execution speed. With lower parameters there is less chance of errors, but 2 operations take more time logically. But how in reality, we have to measure it. Maybe someone has already measured it.

If " Question in general about error percentage and speed of execution" then write the question like that.

 
Valeriy Yastremskiy to open a position immediately with a SL and TP, or to open a position first and then modify it?

Even in 4, it is better to"open a position first, then mod ify it".

Not everyone allows you to open on the market while setting a Stop Loss.

By the way, Stop Loss is not available everywhere. The stop-loss order is processed on the broker's server, it's his personal service (merit, risk, earnings) and not where you think it is, there is no trading stack of stop-loss orders.

 
Vitaly Muzichenko #:

I interject :)

There is a DAX30 index = quoted from 9 to 22

What is the way to find out how many bars in a session on Timeframe M15, H1 etc.

Maxim Kuznetsov #:

(22*3600-9*3600)/PeriodSeconds(M15)

but this is ideally "this many bars should be between 9:00 and 22:00".

The smaller is the timeframe, the greater is the error, in reality it is almost always less. You can't use the history to calculate "the next session every N bars".

It's much simpler...

int  Bars( 
   string           symbol_name,     // имя символа 
   ENUM_TIMEFRAMES  timeframe,       // период 
   datetime         start_time,      // с какой даты 
   datetime         stop_time        // по какую дату 
   );
Документация по MQL5: Доступ к таймсериям и индикаторам / Bars
Документация по MQL5: Доступ к таймсериям и индикаторам / Bars
  • www.mql5.com
Bars - Доступ к таймсериям и индикаторам - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 

Good afternoon everyone.

I need your help.

The EA has a built-in counting function for the current profit:

double GetProfitFromStart()
  {
   double lp=0,cp=0;
   for(int i=0; i<OrdersHistoryTotal(); i++)
     {
      if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
        {
         if(OrderSymbol()==_Symbol && OrderMagicNumber()==Magic)
           {
            if(OrderType()==OP_BUY || OrderType()==OP_SELL)
              {
               if(Start<OrderCloseTime()) {lp+=OrderProfit()+OrderCommission()+OrderSwap();}
              }
           }
        }
     }
   for(int pos=OrdersTotal()-1;pos>=0;pos--)
     {
      if(OrderSelect(pos, SELECT_BY_POS, MODE_TRADES))
        {
         if(OrderSymbol()==_Symbol && OrderMagicNumber()==Magic)
           {
            if(OrderType()==OP_BUY || OrderType()==OP_SELL) {cp=OrderProfit()+OrderCommission()+OrderSwap();}
           }
        }
     }
   return(lp+cp);
  }
void OnTick()
  {
// Получим значение индикатора
   dMA = iMA(Symbol(), 0,PeriodMA, MovingShift, MODE_SMA, PRICE_CLOSE, 0); // MODE_SMA - простое усреднение , значение 0. PRICE_CLOSE- цена закрытия, значение 0.

// Если нет открытых ордеров, то входим в условие
      if(CountOrders()==0)
     {
// Если появился сигнал на покупку, то откроем ордер на покупку
      if(bSignalBuy() == true)
         vOrderOpenBuy();

// Если появился сигнал на продажу, то откроем ордер на продажу
      if(bSignalSell() == true)
         vOrderOpenSell();
     }
// Пишем какой лот текущий и какой следующий
      DrawLABEL("nextlot"   ,1,5,0,Color1(),StringConcatenate("CURRENT LOT: ",DoubleToStr(LOT(),2)));
      DrawLABEL("currentlot",1,5,0,Color2(),StringConcatenate("NEXT LOT: ",DoubleToStr(LOT(),2))); 
       DrawLABEL("lab_Take" ,1,5,0,Color(GetProfitFromStart()>0,Lime,Red),StringConcatenate("Profit: ",DoubleToStr(GetProfitFromStart(),2)));
      TrailingOrders();
   }

void OnTick is made up as above.

How to make profit counter reset to 0.0 when conditions are met:

if(CountOrders()==0) && (GetProfitFromStart()>0

i.e. all orders are closed and the total profit when the last order is closed was >0?

 

Installed MT4. Doesn't save the quotes after closing the terminal - loads a new one each time.

 
Maxim Kuznetsov #:

even in 4, it is betterto "open first, modify later".

Not everyone allows you to open on the market with a Stop Loss at the same time.

By the way, stop loss does not happen everywhere. You can't get it everywhere, it's on the broker's server, it's his personal service (credit, risk, earnings) and not where you think it is, there's no trading channel of stop orders.

Thanks, yes, even the demo on different brokers shows too different conditions.