I am new to mql4 programming. I want want to understand some fundamental. I have this testing EA whose code is displayed below. How do I stop it from multiple entry. Like when the condition for buy is true, it enters buy on every tick, the same with sell.
My question is how to i stop it from entering several buy or sell as the case may be. I want it to enter single buy on a particular pair and when the sell condition is true, it will close the buy and enter sell. Please help me out.
Thanks in advance.
//+------------------------------------------------------------------+
//| test2.mq4 |
//| Copyright 2019, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
double f1 = iMA(NULL,0,14,0,MODE_EMA,PRICE_CLOSE,0);
double f2 = iMA(NULL,0,3,0,MODE_EMA,PRICE_CLOSE,0);
if(f2 > f1)
{
OrderSend(Symbol(),OP_BUY,0.01,Ask,3,NULL,NULL);
}
else if(f2 < f1)
{
OrderSend(Symbol(),OP_SELL,0.01,Bid,3,NULL,NULL);
}
}
//+------------------------------------------------------------------+