- Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6.
- What I would like from the "terminal" as a professional programmer. Another thread with wishes for MQL5.
- Questions from Beginners MQL5 MT5 MetaTrader 5
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)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.
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()); } //+------------------------------------------------------------------+
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
- 2017.02.18
- www.mql5.com
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use