Hi everyone.
I am learning the MQL Language hope there alot of programmer here might help me, I have this very simple EA I created for learning purpose so my problem is I wanted to implement martingale in this strategy where a trade is opened after three consecutive bear or bull, but I was not succeeded I am looking for help if anyone who is competent, below is the code I tried to upload the EA with no success.
#property copyright “”
#property link “”
#property version “1.02”
#property strict
//— input parameters
input int TakeProfit=500;
input int StopLoss=500;
input double LotSize=0.1;
input int Slippage=30;
input int MagicNumber=5555;
//±----------------------------------- ------------------------------+
//| Expert initialization function |
//±----------------------------------- ------------------------------+
int OnInit()
{
//—
//—
return(INIT_SUCCEEDED);
}
//±----------------------------------- ------------------------------+
//| Expert deinitialization function |
//±----------------------------------- ------------------------------+
void OnDeinit(const int reason)
{
//—
}
//±----------------------------------- ------------------------------+
//| Expert tick function |
//±----------------------------------- ------------------------------+
void OnTick()
{
//—
if(TotalOpenOrders() == 0 && IsNewBar() == true)
{
if(Close[1] > Open[1] && Close[2] > Open[2] && Close[3] > Open[3])
{
//Open Buy Order
OrderSend(_Symbol,OP_BUY,LotSize,As k,Slippage,Ask-StopLoss*_Point,Ask+TakeProfit*_Poi nt,“BUY”,MagicNumber);
}
// Sell Logic
if(Close[1] < Open[1] && Close[2] < Open[2] && Close[3] < Open[3])
{
OrderSend(_Symbol,OP_SELL,LotSize,B id,Slippage,Bid+StopLoss*_Point,Bid-TakeProfit*_Point,“SELL”,MagicNumbe r);
}
}
}
//±----------------------------------- ------------------------------+
// Check if there is a new bar
bool IsNewBar()
{
static datetime RegBarTime=0;
datetime ThisBarTime = Time[0];
if (ThisBarTime == RegBarTime)
{
return(false);
}
else
{
RegBarTime = ThisBarTime;
return(true);
}
}
// Returns the number of total open orders for this Symbol and MagicNumber
int TotalOpenOrders()
{
int total_orders = 0;
for(int order = 0; order < OrdersTotal(); order++)
{
if(OrderSelect(order,SELECT_BY_POS, MODE_TRADES)==false) break;
if(OrderMagicNumber() == MagicNumber && OrderSymbol() == _Symbol)
{
total_orders++;
}
}
return(total_orders);
}