MQL4 Code help???

 

I can't seem to figure this out, what would be the MQL4 code for this pseudocode?

It's a function that will stop an EA from making a SELL if the LAST TRADE was a SELL AND A LOSS. As well as stopping a BUY if the LAST TRADE was a BUY AND A LOSS .

It should check the LAST TRADE whether it was a buy or sell....

Function Bool ConfirmOrder(int TradeSignal){

bool confirm_signal;

int order_type;

If TradeSignal = 0 THEN order_type = OP_SELL;

If TradeSignal = 1 THEN order_type = OP_BUY;

Check Trading History for the LAST CLOSED TRADE ()

If (LAST CLOSED TRADE was a LOSS && OrderType() = order_type){

THEN confirm_signal = false;

}

return the confirm_signal ;

}

Please can someone help me on what the MQL4 code would look like?

 
//THIS IS THE CODE I HAVE SO FAR BUT IT ONLY SEEMS TO BE BRINGING OUT NO SIGNAL AT ALL WHICH RESULTS IN A 0 SIGNAL FOR SELL IN THE LATTER FUNCTION (NOT INCLUDED)

int LastClosedTrade(int p_signal){
    bool go_ahead = true;

    
    if(p_signal==0){ int p_type=OP_SELL;}
    if(p_signal==1) {p_type=OP_BUY;}
for(int i=OrdersHistoryTotal()-1;i>=0;i--)
 {
   OrderSelect(OrdersHistoryTotal()-1, SELECT_BY_POS,MODE_HISTORY);
   if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic_number && OrderProfit()<0)
    {   
        go_ahead = false; // DON'T trade, stay out
    }
  }
    return (go_ahead);
}
PLEASE HELP
Reason: