Orders Execution
Indicators Used
0
Views
0
Downloads
0
Favorites
BullDozer
//+------------------------------------------------------------------+
//| BullDozer.mq4 |
//| Copyright © 2011, Serg Deev |
//| http://www.work2it.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, Serg Deev"
#property link "http://www.work2it.ru"
#define MAGICMA 20050610
extern double Lots = 0.05;
extern int TrailingStop = 0;
extern int fast_ema_period = 22;
extern int fast_ema_shift = 9;
extern int fast_ema_method = 2; // 0-MODE_SMA; 1-MODE_EMA; 2-MODE_SMMA; 3-MODE_LWMA;
extern int fast_ema_price = 2; // 0-PRICE_CLOSE, 1-PRICE_OPEN, 2-PRICE_HIGH, 3-PRICE_LOW, 4-PRICE_MEDIAN, 5-PRICE_TYPICAL, 6-PRICE_WEIGHTED
extern int slow_ema_period = 66;
extern int slow_ema_shift = 0;
extern int slow_ema_method = 3; // 0-MODE_SMA; 1-MODE_EMA; 2-MODE_SMMA; 3-MODE_LWMA;
extern int slow_ema_price = 3; // 0-PRICE_CLOSE, 1-PRICE_OPEN, 2-PRICE_HIGH, 3-PRICE_LOW, 4-PRICE_MEDIAN, 5-PRICE_TYPICAL, 6-PRICE_WEIGHTED
extern double AO_Min = 0.0;
extern int AO_OpenTime = 5;
extern int AO_CloseTime = 7;
int GAP_Level = 30;
int GAP_TimeOUT = 100;
int GAP_Timer = 0;
//+------------------------------------------------------------------+
int CalculateCurrentOrders(string symbol)
{
int buys=0,sells=0;
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
{
if(OrderType()==OP_BUY) buys++;
if(OrderType()==OP_SELL) sells++;
}
}
if(buys>0) return(buys);
else return(-sells);
}
//+------------------------------------------------------------------+
bool CheckAO_Up(int t) {
double y;
double x = iAO(NULL, 0, t);
for (int i=t-1; i>=0; i--) {
y = iAO(NULL,0,i);
if (y < x) return(false);
else x = y;
}
return(true);
}
//+------------------------------------------------------------------+
bool CheckAO_Down(int t) {
double y;
double x = iAO(NULL, 0, t);
for (int i=t-1; i>=0; i--) {
y = iAO(NULL,0,i);
if (y > x) return(false);
else x = y;
}
return(true);
}
//+------------------------------------------------------------------+
void CheckForOpen() {
int res;
if(Volume[0]>1) return;
int gap = (Open[0]-Close[1])/Point;
if (gap > GAP_Level) GAP_Timer = GAP_TimeOUT;
if (GAP_Timer > 0) {
GAP_Timer--;
if (GAP_Timer > 0) return;
}
double ma_fast=iMA(NULL,0,fast_ema_period,fast_ema_shift,fast_ema_method,fast_ema_price,0);
double ma_slow=iMA(NULL,0,slow_ema_period,slow_ema_shift,slow_ema_method,slow_ema_price,0);
double ao = iAO(NULL, 0, 0);
if (ma_fast < ma_slow) {
if ((Close[1] < ma_fast) && (ao < -1*AO_Min)) {
if (CheckAO_Down(AO_OpenTime)) {
res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"",MAGICMA,0,Red);
return;
}
}
}
if (ma_fast > ma_slow) {
if ((Close[1] > ma_fast) && (ao > AO_Min)) {
if (CheckAO_Up(AO_OpenTime)) {
res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"",MAGICMA,0,Blue);
return;
}
}
}
}
//+------------------------------------------------------------------+
void CheckForClose() {
int res;
double SL;
double ma_fast=iMA(NULL,0,fast_ema_period,fast_ema_shift,fast_ema_method,fast_ema_price,0);
double ma_slow=iMA(NULL,0,slow_ema_period,slow_ema_shift,slow_ema_method,slow_ema_price,0);
for(int i=0;i<OrdersTotal();i++) {
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
//---- check order type
if(OrderType()==OP_BUY) {
if (CheckAO_Down(AO_CloseTime)) { // óñëîâèå çàêðûòèÿ
OrderClose(OrderTicket(),OrderLots(),Bid,3,White);
break;
}
else if (TrailingStop > 0) { // TrallingStop
if (OrderStopLoss() == 0.0) OrderModify(OrderTicket(),OrderOpenPrice(),Low[0]-Point*TrailingStop,OrderTakeProfit(),0,Blue);
else {
SL = Low[0]-Point*TrailingStop;
if (OrderStopLoss() < SL) OrderModify(OrderTicket(),OrderOpenPrice(),SL,OrderTakeProfit(),0,Blue);
}
break;
}
}
if(OrderType()==OP_SELL) {
if (CheckAO_Up(AO_CloseTime)) { // óñëîâèå çàêðûòèÿ
OrderClose(OrderTicket(),OrderLots(),Ask,3,White);
break;
}
else if (TrailingStop > 0) { // TrallingStop
if (OrderStopLoss() == 0.0) OrderModify(OrderTicket(),OrderOpenPrice(),High[0]+Point*TrailingStop,OrderTakeProfit(),0,Blue);
else {
SL = High[0]+Point*TrailingStop;
if (OrderStopLoss() > SL) OrderModify(OrderTicket(),OrderOpenPrice(),SL,OrderTakeProfit(),0,Blue);
}
break;
}
}
}
}
//+------------------------------------------------------------------+
int init() {
return(0);
}
//+------------------------------------------------------------------+
int deinit() {
return(0);
}
//+------------------------------------------------------------------+
int start() {
if(Bars<100 || IsTradeAllowed()==false) return;
if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();
else CheckForClose();
}
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---