Track order that was closed with tp/sl?

 
I have the following code in mql4 and it is partially working but having an issue with order tracking.
int ticket;
void OnTick(){

    ... not included code, setting variables, etc ...

    if(tenkan_sen < kijun_sen){
        comment += "\nSHORT!";
        if(OrderSelect(ticket,SELECT_BY_TICKET) && OrderType() == OP_BUY){
            if(OrderClose(OrderTicket(),OrderLots(),Bid,1000,clrCrimson)){
                ticket = 0;
            }
        }
        if(ticket <= 0){
            // need to set stoploss and takeprofit prices
            double short_tp = current_close - (atr*6);
            double short_sl = current_close + (atr*2);
            ticket = OrderSend(_Symbol,OP_SELL,0.01,Bid,1000,short_sl,short_tp,"This is a sell",1,0,clrPink);
        }
    } else if(tenkan_sen > kijun_sen){
        comment += "\nLONG!";
        if(OrderSelect(ticket,SELECT_BY_TICKET) && OrderType() == OP_SELL){
            if(OrderClose(OrderTicket(),OrderLots(),Ask,1000,clrPink)){
                ticket = 0;
            }
        }
        if(ticket <= 0){
            // need to set stoploss and take profit prices
            double long_tp = current_close + (atr*6);
            double long_sl = current_close - (atr*2);
            ticket = OrderSend(_Symbol,OP_BUY,0.01,Ask,1000,long_sl,long_tp,"This is a buy",1,0,clrCrimson);
        }
    }
}

This was previously based on the logic of closing the previous position upon opening the last position, it was working as expected before i added the sl and tp values. I am not sure how i should reset the ticket variable to 0 in the event of a sl or tp, or if there is a different way i should be handling this.

 
Use the </> button to insert your code.
 

Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
          General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
          Messages Editor

 
Eleni Anna Branou #:
Use the </> button to insert your code.
Done, thanks
 
  1. Andrew Terhune: but having an issue with order tracking.

    Do you really expect an answer? There are no mind readers here and our crystal balls are cracked. What issue?
         How To Ask Questions The Smart Way. (2004)
              Be precise and informative about your problem

  2. double long_tp = current_close + (atr*6);
    double long_sl = current_close - (atr*2);
    ticket = OrderSend(_Symbol,OP_BUY,0.01,Ask,1000,long_sl,long_tp,"This is a buy",1,0,clrCrimson);

    Why are your TP/SL relative to some variable instead of the Bid?

  3. Check your return codes, and report your errors (including market prices and your variables). Don't look at GLE/LE unless you have an error. Don't just silence the compiler (MT5/MT4+strict), it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 programming forum (2012)
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles (2014)

Reason: