[Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2. - page 486

 
abolk:

show me how you read the global_trailing_SP variable


At the moment, for the main position, the trailing value is calculated by ATR like this:

void Trailing_Stop_by_ATR_SP(int Timeframe,int Period_ATR_SP,double Multiply_SP,int digits_symbol,int Magic)
{  
   double High_1     = NormalizeDouble(iHigh(Symbol(),Timeframe,1),Digits);
   double Low_1      = NormalizeDouble(iLow(Symbol(),Timeframe,1),Digits);
   double atr        = iATR(Symbol(),Timeframe,Period_ATR_SP,1);
   double new_trail  = Low_1 + NormalizeDouble(((Multiply_SP*atr)*digits_symbol)*Point,Digits);
    
   for(int count = OrdersTotal()-1; count >= 0; count--)
      {  OrderSelect(count,SELECT_BY_POS,MODE_TRADES);
      
         if (OrderType() == OP_SELL && OrderMagicNumber() == Magic)
            {  double Op_Price = NormalizeDouble(OrderOpenPrice(),Digits);
               double Stp_Loss = NormalizeDouble(OrderStopLoss(),Digits);
               
               if (new_trail < Stp_Loss && new_trail > High_1)
                  {  
                     OrderModify(OrderTicket(),Op_Price,new_trail,0,0,White);
                  }
            }
      }
}
But there is no problem with this, as the main position is trailing without errors. The problem is to assign the same value to other position(s).
 
FOReignEXchange:

So I don't get it. Does the pending order exist at the time of modification of the main order?

If it exists, then the modification of the main order and modification of the pending order are in the same block. And if the main order is modified, the pending one should do the same, if that is your idea.

Another thing is that our idea does not work. That means a mistake in the condition. Try to do everything in the same way as in the condition for modification of the main order, as I have shown above. It seems to me that the error is in the logic. I am not surprised. Everything is very complicated here. It should be simpler.


It is quite possible that you should make it simpler. This is inexperience.)

At the moment it's like this, for the main position trailing in a separate function. Then, if there are pending orders or other positions with other majors, their values are checked against the stop of the main position. And if they are different, the value of the main is taken.

 
FOReignEXchange:

I'm not surprised. It's a bit complicated for you. You should keep it simple.

I've kept it simple. The problem seems to have disappeared so far. I have combined trailing for all positions. I will make modification of pending orders in a separate function. Thank you.)))
 
tol64:
I have made it simpler. The problem seems to have disappeared so far. Thank you.)))


What, is the pause modifiable or something? :)

The handwriting has to change. The clearer the handwriting, the fewer mistakes are made. Try not to cram everything into one pile, as few variables and other unnecessary things as possible. Always start braces on a new line to make blocks clearly visible.

 
FOReignEXchange:

What, did the trap modify or something?


Yes, in the above function, ATR trailing, I have excluded the Magic check and added a pause:

if (OrderType() == OP_SELL || OrderType() == OP_SELLSTOP) 
 
FOReignEXchange:


Handwriting has to be changed. The clearer the handwriting, the fewer mistakes are made. Try not to cram everything into one pile, with as few variables and unnecessary things as possible. Always write braces on a new line to make the blocks clearly visible.

Thanks for the tips. I engrave the best of them into my neurons.))
 
tol64:


Yes, in the above function, ATR trailing, I excluded the Magic check and added the pauses:


Yes. That's right, I was just about to say Magik. You see. No need for unnecessary variables. I'll see you later.
 
FOReignEXchange:

Yeah. That's right, I was going to say Magik. You see. No need for unnecessary variables. I'll see you later.


That's a wise idea. "No need for unnecessary variables."
No need for a magik-- why check the order for a magik?
If you modify an order from another EA, it will be OK.
You should exclude the magician as a class in general - its developers have wasted their time - and we have been brainwashed by all kinds of magicians.

p.s. And to the dancer, what's in the way is best trimmed.

 
abolk:


wise idea - "no need for extra variables"
and "no need for a magician" - why check the order for a magician?
modify an order from another advisor - no big deal.
exclude the magician as a class at all


)))) No, I think it would be better to leave the magician. You should just leave the pending orders.

To be more exact, we should leave those magicians that are needed. If we use several Expert Advisors on different charts, we should also include symbols in checking. But I have not come to this point yet. ))

 

I never use magicians at all. Although sometimes there are a few items at a time. I use tickets. It's much easier to check through OrderSelect. And the function OrderSend becomes clearer. Well, everyone is the master of his own handwriting. Personally, I have never had any problems without magicians.

Ticket never goes anywhere. It's convenient with it.

Reason: