Useful features from KimIV - page 8

 

There are a lot of questions...
I mean, they come up all the time, but on a case-by-case basis.

For those functions that are published now there are no questions, because I just look without "feel" in the unit.
Also, besides them, there are questions about earlier codes, in particular about trailing, which has something to do with
with above written: how, why to pass to functions, for example, this trailing section puzzled me:

//+------------------------------------------------------------------+
//| Перенос уровня StopLoss                                          |
//| Параметры:                                                       |
//|   ldStopLoss - уровень StopLoss                                  |
//+------------------------------------------------------------------+
void ModifyStopLoss(double ldStopLoss) {
  bool fm;
  fm=OrderModify(OrderTicket(),OrderOpenPrice(),ldStopLoss,OrderTakeProfit(),0,CLR_NONE);
  if (fm) PlaySound("expert.wav");
}
The role of ldStopLoss is unclear ...
 

oooo... :-) is such an ancient function. It was designed to change the stop level of an open position or a set order. There was also a similar function for take profit. They were both replaced by a better and more functional ModifyOrder().

kombat:
The role of ldStopLoss is unclear ...

This is a local variable, by means of which the price level, at which StopLoss should be set, is passed to the ModifyStopLoss function. For example, let's call the ModifyStopLoss function like this:

ModifyStopLoss(1,5662);

Then the local variable ldStopLoss will take the value 1.5662. You can check it this way:

//+------------------------------------------------------------------+
//| Перенос уровня StopLoss                                          |
//| Параметры:                                                       |
//|   ldStopLoss - уровень StopLoss                                  |
//+------------------------------------------------------------------+
void ModifyStopLoss(double ldStopLoss) {
  bool fm;
 
  Print("ldStopLoss=",ldStopLoss);
 
  fm=OrderModify(OrderTicket(),OrderOpenPrice(),ldStopLoss,OrderTakeProfit(),0,CLR_NONE);
  if (fm) PlaySound("expert.wav");
}

The log will contain this record:

<Время> <Эксперт> <Инструмент>,<таймфрейм>: ldStopLoss=1.5662
 
KimIV:

oooo... :-) is such an ancient function. It was designed to change the stop level of an open position or a set order. There was also a similar function for take profit. They were both replaced by more perfect and functional ModifyOrder().


So... ancient ... (sort of embarrassed :)))
I've glancing through the folders, the oldest file is dated 22.01.2006.
And it looks like it wasn't even tampered with by my cranks...
I'm sorry, I've been practicing simple things for a long time, e.g. change a number.
Simple calculators, etc...

All this started with a request to write an Expert Advisor on one of the PRDC forums, but...
My cents are not enough, but I have to use them on my own, and then I need an indicator that displays information on charts.
Now I'm addicted to it... ;) me? It's convenient... everything's there... unitor, etc, compact, portable.

I remember my first and last attempt at Delphi 6... I shudder.
I still have a couple of those disks on the shelf... :))) sorry for the offtop.


So, what 's inside the brackets of function(), is it some kind of "form" to pass some parameters to it?


Because I've got it in my head for some reason that it is a parameter which the function returns as a result of processing.
And it's also that the function gets parameters to be processed inside curly brackets...{}

void TrPos() {
if (OrderType()==OP_BUY) {
    if ( (Bid-OrderOpenPrice())>TrailingStop*Point) {
      if (OrderStopLoss()<Bid-TrailingStop*Point) {
        ModifyStopLoss(Bid-TrailingStop*Point);
        return;
      }
    }
  }
// в качестве примера !!! просто выдраный кусок кода!

I.e. all these Bid, Point and so on are input parameters.

I must have been wildly mistaken... And what is inside braces() allows passing parameters to a function,
while the function itself can be located in any (or other) place of the script proper code...

Right?

 
The question is why, unlike OpenPosition, there is no error handling in ModifyOrder? There are all sorts of errors during modification as well. I would like to have separate functions for Installation, Modification and Closing, and a separate Error Handling Unit for all - less code, easier to write, and it would work faster... If I'm wrong, correct me...
 
Good day, Igor! I have problems using your EAs and scripts using trawls of any form on my real account (Alpari DC). Especially I am interested in e-News-Lucky$ (ideal for my system), e-TFL_v2, Set2StopOrders, e-SotTrailing. It works on demo (also Alpari). No error messages. What may it be? And one more question. How to disable time binding in e-News-Lucky$ to enter and exit at any time? Thank you!
 
ag-forex писал (а):
Good day, Igor! I have problems using your EAs and scripts using trawls of any form on my real account (Alpari DC). Especially I am interested in e-News-Lucky$ (ideal for my system), e-TFL_v2, Set2StopOrders, e-SotTrailing. It works on demo (also Alpari). No error messages. What can it be?
The problem has been solved many times by contacting technical support of this brokerage company.
 
kombat писал (а):
So, what' s inside the brackets of function() is a kind of "form" for passing it some parameters?

Yeah... sort of like a container :-)

kombat wrote (a):
Because for some reason I've got the opposite in my head: this is the parameter that the function returns as a result of processing.

What the function returns is the return value. Here is a simple example. We define a function that adds two numbers:

int f(int a, int b) {
  int x;
  x=a+b;
  return(x);
}

Now, if we call this function like this:

int y;
y=f(3, 5);

then the numbers 3 and 5 are the parameters of the function f. The parameters of the function can be numbers, variables, or expressions. Variables a and b are local variables that take the values of the parameters and give them to the function. The variable x is the return value of the function f, i.e. after our call to the function f, the variable y will take the value passed to it by the variable x, i.e. 8.

kombat:

And also the fact that the function receives parameters to be handled inside curly brackets...{}

void TrPos() {
if (OrderType()==OP_BUY) {
    if ( (Bid-OrderOpenPrice())>TrailingStop*Point) {
      if (OrderStopLoss()<Bid-TrailingStop*Point) {
        ModifyStopLoss(Bid-TrailingStop*Point);
        return;
      }
    }
  }
// в качестве примера !!! просто выдраный кусок кода!

i.e. all these Bid, Point and so on are the input parameters.

no... the ModifyStopLoss function's parameter will be the value of the Bid-TrailingStop*Point expression.

kombat:

I must have made a wild mistake... and what is in brackets() allows to pass parameters to be processed in the function,
the function itself can be located in any (or other) place of the script's code itself...

Right?

yes

 
sasa999:
The question is - why, unlike OpenPosition, ModifyOrder has no error handling?

I've heard it said somewhere that the rules of the road were written in blood. And there is nothing superfluous in them. Behind every word there is almost a life lost in an accident.

I write my functions, in accordance with my experience, and include processing of errors that have occurred in my practice, and there is no way to do without it. I try to be as "polite" as possible (error handling) when trying to enter the market. During modification, most of errors are eliminated by normalization of prices and simple checks of values. If some error occurs during modification, it is OK on the next tick. The same happens at closing.

 

What is the purpose of sending pp - opening price of the order to this function?

void ModifyOrder(double pp=-1, double sl=0, double tp=0, color cl=CLR_NONE)

It's like the colour is already set at the beginning ... test_ModifyOrder.mq4 (12.14 KB) ... why don't you use it, but re-send it to the function

color clModifyBuy = Aqua; // Цвет значка модификации покупки
color clModifySell = Tomato; // Цвет значка модификации продажи
what is the advantage of
int dg=MarketInfo(OrderSymbol(), MODE_DIGITS), er, it;
pp=NormalizeDouble(pp, dg);

before short form

pp=NormalizeDouble(pp, Digits);

why do you need to normalize OrderOpenPrice()? isn't it in the same format as in the order?

op=NormalizeDouble(OrderOpenPrice() , dg);
So far, I haven't noticed any errors if the same thing is inserted when modifying. same with OrderStopLoss(), and OrderTakeProfit()
 
sasa999:

What is the purpose of sending pp - opening price of the order to this function?

void ModifyOrder(double pp=-1, double sl=0, double tp=0, color cl=CLR_NONE)

The orders OP_BUYLIMIT, OP_BUYSTOP, OP_SELLLIMIT and OP_SELSTOP will be moved.

sasa999:

The colour is also sort of already defined at the beginning... test_ModifyOrder.mq4 (12.14 KB) ...why do not use it, and re-send to the function

color clModifyBuy = Aqua; // Цвет значка модификации покупки
color clModifySell = Tomato; // Цвет значка модификации продажи

Thank you! I will use it!

sasa999:
what is the advantage
int dg=MarketInfo(OrderSymbol(), MODE_DIGITS), er, it;
pp=NormalizeDouble(pp, dg);

before a short form

pp=NormalizeDouble(pp, Digits);

The versatility which allows the EA to work with positions and orders not only for the current symbol, but also for other symbols. For example, the EA works on the EURUSD chart. A variant with Digits will not allow working with positions opened on USDJPY.

sasa999:

Why does the OrderOpenPrice() need to be normalised?

op=NormalizeDouble(OrderOpenPrice() , dg);

It is in order to successfully compare values of the double type. If it's not normalized, the comparison is impossible or rather meaningless.

sasa999:
Didn't notice an error if you put the same back in when modifying. same with OrderStopLoss(), and OrderTakeProfit()
Without normalisation, the function generates error 1(OrderModify tries to change already set values with the same values).