extern double Lot=0.1,K_Martin=2,porog=0.8;
extern int TP=22,SL=20,Magic=233;
extern bool poz1_up=true;//ваш выбор:1-ая покупка или продажа(false)?
extern bool Trade=true;//торговля разрешить?
bool fix;int init(){fix=true;return(0);}int deinit(){return(0);}
int start(){double oop,ocp,osl,otp,ol,lotos;int closetime=0,lastorder=0,tip=0;if(!Trade)return(0);
if(poz1_up&&fix){OrderSend(Symbol(),OP_BUY,Lot,Ask,0,Ask-SL*Point,Ask+TP*Point,0,Magic,0,Blue);fix=0;}
if(!poz1_up&&fix){OrderSend(Symbol(),OP_SELL,Lot,Bid,0,Bid+SL*Point,Bid-TP*Point,0,Magic,0,Red);fix=0;}
for(int i=0;i<OrdersHistoryTotal();i++)
{if(!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))continue;
if(OrderMagicNumber()!=Magic)continue;
if(closetime<OrderCloseTime())lastorder=OrderTicket();}
if(OrderSelect(lastorder,SELECT_BY_TICKET,MODE_HISTORY))
{tip=OrderType();oop=OrderOpenPrice();osl=OrderStopLoss();
otp=OrderTakeProfit();ol=OrderLots();ocp=OrderClosePrice();}
Print("ОРДЕР №--[",OrderTicket(),"-",OrderLots(),"]--","цена открытия--[",OrderOpenPrice(),
"]--","цена закрытия--[",OrderClosePrice(),"]--","прибыль--[",OrderProfit(),"]");
if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES)==0)
{if(tip==OP_SELL){if(osl==ocp){lotos=ol*K_Martin;if(lotos>porog)lotos=Lot;
OrderSend(Symbol(),OP_BUY,lotos,Ask,0,Ask-SL*Point,Ask+TP*Point,0,Magic,0,Blue);}
if(otp==ocp)OrderSend(Symbol(),OP_SELL,Lot,Bid,0,Bid+SL*Point,Bid-TP*Point,0,Magic,0,Red);}
if(tip==OP_BUY){if(osl==ocp){lotos=ol*K_Martin;if(lotos>porog)lotos=Lot;
OrderSend(Symbol(),OP_SELL,lotos,Bid,0,Bid+SL*Point,Bid-TP*Point,0,Magic,0,Red);}
if(otp==ocp)OrderSend(Symbol(),OP_BUY,Lot,Ask,0,Ask-SL*Point,Ask+TP*Point,0,Magic,0,Blue);}}return(0);}
//+------------------------------------------------------------------+