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

 

Good afternoon, gentlemen!)

Trying to prepare data for training a neural network. The task is.

Have a matrix, where for example each row (time moment - bar) is an input vector, and columns for example 10000. What to do if there is dynamic data (number of rows1, rows2), and change in number at different points in time.

For example, a matrix is loaded into a network, each row is a vector for learning, but for each row, there is n number of rows dynamically changing in time.

A possible solution conjecture is to add additional columns to the matrix equal to the number of columns in the dynamical row, it turns out that each vector will have columns from the denamic, but as if of one row, just prosumed.

for example

1st vector

1.365 0 1 0 0 1 0 1 0 1 0 0 0 1 1 0 0 1 ... "line1 dynamic" 1 1 1 1 1

ssssssssssssssssssssssssssssssssss "line2 dynamic" 1 1 1 1

solution

1.365 0 1 0 0 1 0 1 0 1 0 0 0 1 1 0 0 1 ... "line1 dynamic" 2 2 2 2 2

 
Top2n:

Good afternoon, gentlemen!)

Trying to prepare data for training a neural network. The task is.

Have a matrix, where for example each row (time moment - bar) is an input vector, and columns for example 10000. What to do if there is dynamic data (number of rows1, rows2), and change in number at different points in time.

For example, a matrix is loaded into a network, each row is a vector for learning, but for each row, there is n number of rows dynamically changing in time.

A possible solution conjecture is to add additional columns to the matrix equal to the number of columns in the dynamical row, it turns out that each vector will have columns from the denamic, but as if of one row, just prosumed.

for example

1st vector

1.365 0 1 0 0 1 0 1 0 1 0 0 0 1 1 0 0 1 ... "line1 dynamic" 1 1 1 1 1

ssssssssssssssssssssssssssssssssss "line2 dynamic" 1 1 1 1

solution

1.365 0 1 0 0 1 0 1 0 1 0 0 0 1 1 0 0 1 ... "line1 dynamic" 2 2 2 2 2

And how do you learn a language that dynamically (once an hour, say) changes its vocabulary? That's how a neural network does it.
 
So there's MQL5, as I understand it. Or is it identical?
 
Andrey Sokolov:
So there's MQL5, as I understand it. Or is it identical?
Exactly the same.
 
Good afternoon. I have created an EA, it works fine, but if I turn off the terminal with the EA running and turn the terminal back on, the EA starts counting all over again. So, I have a question. What do I need to write in my EA, so it will reset the Input parameters on startup?
 
XFaost:
Good afternoon. I have created an EA, it works fine, but if I turn off the terminal with the EA running and turn the terminal back on, the EA starts counting all over again. So, I have a question. What do I need to prescribe in the EA, so it would reset the Input parameters when it starts?
I want my Expert Advisor not to reset the input parameters, but to collect information about the orders that were opened before it was closed.
 
XFaost:
Good afternoon. I have created an EA, it works fine, but if I turn off the terminal with the EA running and turn the terminal back on, the EA starts counting all over again. So, I have a question. What do I need to write in my EA, so it would reset the Input parameters when I start it?
Please describe the way the EA works. Perhaps you need to use a different principle. And if you still need to reset, then you should first define what is meant by "at start". And in general, a reset is a transition to the initial position. Write down the initial settings and set them at the right moment.
 

Greetings. Can you tell me what is wrong?

The EA places orders with stops above and below the price. If one of them triggers, the stop is adjusted if the price moves away from the stop more than set, if the price moves to the stop then no change.

At first I have written only Buy order and it has worked as expected. If I add a mirror image for sell, the stops will be corrected by the set value whatever the price moves.

In general, if separately, or to buy or to sell - everything works as it should, but both parts together - there is a bug.

#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

extern double Lot             = 0.01;
extern int    StopLoss        = 50;
extern int    Slippage        = 5;
extern int    Delta           = 60;
extern int    Delta2          = 170;
extern int    Magic           = 321;

int ticket;
double price, sl, sl2;
datetime counted_bar = 0;

int OnInit()
  {
    if (Digits == 3 || Digits == 5)
   {

       StopLoss      *= 10;
       Delta         *= 10;
       Delta2        *= 10;
      
   }

  
   return(INIT_SUCCEEDED);
  }


void OnTick() {
//////        ПРОДАЖА  ///////////////////////////////////////////////////////
if (SellLimitCount()==0 && SellCount()==0)
{    
  price = NormalizeDouble(Bid - Delta*Point, Digits);
  sl = NormalizeDouble(price + StopLoss*Point, Digits);
  ticket = OrderSend (Symbol(), OP_SELLSTOP, Lot, price, Slippage, sl, 0, "", Magic, 0, Red);
}

if (SellCount()!=0)
  {
   if (Bid < (OrderStopLoss() - NormalizeDouble (StopLoss*Point, Digits)))
     {
     sl = NormalizeDouble (Bid + StopLoss*Point, Digits);
     if (OrderModify(ticket, price, sl, 0, 0, Red)) Print ("Sell_Order_Modify_Ok");
     else Print ("ERROR_Sell_Order_Modify");
     }  
  }
if (SellLimitCount()!=0)
{
  if(Bid > (OrderOpenPrice() + NormalizeDouble (Delta2*Point, Digits)))
   {    
    if (OrderDelete(ticket, Red)) Print ("BuyLimit_Order_Delete_Ok");
    else Print ("ERROR_BuyLimit_Odrer_Delete");
   }  
}
/////////////////////////////////////////////////////////////////////////////////
///////       ПОКУПКА ////////////////////////////////////////////////////////
if (BuyLimitCount()==0 && BuyCount()==0)
{
  price = NormalizeDouble(Ask + Delta*Point, Digits);
  sl = NormalizeDouble(price - StopLoss*Point, Digits);
  ticket = OrderSend (Symbol(), OP_BUYSTOP, Lot, price, Slippage, sl, 0, "", Magic, 0, Blue);
}

if (BuyCount()!=0)
  {
    if (Ask > (OrderStopLoss() + NormalizeDouble (StopLoss*Point, Digits)))
     {
     sl = NormalizeDouble (Ask - StopLoss*Point, Digits);
     if (OrderModify(ticket, price, sl, 0, 0, Blue)) Print ("Buy_Order_Modify_Ok");
     else Print ("ERROR_Buy_Order_Modify");
     }  
  }
if (BuyLimitCount()!=0)
{
  if(Ask < (OrderOpenPrice() - NormalizeDouble (Delta2*Point, Digits)))
   {
    if (OrderDelete(ticket, Blue)) Print ("BuyLimit_Order_Delete_Ok");
    else Print ("ERROR_BuyLimit_Orde_Delete");
   }  
}
///////////////////////////////////////////////////////////////////////////////

}
//+------------------------------------------------------------------+
int BuyLimitCount(){
int count=0;
for(int i=OrdersTotal()-1; i>=0; i--){
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true){
if(OrderMagicNumber()==Magic){
if(OrderType()==OP_BUYSTOP)
count++;}}}return(count);}

int BuyCount(){
int count=0;
for(int i=OrdersTotal()-1; i>=0; i--){
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true){
if(OrderMagicNumber()==Magic){
if(OrderType()==OP_BUY)
count++;}}}return(count);}

int SellLimitCount(){
int count=0;
for(int i=OrdersTotal()-1; i>=0; i--){
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true){
if(OrderMagicNumber()==Magic){
if(OrderType()==OP_SELLSTOP)
count++;}}}return(count);}

int SellCount(){
int count=0;
for(int i=OrdersTotal()-1; i>=0; i--){
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true){
if(OrderMagicNumber()==Magic){
if(OrderType()==OP_SELL)
count++;}}}return(count);}
 
Andrey Sokolov:

Greetings. Can you tell me what is wrong?

The EA places orders with stops above and below the price. If one of them triggers, the stop is adjusted if the price moves away from the stop more than set, if the price moves to the stop then no change.

At first I have written only Buy order and it has worked as expected. If I add a mirror image for sell, the stops will be corrected by the set value whatever the price moves.

Generally, if separately, or to buy or to sell, everything is working as it should be, but both parts together - there is a bug.

...

The entire code you have shown us is a bug, isn't it? At least, the OnTick function is almost entirely a bug...

 
Vitalie Postolache:

A bug, do you mean the whole code shown?

When there are both parts of the code, both for buy and for sell, then after the pending order triggers, its stop is corrected in any price direction for some reason. And when there is only a Buy or Sell part of the code, the stop is corrected as intended, only when the price moves away from it.
Reason: