Custom loss function for regression

I am trying to write a custom loss function for a machine learning regression task. What I want to accomplish is following:

• Reward higher preds, higher targets
• Punish higher preds, lower targets
• Ignore lower preds, lower targets
• Ignore lower preds, higher targets

All ideas are welcome, pseudo code or python code works good for me.

This is what I tried so far, it does not work so well I think it is because it does not take high targets into account (just high preds):

def mae_high(inp, targ):
inp, targ = flatten_check(inp, targ)
thresh = np.percentile(inp.detach().numpy(), 50)