Ok, forgive my ignorance as I'm a newbie but i just can't seem to figure out why i cannot execute this Sellstop line in this modified EA im working on. I have highlighted the line in red. Whenever i run the EA the other things work but this line causes "Error #130" which to my understanding means a problem with Stoploss levels. But i just can't seem to figure out what is wrong with the code. Any thoughts?
//+------------------------------------------------------------------+
//| Straddle_EA.mq4 |
//| branac |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "branac"
#property link "http://www.metaquotes.net"
//---- input parameters
extern double Lots=0.1;
extern double Pips=10;
extern double TP=10;
extern double SL=10;
extern bool Buy=true;
extern bool Sell=true;
extern int DayStartHour = 0;
//extern datetime expiration=D'2006.08.02 03:25';
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
datetime dtDayStart = 0;
int start()
{
//----
int ticket;
// The spread is included in the sl and tp calculations
double buy_price = Ask + Pips*Point;
double sell_price = Bid - Pips*Point;
double stoploss_sell=Ask - SL*Point;
double takeprofit_sell=Bid + TP*Point;
int buy_orders=0;
int sell_orders=0;
if(OrdersTotal() == 0)
{
if (TimeHour(Time[0]) == DayStartHour
&& TimeHour(Time[1]) != DayStartHour
&& dtDayStart < Time[0]) {
dtDayStart = Time[0];
// Buy order
if ( (Buy == true) && (buy_orders == 0) )
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,2,Ask-SL*Point,Ask+TP*Point,"Buy order ",00001,0,CLR_NONE);
buy_orders = 1;
if(ticket<0)
{
Print("OrderSend failed with error #",GetLastError());
return(0);
}
}
// Sell order
if ( (Sell == true) && (sell_orders == 0) )
{
ticket=OrderSend(Symbol(),OP_SELLSTOP,Lots,sell_price,2,stoploss_sell,takeprofit_sell,"Buy order ",00002,0,CLR_NONE);
sell_orders = 1;
if(ticket<0)
{
Print("OrderSend failed with error #",GetLastError());
return(0);
}
}
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Straddle_EA.mq4 |
//| branac |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "branac"
#property link "http://www.metaquotes.net"
//---- input parameters
extern double Lots=0.1;
extern double Pips=10;
extern double TP=10;
extern double SL=10;
extern bool Buy=true;
extern bool Sell=true;
extern int DayStartHour = 0;
//extern datetime expiration=D'2006.08.02 03:25';
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
datetime dtDayStart = 0;
int start()
{
//----
int ticket;
// The spread is included in the sl and tp calculations
double buy_price = Ask + Pips*Point;
double sell_price = Bid - Pips*Point;
double stoploss_sell=Ask - SL*Point;
double takeprofit_sell=Bid + TP*Point;
int buy_orders=0;
int sell_orders=0;
if(OrdersTotal() == 0)
{
if (TimeHour(Time[0]) == DayStartHour
&& TimeHour(Time[1]) != DayStartHour
&& dtDayStart < Time[0]) {
dtDayStart = Time[0];
// Buy order
if ( (Buy == true) && (buy_orders == 0) )
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,2,Ask-SL*Point,Ask+TP*Point,"Buy order ",00001,0,CLR_NONE);
buy_orders = 1;
if(ticket<0)
{
Print("OrderSend failed with error #",GetLastError());
return(0);
}
}
// Sell order
if ( (Sell == true) && (sell_orders == 0) )
{
ticket=OrderSend(Symbol(),OP_SELLSTOP,Lots,sell_price,2,stoploss_sell,takeprofit_sell,"Buy order ",00002,0,CLR_NONE);
sell_orders = 1;
if(ticket<0)
{
Print("OrderSend failed with error #",GetLastError());
return(0);
}
}
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
Liberate me ex inferis