Download MetaTrader 5
To add comments, please log in or register
Sell products right in MetaTrader. Millions of traders are waiting for this!
Alessandro Surdo
134
Alessandro Surdo 2014.02.19 11:41 
hello, I ask help with a simple EA, to open a position when there is a gap between the close on Friday and the opening Monday. I have this EA, and I would like to put a stop loss and trailing stop, but all the solutions I've tried it give me error. Can you help?
thanks

//+------------------------------------------------------------------+
//|                                                         gaps.mq4 |
//|                                                        SFK Corp. |
//+------------------------------------------------------------------+
#property copyright "SFK Corp."
#property link      ""
//---- input parameters
extern int    min_gapsize = 1;
extern double lotsize_gap = 0.1;
//----
datetime order_time = 0;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
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)
     {
       int ticket = OrderSend(Symbol(), OP_SELL, lotsize_gap, Bid, 0, 0, 
                              previous_highprice + spread_gap*point_gap, 
                              "", 4, 0, Red);
       order_time = iTime(Symbol(), PERIOD_M15, 0);
       Print("I am inside (sell) :-)", order_time);
       //----
       if(ticket < 0)
         {
           Print("OrderSend failed with error #", GetLastError());
         }
     }

Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2014.02.19 11:44  
ghibellino:
hello, I ask help with a simple EA, to open a position when there is a gap between the close on Friday and the opening Monday. I have this EA, and I would like to put a stop loss and trailing stop, but all the solutions I've tried it give me error. Can you help?
thanks

<REMOVED>

Please use the SRC button to post code . . .
Alessandro Surdo
134
Alessandro Surdo 2014.02.19 12:28  
RaptorUK:
Please use the SRC button to post code . . .


ok, sorry, I edit the post
Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2014.02.19 12:40  
ghibellino:

ok, sorry, I edit the post
Thank you
Fernando Carreiro
1554
Fernando Carreiro 2014.02.19 15:09  
ghibellino:
hello, I ask help with a simple EA, to open a position when there is a gap between the close on Friday and the opening Monday. I have this EA, and I would like to put a stop loss and trailing stop, but all the solutions I've tried it give me error. Can you help?
thanks


Please inform us of the error code given.

Also, I suggest that besides the Error, that you also Print both Bid and Ask, so as to see spread, as well as the Stops used (TakeProfit in this case) as well as the Minimum Stop allowed for the symbol in question.

Also, please note that you are using a slippage of 0, leaving no tolerance at all.

Only after you are able to supply us with the extra information will we be able to better understand the problem.

Alessandro Surdo
134
Alessandro Surdo 2014.02.19 21:39  
FMIC:


Please inform us of the error code given.

Also, I suggest that besides the Error, that you also Print both Bid and Ask, so as to see spread, as well as the Stops used (TakeProfit in this case) as well as the Minimum Stop allowed for the symbol in question.

Also, please note that you are using a slippage of 0, leaving no tolerance at all.

Only after you are able to supply us with the extra information will we be able to better understand the problem.


thanks for your interest,
as a solution I tried to insert the stop loss in

/ / ---- Input parameters
extern int stoploss = 50;

and change the functions

int ticket = OrderSend (Symbol (), OP_SELL, lotsize_gap, Bid, 0, current_openprice+stoploss,
previous_highprice + * spread_gap point_gap,"", 4, 0, Red);
and

Ticket OrderSend = (Symbol (), OP_BUY, lotsize_gap, Ask, 0, current_openprice-stoploss,
previous_lowprice - spread_gap * point_gap,"", 5, 0, Green);

but it is a bad solution because the stop loss is not adjustable, and also the EA works only on cross JPY


Fernando Carreiro
1554
Fernando Carreiro 2014.02.19 21:51  
ghibellino:

thanks for your interest,
as a solution I tried to insert the stop loss in ...

If you want to us help, you have to provides us with the information requested and follow our suggestions when possible, otherwise you we will just be going around in circles, with no solution to the problem.

So, please read my comments again and try to do as I suggested and provide us with the information requested in order to find a solution.

whroeder1
13644
whroeder1 2014.02.19 22:01  

  1. Play video
    Please edit your post.
    For large amounts of code, attach it.
    You've be asked before. Why didn't you?

  2. but it is a bad solution because the stop loss is not adjustable, and also the EA works only on cross JPY
    extern int stoploss = 50;
    int ticket = OrderSend (Symbol (), OP_SELL, lotsize_gap, Bid, 0, current_openprice+stoploss,
    So make your external parameter pips and adjust it for pair and 4/5 digit brokers
/
To add comments, please log in or register