Hi all,
I am having some problems entering trades with stochastics crossovers. My aim is to open trade when stochastic crosses at the overbrought (level 80) or oversold (level 20) area. However, I am only able to open trade when it crosses. How do I restrict the trades to be carried out at the over brought and oversold regions?
Please help. Thanks.
Terrance
//— input parameters
extern double TakeProfit=530.0;
extern double Lots=0.1;
extern double StopLoss=520.0;
//±-----------------------------------------------------------------+
//| expert initialization function |
//±-----------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//±-----------------------------------------------------------------+
//| expert deinitialization function |
//±-----------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//±-----------------------------------------------------------------+
//| expert start function |
//±-----------------------------------------------------------------+
int start()
{
//----
int ticket, total;
double shortStoc, longStoc;
if(Bars<100)
{
Print(“bars less than 100”);
return(0);
}
if(TakeProfit<10)
{
Print(“TakeProfit less than 10”);
return(0); // check TakeProfit
}
//±-----------------------------------------------------------------+
//| expert start function | Stochastic Trigger
//±-----------------------------------------------------------------+
shortStoc = iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_MAIN,0); //orignial Stoc movement
longStoc = iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_SIGNAL,0); //orignial Stoc movement
//±-------------------------------------------------------------------------------------+
//| expert start function | Set trigger trade only when line crossed and candle closed |//
//±-------------------------------------------------------------------------------------+
int isCrossed = 0;
double shortStoc1 = iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_MAIN,1);
double longStoc1 = iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_SIGNAL,1);
double shortStoc2 = iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_MAIN,2);
double longStoc2 = iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_SIGNAL,2);
double diff1 = shortStoc1-longStoc1;
double diff2 = shortStoc2-longStoc2;
if ((diff1*diff2)<0)
{
if (shortStoc1>longStoc1)
isCrossed = 1;
else isCrossed = 2;
}
//±-----------------------------------------------------------------------------------+
//| expert end function | Set trigger trade only when line crossed and candle closed |//
//±-----------------------------------------------------------------------------------+
//±-----------------------------------------------------------------+
//| expert end function | Stochastic Trigger
//±-----------------------------------------------------------------+
//| expert start function | Trigger order
//±-----------------------------------------------------------------------------------------------------------+
total = OrdersTotal();
if(total < 1)
{
if(isCrossed == 1)
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,1,Ask-StopLossPoint,Ask+TakeProfitPoint,
“My EA”,12345,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());
return(0);
}
if(isCrossed == 2)
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,1,Bid+StopLossPoint,Bid-TakeProfitPoint,
“My EA”,12345,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
Print("SELL order opened : ",OrderOpenPrice());
}
else Print("Error opening SELL order : ",GetLastError());
return(0);
}
return(0);
}
return(0);
}