Author: Zhydkov Roman
Price Data Components
Series array that contains the highest prices of each barSeries array that contains the lowest prices of each bar
Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt can change open orders parameters, due to possible stepping strategy
0 Views
0 Downloads
0 Favorites
breakdown
//+------------------------------------------------------------------+
//|                                                    breakdown.mq4 |
//|                                                    Arist0        |
//|                                              arist0.rr@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Zhydkov Roman"
#property link      ""

extern int    MagicNumber = 123456;
extern double min_lot = 0.01;
extern double max_lot = 10;
extern double risk = 50;         //ïðîöåíò èñïîëüçóåìûõ ñâîáîäíûõ ñðåäñòâ
extern double DIF = 0.0011;      //îòñòóï äëÿ âûñòàâëåíèÿ îðäåðîâ
extern double SL = 0.0025;       //StopLoss
extern double TP = 0.0025;       //TakeProfit
extern double TS = 0.00015;      //TakeProfit
extern double DTS = 0.0009;

//-- GlobalVariable
//double lot;
double pdb;
double pds;
string sym;
bool   exposed=false;

double calc_lot (string _sym){        //Calculate Lot size
   double _templ;
   _templ = AccountFreeMargin()*(risk/100)/(MarketInfo(_sym, MODE_BID)*1000);
   _templ = NormalizeDouble (_templ, 3);
   if (_templ < min_lot) _templ = min_lot;
   if (_templ > max_lot) _templ = max_lot;
   return (_templ);
}

void DeleteOrder (){                   // Delete Open Stop Orders
   int _total=OrdersTotal();
   for(int _pos=0;_pos<_total;_pos++){
      OrderSelect(_pos, SELECT_BY_POS, MODE_TRADES);
      if (OrderType()>1 && OrderMagicNumber() == MagicNumber)
         OrderDelete(OrderTicket());          
   }
}

int OpenOrderBuy (string _sym, double _lot, double _DIF, double _SL, double _TP){
   double _max, _prb;
   _max = iHigh(_sym,PERIOD_D1,1);
   _prb = NormalizeDouble(_max,6)+_DIF;
   return (OrderSend(_sym, OP_BUYSTOP, _lot, _prb, 5, _prb-_SL, _prb+_TP, "" ,MagicNumber, 0, Red));
}

int OpenOrderSell (string _sym, double _lot, double _DIF, double _SL, double _TP){
   double _min, _prs;
   _min = iLow(_sym,PERIOD_D1,1);
   _prs = NormalizeDouble(_min,6)-_DIF;
   return (OrderSend(_sym, OP_SELLSTOP, _lot, _prs, 5, _prs+_SL, _prs-_TP, "" ,MagicNumber, 0, Red));
}

int start(){
   sym = Symbol();
   if (Hour()==0 && exposed == false){
     double lot = calc_lot(sym);
     DeleteOrder();
     OpenOrderBuy (sym, lot, DIF, SL, TP);
     OpenOrderSell (sym, lot, DIF, SL, TP);
     exposed = true;
   }
   if (Hour()==23) exposed = false;
   int total=OrdersTotal();
   for(int pos=0;pos<total;pos++){
      OrderSelect(pos, SELECT_BY_POS, MODE_TRADES);
      if (OrderType()==0 && OrderMagicNumber() == MagicNumber){     //îðäåðà íà ïîêóïêó
         if (OrderOpenPrice()<(Bid-DTS)){
            double db = Bid - OrderOpenPrice();
            double tslb = Bid - OrderStopLoss();
            if (tslb>TS && db>TS){
               OrderModify(OrderTicket(),OrderOpenPrice(),(Bid-TS),OrderTakeProfit(),0,Blue);
            }
         }
      }
      if (OrderType()==1 && OrderMagicNumber() == MagicNumber){     //îðäåðà íà ïðîäàæó
         if (OrderOpenPrice()>(Ask-DTS)){
            double ds = OrderOpenPrice()-Ask;
            double tsls = OrderStopLoss()-Ask;
            if (tsls>TS && ds>TS){
               OrderModify(OrderTicket(),OrderOpenPrice(),(Ask+TS),OrderTakeProfit(),0,Blue);
            }
         }
      }
   }
   return(0);
}
//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---