[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 667

 
artmedia70:

Friends, I can't understand why it doesn't work:

If a position with magic 5100 is found in the loop, the loop must go to a new iteration:

... But this does not happen and the selected position with a 5100 magic number starts to participate in further calculations as the most losing one...

This is the locking one... And then, accordingly, another locking one is set on it...

Help me to understand where the dog is hidden...

That's all, thank you. I found the dog myself...
 

So far, I've worked with simple functions that result in a single output value.

Can the function output the values of several variables? For example: Time_1, High_1, Low_1, Time_2, High_2, Low_2.

Thank you!

 
chief2000:

Can a function output the values of several variables?


A function can only return one parameter, but nobody forbids a function to work with variables declared outside of the start() function(global variables).
 
DDFedor:

The function can return only one parameter, but no one forbids the function to work with variables declared outside of the start() function (global variables).


Let's take a simple Example - if [MA_1>=Ma_2], you should return the values Time_1, High_1, Low_1

for the bar at which the crossover occurred. This module in start() is

 
chief2000:


right?


But it must be taken into account that the values of such variables are relevant until the function is called again. therefore, the variables must be used IMMEDIATELY after the function is called. then the variables will contain the calculated values for THIS function call.
 
DDFedor:

But it must be taken into account that the values of such variables are relevant until the function is called again. therefore, the variables must be used IMMEDIATELY after the function is called. then the variables will contain the calculated values for THIS function call.

Yes, that's understandable. Thank you!

 
chief2000:

So far, I've worked with simple functions that produce a single output value.

Can the function output the values of several variables? For example: Time_1, High_1, Low_1, Time_2, High_2, Low_2.

And what prevents you from using parameter passing by reference rather than by value in function declaration? Example (Language Fundamentals/Variables/Formal Parameters):

It is possible to pass parameters by reference. In this case, modification of such parameters will affect the corresponding variables in the called function passed by reference. You cannot pass elements of arrays by reference. Parameters can be passed by reference only within the limits of a single module, such an opportunity is not provided for library functions. In order to specify that a parameter is passed by reference, the & modifier must be placed after the data type.

Example:

void func(int& x, double& y, double& z[]) { double calculated_tp; ... for(int i=0; i<OrdersTotal(); i++) { if(i==ArraySize(z)) break; if(OrderSelect(i)==false) break; z[i]=OrderOpenPrice(); } x=i; y=calculated_tp; }

Arrays can also be passed by reference, all changes will be reflected in the original array. Unlike simple parameters, arrays can also be passed by reference to library functions.

Note that func() is of void type, but its execution will change all three parameters declared outside it, since all three are provided with the & modifier. Including, by the way, the z[] array changes completely.
 
Mathemat:

And what prevents you from using passing parameters by reference rather than by value in the function declaration? Example (Language Fundamentals/Variables/Formal Parameters):

Note that the func() function has void type, but its execution will change all three parameters declared outside it, since all three are provided with the & modifier. Including, by the way, the z[] array changes completely.

Thank you very much!

 
How to do it ! If the last trade was unprofitable, you need to change the lot, if not, you don't)?
 
rovlent:
How to make so! If the last trade was unprofitable, we should change the lot, if not - no?)


For example like this

//=================================================
// Расчет размера позиции
//==================================================
double CalculateLots(){
   double Res=dLots;
   bool bProfit=true;
   int PrevTime=-1;
   double tmpLots;
   for (int i=0;i<OrdersHistoryTotal();i++){
      if (!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) continue;
      if (OrderSymbol()!=Symbol())                    continue;
      if (OrderMagicNumber()!=MAGIC)                  continue;
      if (OrderCloseTime()<PrevTime)                  continue;
      PrevTime=OrderCloseTime();
      if (OrderProfit()>0) bProfit=true; else bProfit=false;
      tmpLots=OrderLots();
   }
   double Lots_Step=MarketInfo(Symbol(), MODE_LOTSTEP);
   if (!bProfit) Res=tmpLots+Lots_Step;
   return(Res);
}

Increased by the step set by the DC. Although variants may be different

dLots - default position size

Reason: