[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 605

 
VAM_ 08.06.2010 18:48edit | delete

How do you mute it? Drove to the white knees. There are many tool windows (33). There are no EAs. Just middle and Zup. I can't figure out where it sings from. I am begging you to help. Service, events have been. The crosses on the events don't help. It's still singing, the bastard.

Techno:


starling can sit in the turkey )))

Looked through the code - no alerts anywhere! What to do?
 
VAM_:

Looked through the code - no alerts anywhere! What to do?

Check on PlaySound().
 
How can I make it possible to assign different values to a variable defined globally in the course of execution when calling different functions and it saves them?

I need to assign certain values to the variable Part, which is set globally, for the partial closing of a position, and pass it as a parameter to the function which executes the partial closing of the order. This variable is a simple divisor. In other words, if the value initially set to 1, the lot is divided by 1 and the entire position is closed. When the trade conditions change, this variable gets new values and can be equal to, say, 1.5 or 2, then the position lot is divided by this number, and the partial closing is performed. Function call with parameter passing looks like this verbatim:

// На глобальном уровне
double Part = 1;                           // на сколько разделить лот для частичного закрытия 
//..........

void ClosePartPosBySelect(double Part)    // Объявление функции
// ... тру-ля-ля ... тело функции ...
ll=NormalizeLot((OrderLots()/Part));      // рассчёт лота внутри функции
// ... дальнейший код ф-ции ...

//--------- Вызов функции частичного закрытия ---------
// Происходит из тела этой функции
void TrailingPositionsTLE(int MAGIC, int CloseMethod, double Part, int LastTrailing)
// таким образом:
if (CloseMethod==1)
            ClosePartPosBySelect(Part);

So, despite the fact that when the function is called ...

TrailingPositionsTLE(561, 1, 2, 1);

... CloseMethod = 1 (partial closure) is set and Part = 2 is explicitly specified, the function passes its initial value = 1 that was set globally instead of the Part value specified in the course of the program (e.g. 2)...

How do I defeat this? Thanks...

 
artmedia70: When trade conditions change, this variable gets new values and can equal, say, 1.5 or 2, then position's lot is divided by this number and partial closing is performed.


Well, when the trading conditions change, then change your Part variable. Or you have them in another EA? Then this variable has to be read all the time, i.e.

int init()

{

.....

GlobalVariableSet("Part0",Part);

.....

}

int start()

{

...

Part=StrToInteger(GlobalVariableGet("Part0"));

...

}

 
Roger:

Well, when the trading conditions change, then change your Part variable. Or you have them in another EA? Then this variable has to be read all the time, i.e.

int init()

{

.....

GlobalVariableSet("Part0",Part);

.....

}

int start()

{

...

Part=StrToInteger(GlobalVariableGet("Part0"));

...

}

No, the variable is in the same EA. It is globally defined and functions can use it, but its value, if changed inside functions, is not returned to external functions. Therefore, the functions see its value as set initially. If I do not set it at global level, then functions mate on the unsettled variable...
 

When you pass a variable to a function via its parameter, the variable is passed by value, which means that changing the variable in the function itself will not cause it to be overwritten.
Try passing it by reference by inserting an "&" in front of the parameter name

void simple(string &s){
//                 ^
//       спец сим. & перед именем переменной задает передачу по ссылке, а не по значению
//
}
 
VAM_:

Looked through the code - no alerts anywhere! What to do?

On the "Events" tab, uncheck the "Allow" box.

 

Hello Dear Professionals.

I would really like to write an EA which would open two Sell and Buy orders at the same time.

Then after a certain amount of points (parameter lim), the losing order would be closed,

and a profitable one will be closed when the price has fallen below the maximum price since the order was opened

(a kind of virtual trailing stop).

In agony I have created this, but it does not work... does not work

Please suggest something

int start()
  {
 
  double 
   max, min;                                            
  int b, s;
   if (Bid>max) max=Bid; 
    if (Ask<min) min=Ask;  
       if (OrdersTotal()>0)
       {                                   
           if ((max-Bid)>=lim*Point) 
           {                   
          OrderSelect(b,SELECT_BY_TICKET);                                  
          b=OrderClose(OrderTicket(),0.1,Bid,3,Blue);
          }
          
          
          if ((Ask-min)>=lim*Point)  
          {         
      OrderSelect(s,SELECT_BY_TICKET); 
      s=OrderClose(OrderTicket(),0.1,Ask,3,Red);
         }
}
else
{
  if (OrdersTotal()<1)
  {
 b=OrderSend(Symbol(),OP_BUY,0.1,Ask,5,0,0,"",5,0);
      
 s=OrderSend(Symbol(),OP_SELL,0.1,Bid,5,0,0,"",5,0); 
    }                           
   }
         return;

   return(0);
  }
 
artmedia70:
How to make it possible to assign different values to a globally defined variable at runtime when calling different functions and it saves them?

two ways

1. add an ampersant to the function where the value is changed,

e.g. void function( double& Part ){}

then, when a value inside the function is changed, the new value will return to the place of call

2. remove the variable from the parameter list of the function, since the variable is defined globally, its value can be changed in any place of the code without passing it as a parameter...

But to avoid confusion, the 1st variant is better, so as not to think what this variable is, as there can be more than one such globally defined variable (and within one function)...


I've glanced through the post, the answer has already been given...

 
artmedia70:
but its value, changed inside functions, is not returned to external ones.


Show the function itself.

If it is void ClosePartPosBySelect(double Part), change to

void ClosePartPosBySelect()

Reason: