Modify operation already open

 
#include<Trade\Trade.mqh>
//--- object for performing trade operations
CTrade  trade;

int SL = 10;
int TP = 90;

void buy(double a)
{
   trade.Buy(1,NULL,1,a+SL,price()+TP);
}

double price()
{
   return SymbolInfoDouble(_Symbol, SYMBOL_LAST);
}
This is the code I use to get into operation.


I have two questions:

1) It's correct? (it goes into operation correctly so I think it does, but recently I have been questioned about SYMBOL_BID and SYMBOL_ASK, so I don't know which of the 3 I should use)

2) I want to modify previously opened operations under certain conditions (I want to change SL), is it possible? In the documentation I found "PositionModify" referring to CTrade, but it requires a ticket, where do I find this ticket? How can I get the ticket of each operation I open?
 
Samuele Quaresima: I have been questioned about SYMBOL_BID and SYMBOL_ASK, so I don't know which of the 3 I should use)
   trade.Buy(1,NULL,1,a+SL,price()+TP);

You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit and open at the Ask.

  1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

  2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close to a specific Bid price, add the average spread.
              MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

  3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)
    Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY shows average spread = 26 points, but average maximum spread = 134 (your broker will be similar).

 
William Roeder #:

You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit and open at the Ask.

  1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

  2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close to a specific Bid price, add the average spread.
              MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

  3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)
    Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY shows average spread = 26 points, but average maximum spread = 134 (your broker will be similar).

Thank you. What I want for the second question is that the operation starts with a + SL of Stop Loss and that price () + TP of Take Profit, and so it is, what I have to add is an automatic modification of the stop loss in case they occur certain conditions. How can I select the operation to modify?