Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1425

 
vitaliy zamkovoy current price and compare it to some constant with the subsequent opening of an order, how should we record it?

Copy the ticks for the last 20 seconds, get the difference of the extreme values of the array and compare it with that constant.

 
Alexey Viktorov #:

Copy the ticks for the last 20 seconds, get the difference of the extreme values of the array and compare it to the same constant.

This should not be done one time, but as a continuous EA loop.

(A piece of code if you can...).

 
Alexey Viktorov #:

Copy the ticks for the last 20 seconds, get the difference of the extreme values of the array and compare it to the same constant.

Good morning, Alexey! What if we initialise the timer for 20 seconds first and check the difference of extreme values without an array? Isn't this option easier?

Regards, Vladimir.

 
MrBrooklin #:

Good morning, Alexey! What if we initialise the timer for 20 seconds first and check the difference of extreme values without an array? Wouldn't that be easier?

Regards, Vladimir.

This is all very interesting, of course, but I would like to see a "cheat sheet" for a coloniser 😁
 
vitaliy zamkovoy #:
This is all very interesting, of course, but I'd like to see a "cheat sheet" for the big boy 😁

It's too early to talk about the cheat sheet. I'm learning programming myself, that's why I'm asking questions. Maybe it will come in handy for me someday too.

Regards, Vladimir.

 
MrBrooklin #:

Good morning, Alexey! What if we initialise the timer for 20 seconds first and check the difference of extreme values without an array? Wouldn't that be easier?

Regards, Vladimir.

It may be easier, but the task is not to check every 20 seconds, but every tick from the current price 20 seconds backwards.

vitaliy zamkovoy #:

This should be done not once, but as a continuous cycle of the Expert Advisor.

(A piece of code, if you can...)

In OnTick it will be executed every tick continuously.

A piece of code if you can, but it goes against my principles. I don't write cheat sheets for two-liners. One cheat sheet for all cases has already been written and can be found here.

 
Alexey Viktorov #:

It may be easier, but the task is not to check every 20 seconds, but every tick from the current price 20 seconds backwards.

In OnTick it will be executed every tick continuously.

I can write a piece of code, but it goes against my principles. I don't write cheat sheets for two-students. One cheat sheet for all cases has already been written and can be found here.

I will now ask for help from knowledgeable people again, but please don't get distracted by me - keep the principles!
 
If we subtract the price of twenty seconds ago from the current price and compare it with a certain constant for the subsequent opening of an order, how can this be written in the Expert Advisor?
 
vitaliy zamkovoy #:
I'm going to ask for help from knowledgeable people again now, but you please don't get distracted by me - keep the principles!

ok. Please wait for a reply.

 
vitaliy zamkovoy current price and compare it with a certain constant for the subsequent opening of an order, how can this be written in the Expert Advisor?

Look at this code:

//+------------------------------------------------------------------+
//|                                                         Test.mq5 |
//|                                  Copyright 2022, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"

//ВХОДНОЙ ПАРАМЕТР
input ushort Constanta=50; //Константа

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer
   EventSetTimer(20);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
   EventKillTimer();
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
   double open_0=iOpen(_Symbol,PERIOD_CURRENT,0);
   if(open_0-SymbolInfoDouble(_Symbol,SYMBOL_BID)>Constanta*_Point)
      Print("Цена прошла вниз расстояние больше чем Константа, поэтому нужно открыть позицию SELL!");
   if(SymbolInfoDouble(_Symbol,SYMBOL_BID)-open_0>Constanta*_Point)
      Print("Цена прошла вверх расстояние больше чем Константа, поэтому нужно открыть позицию BUY!");
   Sleep(20000);
   if(open_0-SymbolInfoDouble(_Symbol,SYMBOL_BID)>Constanta*_Point)
      Print("Цена прошла вниз расстояние больше чем Константа, поэтому нужно открыть позицию SELL!");
   if(SymbolInfoDouble(_Symbol,SYMBOL_BID)-open_0>Constanta*_Point)
      Print("Цена прошла вверх расстояние больше чем Константа, поэтому нужно открыть позицию BUY!");
   Sleep(20000);
   if(open_0-SymbolInfoDouble(_Symbol,SYMBOL_BID)>Constanta*_Point)
      Print("Цена прошла вниз расстояние больше чем Константа, поэтому нужно открыть позицию SELL!");
   if(SymbolInfoDouble(_Symbol,SYMBOL_BID)-open_0>Constanta*_Point)
      Print("Цена прошла вверх расстояние больше чем Константа, поэтому нужно открыть позицию BUY!");
   Sleep(20000);
  }
//+------------------------------------------------------------------+
Regards, Vladimir.
Reason: