mql5 - vertical line after a certain time since the last trade

 

Hi all!

Guys, can someone help/suggest how to implement the following idea in MQL5 (I just got acquainted with Metatrader myself - I'm not writing any code yet).

Code algorithm:
1) The time of closing of the last trade and the result of the trade are determined.

2) Determines the total result of the day after closing the last trade.

3) According to the indicator settings, a vertical line is drawn at a certain interval in the future from the time of closing of the last trade.
Settings:
- if the result of the last trade is negative and the result of the day is negative, a vertical line is drawn at a distance of 24 hours (a day) into the future.
- if the result of the last trade is negative and the result of the day is positive, the vertical line is drawn 2 hours into the future.
- if the result of the last trade is positive, the vertical line is drawn 1 hour into the future.

4) The line remains on the chart even after opening a new trade, but moves after closing a new trade according to the above algorithm, because already a new trade was the last one closed.

Note.
The positive result is a positive result, it does not matter whether the order was triggered or the position was manually closed. I.e. plus in the balance.
A negative result is minus or zero as a result of a deal.

P.S>

The essence of this code for me is to get used to taking a break after a trade, and not to get too hot. I have noticed that my losses are caused by trying to quickly win back unsuccessful deals. For me it is possible to put a line manually and move it in accordance to this rule, but I need exactly a program variant, because in the future I want to bind additional conditions/filters to the indicator, i.e. to complicate the algorithm of decision-making.

Thanks in advance and good luck!

 

As an example.

void moveVLine(string obj_name, datetime obj_time)
{
   int         tm       = PeriodSeconds(PERIOD_D1);
   datetime    next_day = obj_time + tm;
   MqlDateTime tm_str;
   
   TimeToStruct(next_day,tm_str);
   if(tm_str.day_of_week == 6)
   {
      tm *= 3;
      next_day = obj_time + tm;
   }
   ObjectMove(0,obj_name,0,next_day,0);
   
   return;
}
 
Сергей Таболин:

As an example.

Sergey, thank you!
I'll let you know how it turns out when I run your example
 
Сергей Таболин:

As an example.

The example did not compile :(
As I understood - the code is a fragment and it is necessary to add some mandatory components (#property, etc.)?
 

I found a similar indicator that simply draws a vertical line at a certain time - I'll try to use it as a basis, adding the necessary algorithms instead of predetermined static time.
https://www.mql5.com/ru/code/18449

Vertical line
Vertical line
  • www.mql5.com
Индикатор рисует, а затем перемещает нарисованную вертикальную линию (OBJ_VLINE) на заданное время (часы и минуты). Входные параметры: Из параметра "Use only Hours and minutes" используются только часы и минуты.  Вертикальная линии рисуется для текущего дня. Если начинается новый день, то нарисованная линия переносится на этот новый день на...
 
Stupidity.
There is a source (code above) that draws a line on a bar at a given time. Just need to remove time from input parameters and get time value from history of trades. Looking through the documentation Trading functions, I suspect that the truth is somewhere among the functions in the History group... So far I don't see anything :(
Can someone help/tell me how to get data of last deal from history (time of closing a position and fixing the result of a deal)?
 
renatmt5:
The example did not compile :(
As I understood - the code is a fragment and it is necessary to add some mandatory components (#property, etc.)?

This is a vertical line transfer function. It must be called from the main code if certain conditions are met. In addition, the line itself must already be there.

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

This is a vertical line transfer function. It must be called from the main code if certain conditions are met.

OK, thanks again!
 
renatmt5:

Hi all!

Guys, can someone help/suggest how to implement the following idea in MQL5 (I just got acquainted with Metatrader myself - I'm not writing any code yet).

Algorithm code:
1) Determines the time of closing of last trade and the trade result.

2) Determines the total result of the day after the last trade closure.

3) According to the settings of the indicator a vertical line is drawn on a certain interval in the future from the time of closing of the last trade.
Settings:
- if the result of the last trade is negative and the result of the day is negative, a vertical line is drawn at a distance of 24 hours (24 hours) into the future.
- if the result of the last trade is negative and the result of the day is positive, the vertical line is drawn 2 hours into the future.
- if the result of the last trade is positive, a vertical line is drawn at a distance of 1 hour into the future.

4) The line stays on the chart even after opening a new trade, but it is moved after closing a new trade according to the above algorithm, as the new trade has already become the last closed trade.

Note.
A positive result is a plus, irrespective of whether the order has triggered or a position has been manually closed. I.e. plus in the balance.
A negative result is minus or zero as a result of the trade.

P.S>.

The essence of this code for me in the following - to get used to do a pause after deals and not to break a hot streak. I've noticed that my losses are caused by trying to win back unsuccessful deals quickly. For me it is possible to put a line manually and move it in accordance to this rule, but I need exactly a program variant, because in the future I want to bind additional conditions/filters to the indicator, i.e. to complicate the algorithm of decision-making.

Thanks in advance and good luck to everyone!

So, let's call it an indicator.

So, let us set it this way. Let us define that we interrogate the trading history once per minute. Then we need two more parameters:

  • take into account the last deals only for the current symbol (the symbol on which the indicator is running) or for all?
  • and magfic number accounting (consider only one or all)?


I will need an answer from you. I will try to appear in this thread again by lunchtime.

 
Vladimir Karputov:

An indicator is an indicator.

So it's like this. Let's define that we interrogate the trading history once a minute. Then we need two more parameters:

  • take into account the last deals only for the current symbol (the symbol on which the indicator is running) or for all?
  • and magfic number accounting (consider only one or all)?


I will need an answer from you. I will try to appear in this thread again by lunchtime.

Vladimir, thank you for taking the time to ask my question. As simple as possible initially, as I expect to refine it myself in the long term, rather than halting it :)
- only on the current symbol
- Regarding magfic number - I'm not sure what it's about. Like some kind of ID? It's not important for me, to be honest. I only need data on one last closed transaction

 

I would like to clarify the term "last trade".

Is it the last trade within the current day? Or for the last N-days?

Reason: