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

 
hoz:



So I have a check for this case:

If stop - new stop (in b.u.) is not equal to zero... then we modify... If not, we don't modify. That's why it's not clear to me how this happens. After all, I understand that I need to check for equality of past and new stop and I've done it.

Here's a look at how I check from above and below when trawling without error for a bai:

          if(OrderStopLoss() > OrderOpenPrice())
          {
            if(NormalizeDouble(Bid-OrderStopLoss()-plus*tral,Digits) > prev)
            if(Bid > NormalizeDouble(OrderStopLoss()+plus*tral+prev,Digits))
            {
              SL = NormalizeDouble(OrderStopLoss()+plus*part*tral,Digits);
              ModifyOrder(OrderTicket(),OrderOpenPrice(),SL,OrderTakeProfit(),0,Blue);return(0);
          } }

I can give the ModifyOrder() function, good for all order and position modifications.

 
Vinin:

Edit this code so it doesn't look like a hack
I don't understand.
How do you edit it? What do you mean?
 
borilunad:
I would advise to modify it not by bars, but by so many pips. If necessary, this is what the resources are for. And the "no error" error pops up when the price is repeated for a modification that already exists. Therefore, you have to go step by step as I advised you at the beginning.


The B.U. is of course drawn by pips. I meant to call the B.U. function at every tick or at bar opening for example... But that would be silly. The price can jump a lot per bar. So, the call will be similar to the tickwise one, right? I was just thinking, maybe some condition should be added, so it won't be called at every tick. I think we should compare the current STOP and the one that is going to be set, sort of...

In general. What a strange thing to do.

I added a condition to start and it worked out that way:

if (priceBU != OrderStopLoss())
   {
       MovingStopLossToBU();
   }

Now there are no errors.

What I don't understand is that the MovingStopLossToBU() function itself changes only if the stop is not equal to Stop Loss:

if (ND(OrderStopLoss() - priceBU * pt) != 0.0)
    if (!OrderModify(OrderTicket(), OrderOpenPrice(), priceBU, OrderTakeProfit(), 0, CLR_NONE ))
    {
       Print ("Ошибка модификации ордера ", OrderType(), " - ", GetLastError());
    }
How do you understand it then?
 
Good evening, could you tell me how to colour the candles above the average MA(10) in green and below in red?
 
hoz:


The B.U. is of course drawn by pips. I meant to call the B.U. function at every tick or at bar opening for example... But that would be silly. The price can jump a lot per bar. So, the call will be similar to the tickwise one, right? I was just thinking, maybe some condition should be added, so it won't be called at every tick. I think we should compare the current STOP and the one that is going to be set, sort of...

In general. What a strange thing to do.

I added a condition to start and it worked out that way:

Now there are no errors.

What I don't understand is that theMovingStopLossToBU() function itself changes only if the stop is not equal to Stop Loss:

How do you understand it then?

In your example, when the stop is zero, that means you just opened a position without a stop. And I gave you the case when you're already at breakeven.

But look above, I gave you my trawl without breakeven! And I can give you the function.

 
agat8430:
I don't understand.
How to edit it ? how to understand it ?
Then you've come to the wrong place if you don't understand. Study what you don't understand, you'll ask. And if you don't understand anything, you don't need it.
 
borilunad:
See above, I gave you my error-free trawl! And I can give you the function.


I did not see your reply when I wrote. I'll take a look now.

But in general, I'd be happy to see your modification function, maybe I'll learn something new for myself.

 
borilunad:

In your example, when the stop is zero, it means you have just opened a position without a stop. And I gave you the case when it's already at breakeven.

See above, I gave you my trawl with no break-even! And I can give you the function.


No, not without a stop. I only posted a piece of it. Here's my breakeven function:

//+-------------------------------------------------------------------------------------+
//| Перевод в б.у. рыночных ордеров                                                     |
//+-------------------------------------------------------------------------------------+
void MovingStopLossToBU()
{
    double priceBU;
    int type = OrderType();
    for (int i=OrdersTotal() - 1; i>=0; i--)
    {
        if (!OrderSelect(i,SELECT_BY_POS)) continue;
        if (i_magic != -1) if (OrderMagicNumber() != i_magic) continue;
        if (OrderSymbol() != Symbol()) continue;
        if (OrderType() > 1) continue;
        
        RefreshRates();
        
        if (type == 0)
        {
           double price = Ask;
           int li_cmd = 1;
        }
        else
        {
           price = Bid;
           li_cmd = -1;
        }

           if (li_cmd * (price - OrderOpenPrice()) >= i_triggerForBU * pt)
           {
             priceBU = ND(OrderOpenPrice() + li_cmd * (i_preservedProfit * pt));
             if (ND(OrderStopLoss() - priceBU * pt) != 0.0)
             {

                 if (!OrderModify(OrderTicket(), OrderOpenPrice(), priceBU, OrderTakeProfit(), 0, CLR_NONE ))
                 {
                     Print ("Ошибка модификации ордера ", OrderType(), " - ", GetLastError());
                 }
               
                     Comment ("Ордер успешно переведён в безубыток");
                     Print ("Ордер успешно переведён в безубыток");
             }
           }
    }
}

In the line it is clearly seen that if the calculated stop is equal to the one that is already there, there will be no modification! Right? So the check originally was? But error 1 was constantly popping up, until I had entered another condition in the start before the modification function:

if (priceBU != OrderStopLoss())
   {
       MovingStopLossToBU();
   }
That's why.... that's what I'm trying to figure out. I think I've described everything thoroughly.
 
hoz:
Then you've come to the wrong place if you don't understand. Study what you don't understand, you'll ask. And if you don't understand anything, you don't need it.


If you do not understand anything, you don't need it. Well, tell me how to edit the code so it does not look hacked if you understand everything. It's my first time on the forum, and I got such a nice answer.

"Genius people have a genius answer."

 
agat8430:


Well then tell me how to edit the code that would not resemble a hack if you all understand. I came to the branch for beginners. I came on the forum for the first time on the forum and I got a nice answer.

"Genius people have a genius answer".

For newcomers first:

A forum navigator and answers to frequently asked questions. Highly recommended reading!( 1 2 3 4 5 6 ) 51 18.02.2011 FAQ

Reason: