New order based on the previous order.

 
Please, somebody can explain as to do this and to give an example.

Which are the variables that I should use and how to write this code?

" If the last open order is with + 40 pips to open new order for the same side.
If the last order is it is with - 40 pips to open new order to the side opposite ".

Thank you

gess