Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1610

 
Vitaly Muzichenko #:

Can you tell me how to shorten the construction?

The point is to cut off pairs that already have a symbol in them

I have a position on USDCHF

===

There is a position on EURGBP, the signal came from AUDUSD - how can we detect that there is no position on AUD or USD ?

Valery's thinking is correct. But I do not understand why we should identify the currency we are looking for in the order currencies at each iteration of the cycle? And it seems easier to me to take the margin currency and profit currency instead of looking in the line. Look at the currency specification... I would do this

bool Search(string _sy)
 {
  int OT = OrdersTotal();
  string curencyProfit = SymbolInfoString(_sy, SYMBOL_CURRENCY_PROFIT),
         currencyMargin = SymbolInfoString(_sy, SYMBOL_CURRENCY_MARGIN);
  for(int i = 0; i < OT; i++)
   {
    if(OrderSelect(i, SELECT_BY_POS))
     {
      bool res = StringFind(OrderSymbol(), curencyProfit) >= 0 ||
                 StringFind(OrderSymbol(), currencyMargin) >= 0;
      if(res)
        return(true);
     }
   }
  return(false);
 }/******************************************************************/
 
Valeriy Yastremskiy #:

StringFind

I think there should be 2 lines, searching both 0 and 3 positions. To cut off a random match in the middle.

SZ

Dumb, there are 4 conditions.

Not equal A B and not equal C D

condition A==C or A==D or B==C or B==D

I don't think anyone could write it)))

Dumb at the second attempt. Apparently the time has come in the evening.

 
Vitaly Muzichenko #:

Can you tell me how to shorten the construction?

The point is to cut off pairs that already have a symbol in them

I have a position on USDCHF

===

There is a position on EURGBP, the signal came from AUDUSD - how to detect that there is no position on AUD or USD ?

I would collect all open order currencies in an array and go through the array upon receiving the signal.

 
Alexey Viktorov #:

Valeri has the right direction of thought. But I don't understand why we need to define the currency we are looking for in the order currencies at each iteration of the cycle? And I think it's easier to take the margin currency and profit currency instead of looking in the line. Look at the specification for currencies ... I would do so

I will check it tomorrow.


Taras Slobodyanik #:

I would collect all open order currencies in an array and look through the array upon getting a signal.

The idea is the same, but you also need an array

 

you can also set a magic 1 = AUD, 2 = EUR.... for each currency and compare magics,

about the arrays, imho, it is rational, now 3 currency pairs 4 conditions, tomorrow 33 currency pairs 34 conditions?

 
Vitaly Muzichenko #:

I'll check it tomorrow.


The point is the same, but you also need an array

Why wait until tomorrow? If you're too lazy to look through the specifications, run the script through all the symbols of interest and find a match for margin currency and profit currency.
/********************Script program start function*******************/
void OnStart()
 {

  Comment(SymbolInfoString(_Symbol, SYMBOL_CURRENCY_PROFIT), "\n",
          SymbolInfoString(_Symbol, SYMBOL_CURRENCY_MARGIN)
         );
 }/******************************************************************/
I didn't check everything before writing, but I didn't find any matches...
 
Vitaly Muzichenko #:

The meaning is the same, but you also need an array

Well, the point is quick - took the currency code, made a search using a ready-made array, which is updated when a trade is opened.

 

Help with the code. I need the pending order to move with opening of a new bar on the trend line.

I.e. it would be a permanent crossing of the order and the line.

We should know the crossing point of the trend line and time in order to make it shift. How to calculate it?

 
Zalevsky1234 pending order to move with opening of a new bar on the trend line.

I.e. it would be a permanent crossing of the order and the line.

We should know the crossing point of the trend line and time in order to make it shift. how to calculate it?

Here is the function for calculating the intersection point
 

Question about static variable var of X::doJob() method. There's a class U which creates an object of type X, does some work and then destroys it. And this happens periodically. Question: when is the var variable deleted?


class X {
public:
   void doJob() {
      static int var = 0;
   }
};

class U {
private:
   X *x;
public:
   U(){

   }
   ~U() {
      delete x;
   }
   void U::dojob(){
      x = new X();
      x.doJob();
      delete x;
   }
};