Hi,
Please take a look at the code below.
The sell side is working fine. But the buy side is not working fine.
Can somebody please tell me why.
Please take a look at the code below.
The sell side is working fine. But the buy side is not working fine.
Can somebody please tell me why.
PHP Code
//+------------------------------------------------------------------+
//| A1.mq4 |
//| Brijesh |
//| |
//+------------------------------------------------------------------+
#property copyright "Brijesh"
#property link ""
extern double iLots = 1;
extern int iMagicNumber = 12444;
double iBuyPrice, iSellPrice,iRange1,iRange2, iStopLoss1, iStopLoss2, iTakeProfit1, iTakeProfit2, Entry;
int iTicket;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
if (High[1] > High[2] && Low[1] > Low[2]) bn();
else
if (High[1] < High[2] && Low[1] < Low[2]) sn();
//----
return(0);
}
//+------------------------------------------------------------------+
void bn()
{
int iTotal = OrdersTotal();
iBuyPrice = Close[1] + Point; // buy price
iRange1 = High[1] - Low[1]; // range of the previous bar
iStopLoss1 = Low[1]- iRange1; // sl
iTakeProfit1 = High[1] + iRange1; // tp
datetime iExpire1=CurTime()+PERIOD_M1*60; //order expiry
if(iTotal < 1)
{
int Mode;
if (Bid > iBuyPrice) {Mode = OP_BUYLIMIT; Entry = iBuyPrice;}
if (Bid == iBuyPrice) {Mode = OP_BUY; Entry = iBuyPrice;}
if (Bid < iBuyPrice) {Mode = OP_BUYSTOP; Entry = iBuyPrice;}
iTicket = OrderSend(Symbol(),Mode, iLots, Entry, 3, iStopLoss1 , iTakeProfit1, "Buy Script", iMagicNumber,iExpire1,Green);
if (iTicket>0)
{
if(OrderSelect(iTicket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
}
else
{
Print("Error opening BUY order : ",GetLastError());
}
}
}
void sn()
{
int iTotal1 = OrdersTotal();
iSellPrice = Close[1] - Point; //sell price
iRange2 = High[1] - Low[1]; // range of the previous bar
iStopLoss2 = High[1]+ iRange2; // Sl
iTakeProfit2 = Low[1] - iRange2; // TP
datetime iExpire2=CurTime()+PERIOD_M1*60; // Order expiry
if (iTotal1 < 1)
{
int Mode1;
if (Bid > iSellPrice) {Mode1 = OP_SELLSTOP; Entry = iSellPrice;}
if (Bid == iSellPrice) {Mode1 = OP_SELL; Entry = iSellPrice;}
if (Bid < iSellPrice) {Mode1 = OP_SELLLIMIT; Entry = iSellPrice;}
iTicket = OrderSend(Symbol(),Mode1, iLots, Entry, 3, iStopLoss2 , iTakeProfit2, "Sell Script", iMagicNumber,iExpire2,Red);
if (iTicket>0)
{
if(OrderSelect(iTicket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
}
else
{
Print("Error opening BUY order : ",GetLastError());
}
}
}