Simple EA: Changes from long to short (vice versa) if trailing stop is reached

 

Hi Guys,

I can program EAs a little bit, so I copy and paste what I need and adjust it to match my requriments.

But there is one thing I could not find. I want an EA that is always in the market and only changes from long to short (or the other way) when a trailing stop is hit.

Can you give me a rough sketch how this has to be programed or do you maybe know an EA what has that?

Thanks, Sebastian

 

very rough...

orderselect history:
   latest order: 
      if(ordertype() == OP_BUY) if(ordercloseprice() == orderStoploss()) open short
      if(ordertype() == OP_SELL) if(ordercloseprice() == orderStoploss()) open long
hope this gives you some ideas atleast
 
int ReturnTypeOfLastOrderClosed()
   {
   int i=OrdersHistoryTotal()-1;
   //----
   OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
      {                                     
      int OT = OrderType();
      }
   return (OT);
   }
Reason: