Read an external constructed var value? - page 2

 

I think the OP needs to clarify his/her question. As WHRoeder and others are fond of saying: there are no mind readers here.

JJF, please provide the forum with more information regarding your question. For example, why is the external information (i.e., ticket numbers) needed and from where the information come from? Another example might be why you want the information in a certain way (i.e., string-based variables versus integer-based variables). These are just examples...please fill free to provide as much (or as little) additional information that you believe is necessary, but remember, the forums ability to help is proportional to the amount and specificity of the information you provide.

 
RaptorUK:

I think this is the key phrase . . .

"let say I place the constructed var name into to a "normal" var (string) called 'trade_x'"

Yes, I think you are right. the OP is apparently trying to de-reference the name as if it is a pointer. In these cases it probably means the actual problem hasn't been stated clearly enough so that a more standard solution can be chosen.
 
Greetings,

Well, the actual use is to exclude trades when I am looking to bail_out from a mix of profitable & non_profitable trades without 'harming' other 'long range' trades that I would like to keep.

So this is how it looks now:
  /*------------------+
  | Extern Variables  |
  +------------------*/
extern int    Exclude1      =  9999;   // 1st ticket to exclude from the profit count
extern int    Exclude2      =  9999;   // 2nd ticket to exclude from the profit count
extern int    Exclude3      =  9999;   // 3rd ticket to exclude from the profit count
extern int    Exclude4      =  9999;   // 4th ticket to exclude from the profit count
extern int    Exclude5      =  9999;   // 5th ticket to exclude from the profit count
extern double Bail_Out_SUM  =  5;      // the target sum ($$$) to Bail_Out for..

  /*----------------------+
  | expert start function |
  +-----------------------*/

int start()
  {
int       Exclude[6];
int       err, ticket;
string    note;

//-----------------
Exclude[1]=Exclude1;
Exclude[2]=Exclude2;
Exclude[3]=Exclude3;
Exclude[4]=Exclude4;
Exclude[5]=Exclude5;

for (int i = 1; i <= 5; i ++)
    {
    if (Exclude[i]==9999) continue;
    ticket=Exclude[i];
    OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES);
    .
    .
    .


Thanks for all the answers,

James
 
JJF:
Greetings,

Well, the actual use is to exclude trades when I am looking to bail_out from a mix of profitable & non_profitable trades without 'harming' other 'long range' trades that I would like to keep.

So this is how it looks now:

Thanks for all the answers,

James
Hey, I read your other thread, hope you don't get stop out this time:)
 

Now I really get it. Use MT4 GlobalVariable() - GV - like I've told you before. Write this script.

  int total = GlobalVariablesTotal();
   
  for (int pos = 1; pos <= total; pos ++)
    {
    string name   = GlobalVariableName(pos);
    if (StringFind (name, "Trade"+pos, 0) != 0) continue;
    int    value  = GlobalVariableGet (name);
    Alert (total," : ",pos,".",name," = ",value);
    Sleep (1000);
    }

Open MT4 > open GV window by press F3 > click "Add" button to create new GV > name it "Trade1" and set it's value > then do it again for "Trade2, Trade3, ... Trade16, Trade17, ... Trade100, Trade 101 ... .

Then run the script.

Nasty thing is, you have to delete, unused GV manually.

I never use F3 to fill the value of the GVs, I use script instead, so I can load the saved .set parameters. You resourceful guy, you figure that out.

:(

 
JJF:
Greetings,

Well, the actual use is to exclude trades when I am looking to bail_out from a mix of profitable & non_profitable trades without 'harming' other 'long range' trades that I would like to keep.

So this is how it looks now:


Thanks for all the answers,

James

Well the thing is that you are apparently having to type in the ticket numbers of the trades you wish to exclude. But that is an error prone unpleasant task. Some possibilities:

Give the "long range" trades magic numbers so they can be protected, or give the newer short term trades magic numbers so they can be selected. The idea is to get the computer to do the work.

Look at the start time of the trade and only include/exclude trades which are from long ago.

Use different lot sizes on "long range" trades compared to others eg 0.10 lots and 0.11 lots.


In terms of the coding

OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES);

When selecting by ticket the MODE_TRADES parameter is not actually doing anything and is better off left off so you realize that you can be selecting from the history pool as well. And make sure you check, and report the OrderSelect if it fails.

 
JJF:
Greetings,

Well, the actual use is to exclude trades when I am looking to bail_out from a mix of profitable & non_profitable trades without 'harming' other 'long range' trades that I would like to keep.

So this is how it looks now:


Thanks for all the answers,

James


You should do

#property show_inputs

to make sure the script pops up the inputs box before it runs

 
Hi dabbler,

My system picks the 'long range' automatically by choosing the lowest buy and the highest sell (separately for each pair or commodity).

Choosing by time is not good enough. A better 'long range' trade can be acquired later then an existing one.
Also, that is the reason why marking them by lot size can be misleading.

Beside, if I have to 'sacrifice' some of my 'less valuable' trades to ditch a mix of loosing and profiting trades (of different pairs, time and lot size) without a loss, I think I have to pick them manually.

You mentioned 'magic numbers' as a way to mark them automatically.
I saw that 'magic number' title before, but I couldn't figure out what they are good for.

James
 
JJF:

I saw that 'magic number' title before, but I couldn't figure out what they are good for.

The documentation is non-existent on that point. Basically a magic number is just an integer (whole number) that you can define for the purpose of identifying a particular trade type or more specifically an owner.

#define MAGICNUMBER  38942403

Every EA would use its own unique magic number and then the EA knows which trades "belong to it". The EA "thinks to itself", if the trade has a magic number of 38942403 then it is one that I placed and I have to decide what to do with it.

Read this ...

https://www.mql5.com/en/articles/1359

(just sections 1 and 2 will be enough)

 
Instead manually input them, why don't you create a script with YES/NO Message Box, iterating current trades, so you just simply click YES for particular ticket number and no for the other. The MessageBox must be very informative though, telling everything from lot size to profitable or not :)