Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1127

 
Still don't understand what the question is?
 
MrBrooklin:

Hello Vladimir!

Please help me modify the start of the script below:

I need the script to set pending orders not from ask and bid, but from hight and low of the previous bar (candlestick).

Sincerely, Vladimir.

Like this:

//--- start work
   double start_price_ask=0.0;
   double start_price_bid=0.0;
//---
   MqlRates rates[];
   ArraySetAsSeries(rates,true);
   int start_pos=0,count=3;
   if(CopyRates(m_symbol.Name(),Period(),start_pos,count,rates)!=count)
     {
      Print(__FILE__," ",__FUNCTION__,", ERROR: CopyRates ");
      return;
     }
//---
   if(InpPending==stop)
     {
      start_price_ask=rates[1].high+ExtUpGap;
      start_price_bid=rates[1].low-ExtDownGap;
     }
   else
      if(InpPending==limit)
        {
         start_price_ask=rates[1].low-ExtDownGap;
         start_price_bid=rates[1].high+ExtUpGap;
        }
 

Forum on Trading, Automated Trading Systems and Strategy Tests

FAQ from Beginners MQL5 MT5 MetaTrader 5

Vladimir Karputov, 2019.09.18 12:49

About like this:

//--- start work
   double start_price_ask=0.0;
   double start_price_bid=0.0;
//---
   MqlRates rates[];
   ArraySetAsSeries(rates,true);
   int start_pos=0,count=3;
   if(CopyRates(m_symbol.Name(),Period(),start_pos,count,rates)!=count)
     {
      Print(__FILE__," ",__FUNCTION__,", ERROR: CopyRates ");
      return;
     }
//---
   if(InpPending==stop)
     {
      start_price_ask=rates[1].high+ExtUpGap;
      start_price_bid=rates[1].low-ExtDownGap;
     }
   else
      if(InpPending==limit)
        {
         start_price_ask=rates[1].low-ExtDownGap;
         start_price_bid=rates[1].high+ExtUpGap;
        }

Great!!! Thank you!

Regards, Vladimir.

 
Why can't I use a custom criterion in a full parameter enumeration, what is the sacred meaning of this?
 

Forum on Trading, Automated Trading Systems and Strategy Tests

FAQ from Beginners MQL5 MT5 MetaTrader 5

Vladimir Karputov, 2019.08.31 14:38

Please.

Please pay attention to the m_first_start variable declared at global program level

bool        m_first_start  = false;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()

At the end of OnTick this variable is assigned the value "true"

//---
   m_first_start=true;
  }
//+------------------------------------------------------------------+
//| Refreshes the symbol quotes data                                 |
//+------------------------------------------------------------------+
bool RefreshRates()
  {

and the EA will no longer place pending orders until its next restart

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   if(m_first_start)
      return;

Hello Vladimir!

Please advise how to change the code so that the EA has placed pending orders on every bar to improve my self-education. I tried to simply delete all the yellow marking, but it would immediately start opening and placing thousands of orders and positions.

Sincerely, Vladimir.

 
MrBrooklin:

Hello Vladimir!

To enhance my self-education, please advise how to change the code so that the EA places pending orders on every bar. I tried to simply delete all marked in yellow, but it immediately starts opening and placing thousands of orders and positions.

Sincerely, Vladimir.

You should detect the moment when a new bar is born and place pending orders only then:

//+------------------------------------------------------------------+
//|                                                         Test.mq5 |
//|                              Copyright © 2019, Vladimir Karputov |
//|                                           http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2019, Vladimir Karputov"
#property link      "http://wmua.ru/slesar/"
#property version   "1.000"
/*
   barabashkakvn Trading engine 3.043
*/
#include <Trade\SymbolInfo.mqh>
//---
CSymbolInfo    m_symbol;                     // object of CSymbolInfo class
//--- input parameters

//---
datetime m_prev_bars             = 0;        // "0" -> D'1970.01.01 00:00';

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- we work only at the time of the birth of new bar
   datetime time_0=iTime(m_symbol.Name(),Period(),0);
   if(time_0==m_prev_bars)
      return;
   ЗДЕСЬ РАЗМЕЩАТЬ КОД ПО ВЫСТАВЛЕНИЮ ОТЛОЖЕННЫХ ОРДЕРОВ
//---
  }
//+------------------------------------------------------------------+
Files:
Test.mq5  4 kb
 

Thank you, Vladimir, for the tip.

Respectfully, Vladimir.

 
Vladimir Karputov:

It is necessary to determine when a new bar is born and only then place pending orders:

It is absolutely obvious! Where do these questions come from? From laziness or something else?

 
Сергей Таболин:

It's absolutely obvious! Where do these questions come from? From laziness or something else?

MrBrooklin is just taking his first steps, so he needs a hint. Everyone started out and was green at one time or another.

 
Vladimir Karputov:

MrBrooklin is just taking his first steps, so he needs some tips. Everyone started out once and was green.

I'm not against it in principle. But there has to be a logic to it?

I want something to be done on the new bar. Well, first of all, you need to define this new bar.

These questions are not a beginner, but a lazy man who wants everything chewed up and put in his mouth. Can't you use your brain?

Reason: