Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1474

 
Aleksandr Slavskii #:

I tried to make an analogue of the comment, but the letters were bigger.

Some time after running the Expert Advisor with a comment on several charts, something bad happens, up to the screen going out and rebooting the server)))))

It is clear that I am doing something wrong with the CCanvas class, but what exactly is wrong, I do not understand.

I think I got it. Correct me if I understood it wrong.

In my code, on each tick I create a resource with different names.

code from Canvas

      //--- generate resource name
      m_rcname="::"+name+(string)ChartID()+(string)(GetTickCount()+MathRand());
      //--- initialize data with zeros
      ArrayInitialize(m_pixels,0);
      //--- create dynamic resource
      if(ResourceCreate(m_rcname,m_pixels,width,height,0,0,0,clrfmt))

And at the next refresh of the image this resource is not deleted, apparently.

The object is the same, but the resources are attached to it differently.

So I've redone the code.

I think it should be correct.

#include <Canvas\Canvas.mqh>
//+------------------------------------------------------------------+
void Comm(string txt, color clr = clrYellow, int FontSize = 20, string Font = "Consolas", int flag = FW_BOLD)
  {
   int shift = 0;
   if(ChartGetInteger(0, CHART_SHOW_ONE_CLICK))
      shift = 60;

   CCanvas canvas;
   canvas.FontNameSet(Font);
   canvas.FontFlagsSet(flag);
   canvas.FontSizeSet(FontSize);

   int width = 0, height = 0;
   string result[];
   int size = StringSplit(txt, StringGetCharacter("\n", 0), result);
   height = (int)(FontSize * 1.8 * size);

   for(int i = 0; i < size; i++)
     {
      int w = canvas.TextWidth(result[i]);
      if(width < w)
         width = w;
     }

   if(ObjectFind(0, "Comment") < 0)
      canvas.CreateBitmapLabel(0, 0, "Comment", 5, 20 + shift, width, height, COLOR_FORMAT_ARGB_NORMALIZE);
   else
      canvas.Attach(0, "Comment", width, height, COLOR_FORMAT_ARGB_NORMALIZE);
   canvas.Erase(0x00FFFFFF);

   for(int i = 0; i < size; i++)
      canvas.TextOut(0, (int)(FontSize * 0.8 * i), result[i], ColorToARGB(clr, 255));

   canvas.Update(true);
  }
//+------------------------------------------------------------------+
 
Aleksandr Slavskii #:

It doesn't write anything when compiling. It uninstalls and rebuilds. That's it.

It's still working on the server. I'll wait, maybe it will write something in the logs.

"Experts" magazine

 
Artyom Trishkin #:

Experts Magazine

In Experts Magazine, sterile cleanliness.

//---

We have generally solved the cause of the problem.

The question remains, how to delete a resource created by kanvas from memory when closing the programme.

I delete the object, it has a name, but the name of the resource is "protected" and you can't recognise it in any way.

Yes, OOP is a funny thing.

In the end I had to declare canvas in the global instead of in the function body and add canvas.Destroy() to the deinit;

Flight is fine)

 

Good day and good mood!

For a long time I have been using a ready-made function for calculating the lot depending on the risk, but it did not have a binding to the stop-loss size. Today I decided to write my own function from scratch in the form of a script (for ease of checking), but with the stop loss taken into account. Please see the formula for calculating the lot size (highlighted in yellow). Perhaps I missed something.

All kinds of checks for minimum, maximum lot, step, etc., etc., were not included, because I will do it later!

Regards, Vladimir.

//+------------------------------------------------------------------+
//|                                   Lot_Size_Depending_On_Risk.mq5 |
//|                                  Copyright 2023, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property script_show_inputs
input double Risk=5;      // Размер риска
input uint Stop_Loss=500; // Размер стоп-лосса
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double Lot_Size_Depending_On_Risk()
  {
   //--- определим валюту депозита
   string symbol="";
   string account_currency="";
   symbol=account_currency==AccountInfoString(ACCOUNT_CURRENCY) ? "EURUSDrfd" : "USDRUBrfd";
   double trading_account_currency=NormalizeDouble(SymbolInfoDouble(symbol,SYMBOL_BID),2);
   double lot=(AccountInfoDouble(ACCOUNT_MARGIN_FREE)*Risk*0.01)/(Stop_Loss*trading_account_currency);
   return(lot);
  }
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   Print(DoubleToString(Lot_Size_Depending_On_Risk(),2));
  }
//+------------------------------------------------------------------+
 
MrBrooklin #:

Good day and good cheer everyone!

For a long time I have been using a ready-made function for calculating the lot depending on the risk, but it did not have a binding to the stop-loss size. Today I decided to write my own function from scratch in the form of a script (for ease of checking), but with the stop loss taken into account. Please see the formula for calculating the lot size (highlighted in yellow). Perhaps I missed something.

All kinds of checks for minimum, maximum lot, step, etc., etc., have not been included, because I will do it later!

Regards, Vladimir.

It is necessary to take into account the cost of one tick.

 
Alexey Viktorov #:

Be sure to consider the cost per tick.

Hi Alexey, thank you for responding. For the purpose of self-education, I would like to understand the purpose of taking into account the cost of one tick and also briefly explain in which part of the formula it should be applied, if you don't mind. Perhaps I have not quite understood what you are talking about.

Regards, Vladimir.

 
MrBrooklin #:

Hi Alexey, thank you for responding. For self-education purposes, I want to understand the purpose of taking into account the cost per tick and also briefly explain in which part of the formula to apply it, if you don't mind. I may have misunderstood what you are talking about.

Regards, Vladimir.

To determine the amount a trader is willing to lose in case of failure. Loss = Loss*pip value*lot. Hence - lot = acceptable loss/( Loss*pip value) The formula is approximate.

 
Alexey Viktorov #:

To determine the amount a trader is willing to lose in case of failure. Loss = Loss*pip value*lot. Hence - lot = acceptable loss/( Loss*pip value) The formula is approximate.

I see. I will think at my leisure how to implement it. Thanks for your advice!

Regards, Vladimir.

 

How can I find out the time of closing a position in the tester?

I open positions 1, 2, 3

I close positions 3, 2, 1

Neither in the tester report nor in the tester itself I have not figured out how to find out the closing time of a particular position.

The same in the report that the tester records, there is no way to find out the time of closing a position.


I need to find out the time of opening and closing a position. How?

In one of its librariesfxsaber writes: "Thank you to the developers for creating the Tester's caches and helping to open its formats".

I can't understand the library itself.

I could only find the format of opt files.

If anyone knows where on the forum disclose tst-files - single pass format, please give me a link, maybe I can find position_ID in them.

fxsaber if you read, please reply.

 
Aleksandr Slavskii #:

How do I know the time of closing a position in the tester?

I open positions 1, 2, 3

Closing positions 3, 2, 1

Neither in the tester report nor in the tester itself I have not figured out how to find out the closing time of a particular position.

The same is true for the report written by the tester, there is no way to find out the time of closing a position.


I need to find out the time of opening and closing of a position. How?

fxsaber in one of its libraries writes: "Thanks to the developers for creating Tester caches and helping to open its formats.

I could only find the format of opt files.

If anyone knows where on the forum they disclose tst-files - single pass format, please give me a link, maybe I can find position_ID in them.

fxsaber if you read, please reply.

Look for a market exit trade

DEAL_ENTRY_IN

Market Entry

DEAL_ENTRY_OUT

Exit the market

DEAL_ENTRY_INOUT

reversal

DEAL_ENTRY_OUT_BY

Closing with a counter position

and look for position ID on the ticket of this trade

DEAL_TICKET

Ticket of the trade. A unique number that is assigned to each trade

long

DEAL_ORDER

Order, on the basis of which the deal was executed.

long

DEAL_TIME

Time of transaction execution

datetime

DEAL_TIME_MSC

Time of transaction in milliseconds since 01.01.1970

long

DEAL_TYPE

Deal type

ENUM_DEAL_TYPE

DEAL_ENTRY

Direction of the trade - market entry, market exit or reversal

ENUM_DEAL_ENTRY

DEAL_MAGIC

Magic number for the trade (seeORDER_MAGIC)

long

DEAL_REASON

Reason or source of the transaction

ENUM_DEAL_REASON

DEAL_POSITION_ID

Identifier of the position, in the opening, modification or closing of which this deal participated. Each position has a unique identifier, which is assigned to all deals executed on the instrument during the life of the position.

long


Generally speaking, the time of a deal exiting the market is the time of position closing.

Reason: