Hello All,
Im totally new in MQL4 coding and really need help. Once i Open Buy and Sell, how do i code to close-order if
1. MACD Main is lesser than MACD Signal Line
The code for OPEN and SELL as below.
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OpenBuy()
{
// Open Buy Order
int ticket=OrderSend(_Symbol,OP_BUY,LotSize,Ask,MySlippage,0,0,"BUY",MagicNumber);
if(ticket<0) Print("Buy Order Send failed with error #",GetLastError());
else Print("Buy Order placed successfully");
// Modify Buy Order
bool res=OrderModify(ticket,OrderOpenPrice(),Ask-StopLoss*MyPoint,Ask+TakeProfit*MyPoint,0);
if(!res) Print("Error in OrderModify. Error code=",GetLastError());
else Print("Order modified successfully.");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OpenSell()
{
//Open Sell Order
int ticket=OrderSend(_Symbol,OP_SELL,LotSize,Bid,MySlippage,0,0,"SELL",MagicNumber);
if(ticket<0) Print("Sell Order Send failed with error #",GetLastError());
else Print("Sell Order placed successfully");
// Modify Sell Order
bool res=OrderModify(ticket,OrderOpenPrice(),Bid+StopLoss*MyPoint,Bid-TakeProfit*MyPoint,0);
if(!res) Print("Error in OrderModify. Error code=",GetLastError());
else Print("Order modified successfully.");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
Many Thanks in Advance.
Im totally new in MQL4 coding and really need help. Once i Open Buy and Sell, how do i code to close-order if
1. MACD Main is lesser than MACD Signal Line
The code for OPEN and SELL as below.
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OpenBuy()
{
// Open Buy Order
int ticket=OrderSend(_Symbol,OP_BUY,LotSize,Ask,MySlippage,0,0,"BUY",MagicNumber);
if(ticket<0) Print("Buy Order Send failed with error #",GetLastError());
else Print("Buy Order placed successfully");
// Modify Buy Order
bool res=OrderModify(ticket,OrderOpenPrice(),Ask-StopLoss*MyPoint,Ask+TakeProfit*MyPoint,0);
if(!res) Print("Error in OrderModify. Error code=",GetLastError());
else Print("Order modified successfully.");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OpenSell()
{
//Open Sell Order
int ticket=OrderSend(_Symbol,OP_SELL,LotSize,Bid,MySlippage,0,0,"SELL",MagicNumber);
if(ticket<0) Print("Sell Order Send failed with error #",GetLastError());
else Print("Sell Order placed successfully");
// Modify Sell Order
bool res=OrderModify(ticket,OrderOpenPrice(),Bid+StopLoss*MyPoint,Bid-TakeProfit*MyPoint,0);
if(!res) Print("Error in OrderModify. Error code=",GetLastError());
else Print("Order modified successfully.");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
Many Thanks in Advance.
