[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 19

 
Good day to all. I need a robot that will keep track of trades and create a pending order at close by takeprofit to replace a closed one with the same parameters as a closed one. Can such a robot be implemented? I have never used one before. If you have one somewhere, please give me a link. Thank you in advance.
 
Previously, the profit close was in the currency of the deposit and was calculated as
double Lot = 0.1;
int KoffProfit = 10;
ProfitValue = Lot * KoffProfit * MarketInfo(Symbol(), MODE_TICKVALUE); 
how to convert this formula to points?
 

I'm wondering how to optimise the code to speed up the owl in the tester. Can you please tell me how to execute the loop faster, like this:

for (int i = OrdersTotal() - 1; i >= 0; i--) {
   if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES))  continue; 
   if (OrderSymbol() != Symbol())                    continue;    
   if (OrderMagicNumber() != Magic)                  continue;
   
   // работаем с ордерами      
}

or like this:

for (int i = OrdersTotal() - 1; i >= 0; i--) {
   if (OrderSelect(i, SELECT_BY_POS)) {
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) {
      // работаем с ордерами
      }
   }
}

and any other tips for speeding up the EA?

 
T-G: Previously, closing on profit was in the deposit currency and counted like this
how to convert this formula to points?
This formula makes no sense to change, it's easier to find the necessary order (OrderSelect()) and calculate (OrderOpenPrice()-Bid)/Point ( or OrderOpenPrice()-Ask) and get how many pips the order already has
T-G:and are there any other tips for speeding up the EA?

In mql4 there is a full check of conditions, i.e. all expression that is in brackets if() will be checked to the end, so sometimes it's reasonable to break complex conditions into several conditions:

if(a>b && c>d) can be replaced with if(a>b){ if (c>d)..... }

So the first variant of the code proposed by you will work a bit faster, though from practice - the enumeration of orders does not load the processor much, mathematical operations load the processor much, it makes sense to look for increasing the code performance - not all calculations have to be performed every tick

 
IgorM:

In mql4 there is a full check of conditions, i.e. all expression which is in brackets if() will be checked to the end, so sometimes it is reasonable to break complex conditions into several conditions:

if(a>b && c>d) can be replaced with if(a>b){ if (c>d)..... }

So the first variant of the code you suggest will work a bit faster, though from practice - order search does not load the processor much, mathematical operations load the processor much, it makes sense to look for increasing the code performance - not all calculations need to be performed every tick

I see. Thank you:

Rez = OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Bid, Digits), iSlippage, Blue);
if (Rez) Comment("Закрыт ордер # ", OrderTicket(), "  прибыль ", OrderProfit());

or the same normalization in the conditions:

if (NormalizeDouble(dOrderOpenPriceBuyStop - StepTral * Point, Digits) > NormalizeDouble(Ask + Step * Point, Digits))

slows down the execution of EAs a lot?

 
T-G: or the same normalisation in conditions:

slows down the execution of EAs much?

Try to check it yourself with GetTickCount(), create a script and run normalization once 10 000 times and run it twice 10 000 times, then you can assess how useful it is for you to look for code sections where normalization is often run. About Print() I even find it hard to answer - will you be outputting Pronta every tick? Usually the output operations slow down the Expert Advisor significantly, the scripts with Comment() run 10 times longer than without output, but then again, the question is about expediency - if you have to, you have to.
 
T-G:

I see. thank you. but tell me Print for example after closing an order:

or the same normalization in the conditions:

slows down significantly the execution of EAs?

The Print() operation is an operation with a file (in this case, a log file). And these operations are VERY slow (compared to processing data from memory). CONCLUSION: Create a variable which is initialized in init()

bool gb_VirtualTrade;
init()
{
    gb_VirtualTrade = (IsOptimization() || (IsTesting() && !IsVisualMode));
}

And print by condition of this variable (this is ONE option).

The normalization example you have given makes no sense, if we proceed from the stated objectives (code optimization). Normalization is REQUIRED according to the technical requirements of the brokerage server, in order to execute a trade order ONLY for price and STOP.

 
Hello, when an Expert Advisor opens a position, should I write in its code an indicator (condition) based on the signals of which it opens an order or should I write in the Expert Advisor the path to the window of a financial instrument with indicators installed?
 

Dear speculators, help! Looking for an EA which automatically sets SL and TP when opening a position.

I am very grateful in advance.

 
Good afternoon. If anyone knows where you can download a ZIGZAG indicator that marks the point at which a new beam appears (e.g. in a different colour). If there is one at all...
Reason: