What data type for of MQL5 is good for this?

 
Hello,

I need to store (add, delete, edit) max profit base on  ticket numbers for example as below, what data type or library of mql5 can I use?

Maxprofit.ticketnumber1 = 1003
Maxprofit.ticketnumber2 = 811
 

The question makes no sense. Profit is just a sum.  Maximum profit requires multiple profits.

Until you can state your requirements in concrete terms, it can not be coded.

Use the automatic translation tool if needed. Use simple language structure when using mechanical translation. (2013)
 
William Roeder #:

The question makes no sense. Profit is just a sum.  Maximum profit requires multiple profits.

Until you can state your requirements in concrete terms, it can not be coded.

I am doing a hedging system. As long as I have left symbol ticket number, I can find right symbol ticket number. I need a way to store the max profit of the pair.

I need a data type, with left ticket number as the key.
 
Sunfire #:
I am doing a hedging system. As long as I have left symbol ticket number, I can find right symbol ticket number. I need a way to store the max profit of the pair.

I need a data type, with left ticket number as the key.

As William said it is a little hard to follow what you want, but my understanding is need a list of ticket numbers and profits held as pairs - as they are different types (ulong and double) a 2 dimensional array is not ideal (unless you want to cheat and store the ticket numbers as doubles, but that's messy).

So instead you can create a structure which can hold a ulong and double - a nice feature of structures is you can define methods inside them too.

If you need to hold many of these, like a table, you could put them in an array. 

Simple example attached:

//+------------------------------------------------------------------+
//|                                            428037-DataStruct.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"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
//https://www.mql5.com/en/forum/428037/

struct maxProfitStruc
  {
   ulong             ticketNo;
   double            profit;
   ulong             HedgeticketNo;
   double            Hedgeprofit;

   ulong             findMaxTicket()
     {
      if(profit >= Hedgeprofit)
        {
         return(ticketNo);
        }
      else
        {
         return(HedgeticketNo);
        }
     }

   double             findMaxProfit()
     {
      if(profit >= Hedgeprofit)
        {
         return(profit);
        }
      else
        {
         return(Hedgeprofit);
        }
     }

  };



//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   maxProfitStruc maxProfitArray[] = {};
   ArrayResize(maxProfitArray,10);

//E.g. how to access elements in row 0:
   maxProfitArray[0].ticketNo      = 123456789;
   maxProfitArray[0].profit        = -1.0;
   maxProfitArray[0].HedgeticketNo = 223456789;
   maxProfitArray[0].Hedgeprofit   = 2.0;
   
   PrintFormat("Ticket with max profit = %d $%+.2f",  maxProfitArray[0].findMaxTicket(), maxProfitArray[0].findMaxProfit());

  }
//+------------------------------------------------------------------+
 
R4tna C #:

As William said it is a little hard to follow what you want, but my understanding is need a list of ticket numbers and profits held as pairs - as they are different types (ulong and double) a 2 dimensional array is not ideal (unless you want to cheat and store the ticket numbers as doubles, but that's messy).

So instead you can create a structure which can hold a ulong and double - a nice feature of structures is you can define methods inside them too.

If you need to hold many of these, like a table, you could put them in an array. 

Simple example attached:

Thank you, your comprehesion power is very strong, despite my bad english words. You suggestion would work as well.


I modded this for for my purpose:

https://www.mql5.com/en/forum/170566#comment_4108666

Help please, array mangement question. MQL4 vs .Net - How to manage array management in C#?
Help please, array mangement question. MQL4 vs .Net - How to manage array management in C#?
  • 2017.02.18
  • www.mql5.com
Hello, i am bringing some of my indicators over from ninjatrader which are c# written and have a couple of questions regarding array management i am hoping someone can shed some light on. ) in c# i use "foreach" to search a double arrray to count how many times a particular double exists in the array