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

 
FAQ:


Eh, as the saying goes: "Study, student" (c).

Delete unnecessary (comment it out)


Thank you very much! I'm a lifelong learner, too! And in general, learning is more interesting than working. I'm going to try to adjust it now, I don't want to change the order in the code. At any time I change or add conditions depending on the changes in the market behavior. All the best to you and good night!
 
RMX13:

A piece of code which opens an order and sets stop loss and take profit

terminal generates the following errors: EURUSD,M30: OrderSend error 130

EURUSD,M30: invalid ticket for OrderModify function

EURUSD,M30: OrderModify error 4051

EURUSD,M30: OrderSend failed with error #4051 bid:1.23674000 ask:1.23683000 Open:1.23674000 SL:1.2423 TP:1.2283 MODE_STOPLEVEL:0.00000000 LOT:0.01000000

What is the problem can you tell?

RMX13, everyone has the same problem. To avoid error 130, you need to normalise all calculations with prices, lots and conditions, especially close to prices taking into account spread, stoplevel and freezevel, and slippage, which should be increased depending on volatility. Just asc doesn't need to be normalized, but if you add something to it, it needs to be with Digits, and lots with 2 (cents), etc. throughout the code, and of course error handling in all trading functions, so as not to bother the DC for nothing. Good luck!

See in Doc: OrderSend(Everything must match the contents in the set order)! That's why there are errors(:((

 

Dear FAQ! I use this if possible, but it does not suit me because of its immutability and, of course, my inexperience. For breaking even and further trawling I use dynamic methods with self-changing parameters, that's why I don't set tralestop or std. I also use stoploss if the connection is interrupted. That's why sometimes the slose from Mashka is delayed and SL is triggered. Errors are very rare because of the lack of "thickness"(granit77) of the EA, which I am constantly improving and adapting to the ever-changing market.

Thank you for your thoughtfulness!

I have made it and it has worked in my environment without errors in the tester. I will try it again tomorrow on Real.

  for(int j = OrdersTotal()-1; j >= 0; j--)
  {
    if(OrderSelect(j, SELECT_BY_POS, MODE_TRADES))
    {  
      if(OrderSymbol() != Symbol() && OrderMagicNumber() != Magic) continue;//фильтр по символу то пропускаем
      if(OrderCloseTime() != 0) continue;        //фильтр по времени закрытия (если не=0 то ордер уже закрыт)
      if(OrderType() == OP_BUY)
      {
        if(maFa0 < maFa1 && maSl0 < maSl1-clo*Point)
        {
          CloseOrder(OrderTicket(),OrderLots(),Bid,slip,Yellow);return(0);
      } }
      if(OrderType() == OP_SELL)
      {
        if(maFa0 > maFa1 && maSl0 > maSl1+clo*Point)
        {
          CloseOrder(OrderTicket(),OrderLots(),Ask,slip,Yellow);return(0);
  } } } }

I had to separate Close in a separate block. Thanks again!

Good morning!

As they say, it's better in the morning! All I needed was one line to check for orders that have just been closed:

      if(OrderCloseTime() != 0) continue;        //фильтр по времени закрытия (если не=0 то ордер уже закрыт)
I've merged everything and hope there are no more mistakes for that reason! Live and learn! All the best, including profit positivo!
 
borilunad:

RMX13, everyone has the same problem. To avoid error 130, you need to normalise all calculations with prices, lots and conditions, especially close to prices taking into account spread, stoplevel and freezevel, and slippage, which should be increased depending on volatility. Just asc doesn't need to be normalized, but if you add something to it, it needs to be with Digits, and lots with 2 (cents), etc. throughout the code, and of course error handling in all trading functions, so as not to bother the DC for nothing. Good luck!

See in Doc: OrderSend(Everything must match the contents in the set order)! That's why there are errors(:((

Thank you it is understandable.

And how to eliminate this " invalid ticket for OrderModify function "?

 
On Roboforex forum the moderators state that in MT4 tick volumes show the number of changes in bid price and that changes in ask price only are not reflected in tick volume. I was very surprised by this, as I thought that tick volumes reflect all price changes - both when only bid and ask changes, and when both prices change. But they are sure that they are right and ask why it is done so in MT4 and send to developers. Question to developers - are they really right and tick volume shows only a part of all price changes?
 

Can you explain me, please, where to start, what to do, what are the pitfalls.........or a link to read for beginners in forex?

 
RMX13:

Thank you, that's clear.

But how do I fix this " invalid ticket for OrderModify function "?


To do this, I need to run the same Select and in the same order before specifying the order type, as done in my code above, and then specify OrderTicket() in all trading functions.
 
NoBi4ok:

Can you explain me, please, where to start, what to do, what are the pitfalls.........or a link to read for beginners in forex?


If you are interested in trading, you have to download the Forex primer (you can find it in almost any dealing centre (DC) in the education section). If you are interested in Forex programming, then on top of every page of this site there is a link to the tutorial and documentation (reference book). But about the pitfalls you have to ask here for each case separately - for this stone must be encountered. Giving information without the context of personal practice is pointless: you will forget it immediately.
 
NoBi4ok:

Can you explain me, please, where to start, what to do, what are the pitfalls.........or a link to read for beginners in forex?


See above for all the blue recommended by the moderator! All very important to read and assimilate.
Reason: