//+------------------------------------------------------------------+ //| pinbar.mq4 | //| Copyright 2018, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2018, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict //--- input parameters extern double bmi=25.0; double tp=0; double sl=High[1]; double sl2=Low[1]; double lot=0.01; double orderStatus; double LowStoch=20; double HighStoch=80; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- bmi*=0.01; //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OpenBuyOrder(){ orderStatus = OrderSend(Symbol(),OP_BUY,lot,Ask,3,sl2,tp,"",0,0,Green); } void OpenSellOrder(){ orderStatus = OrderSend(Symbol(),OP_SELL,lot,Bid,3,sl,tp,"",0,0,Red); } void OnTick() { //--- double total = High[1]-Low[1]; double body = MathAbs(Open[1]-Close[1]); double maxSize = total*bmi; double stoch = iStochastic(NULL,0,14,3,3,MODE_SMA,0,0,0); if(OrdersTotal()>0){TrailStops() ;return;} if((body<=maxSize &&Open[1]Close[1]&&High[1]-Close[1]<=maxSize &&Low[1]Close[1]&&Open[1]-Low[1]<=maxSize &&High[1]>High[2]&&High[1]>High[3]&&Close[1]>HighStoch)||(body<=maxSize &&Open[1]High[2]&&High[1]>High[3]&&Close[1]>HighStoch)){ OpenSellOrder(); } } void TrailStops() { int trailingStop = 200; for (int i = 0; i < OrdersTotal(); i++) { if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { continue; } if (OrderSymbol() != Symbol()) { continue; } if(OrderType() == OP_BUY) { if (Bid - OrderOpenPrice() > trailingStop * Point && OrderStopLoss() < Bid - trailingStop * Point) { if (!OrderModify(OrderTicket(), OrderOpenPrice(), Bid - trailingStop * Point, OrderTakeProfit(), 0, Green)) { Print("OrderModify error ",GetLastError()); } return; } } else if(OrderType() == OP_SELL) { if(OrderOpenPrice() - Ask > trailingStop * Point && OrderStopLoss() > Ask + trailingStop * Point) { if (!OrderModify(OrderTicket(), OrderOpenPrice(), Ask + trailingStop * Point, OrderTakeProfit(), 0, Green)) { Print("OrderModify error ",GetLastError());} } } } } //+------------------------------------------------------------------+ //| Tester function | //+------------------------------------------------------------------+ double OnTester() { //--- double ret=0.0; //--- //--- return(ret); } //+------------------------------------------------------------------+ //| ChartEvent function | //+------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { //--- } //+------------------------------------------------------------------+