//+------------------------------------------------------------------+ //| gaps.mq4 | //| SFK Corp. | //+------------------------------------------------------------------+ #property copyright "SFK Corp." #property link "" //---- input parameters extern int min_gapsize = 1; extern double lotsize_gap = 0.2; //---- int magic = 12345; int cnt = 0; datetime order_time = 0; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int TotalOpenOrders() { cnt=OrdersTotal(); int TotalOpenOrders = 0; if(cnt==0) { return(0); } else { for(;cnt>=0;cnt--) { RefreshRates(); OrderSelect(cnt,SELECT_BY_POS); if(OrderMagicNumber()==magic) { TotalOpenOrders++; } } } return(TotalOpenOrders); } int start() { /* Thing to be done in future in this program to make it more efficient and more powerful: 1. Make the dicission of the quantity of lots used according to the scillators; 2. This program will catch the gaps. Things to ware of: 1. the spread; 2. excuting the order not on the gap ends a little bit less. */ // Defining the variables to decide. // Print("order time", order_time); double current_openprice = iOpen(Symbol(), PERIOD_M15, 0); double previous_highprice = iHigh(Symbol(), PERIOD_M15, 1); double previous_lowprice = iLow(Symbol(), PERIOD_M15, 1); double point_gap = MarketInfo(Symbol(), MODE_POINT); int spread_gap = MarketInfo(Symbol(), MODE_SPREAD); datetime current_time = iTime(Symbol(), PERIOD_M15, 0); // catching the gap on sell upper gap if( ( current_openprice > previous_highprice + (min_gapsize + spread_gap)*point_gap && current_time != order_time ) && TotalOpenOrders() == 0) { double tp = previous_highprice + spread_gap*point_gap; double delta = MathAbs(tp - Bid); if ( delta < 0.00060 ) { delta = 0.00060 - delta; tp = (previous_highprice + spread_gap*point_gap ) - delta ; } int ticket = OrderSend(Symbol(), OP_SELL, lotsize_gap, Bid, 0, 0, tp, "", magic, 0, Red); order_time = iTime(Symbol(), PERIOD_M15, 0); // Print("I am inside (sell) :-)", order_time); //---- if(ticket < 0) { Print("OrderSend failed with error #1", GetLastError()); Print ("erro venda " + Bid + " =>" + (previous_highprice + spread_gap*point_gap) ); } else { Print ("ok venda " + Bid + " =>" + (previous_highprice + spread_gap*point_gap) ); } } //catching the gap on buy down gap if( (current_openprice < previous_lowprice - (min_gapsize + spread_gap)*point_gap && current_time != order_time) && TotalOpenOrders() == 0 ) { double tp2 = previous_lowprice - spread_gap*point_gap; double delta2 = MathAbs(tp2 - Bid); if ( delta2 < 0.00060 ) { Print (" vai falhar ", delta2 ); delta2 = 0.00060 - delta2; tp2 = (previous_lowprice - spread_gap*point_gap ) +delta2; // Print (" vai falhar ", delta2 ); } ticket = OrderSend(Symbol(), OP_BUY, lotsize_gap, Ask, 0, 0, tp2,"", magic, 0, Green); order_time = iTime(Symbol(), PERIOD_M15, 0); // Print("I am inside (buy) :-)", order_time); if(ticket < 0) { Print("OrderSend failed with error #2", GetLastError()); Print ( "erro compra " + Ask + " =>" + (previous_lowprice - spread_gap*point_gap) ); } else { Print ( "ok compra " + Ask + " =>" + (previous_lowprice - spread_gap*point_gap) ); } } //---- return(0); } //+------------------------------------------------------------------+
Sample
Analysis
Market Information Used:
Series array that contains open prices of each bar
Series array that contains the highest prices of each bar
Series array that contains the lowest prices of each bar
Indicator Curves created:
Indicators Used:
Custom Indicators Used:
Order Management characteristics:
Checks for the total of open orders
It automatically opens orders when conditions are reached
Other Features: