What I see in your code is that nothing is done if there are already order(s) open. So it is inefficient to do the calculations unnecessarily. OrdersTotal() should be the first check and bypass the calculation code if there are open order(s).
It would be better to loop through open orders and check for magic number and symbol
Note that by just using OrdersTotal() as a check, any manually opened trades or by another EA will not allow orders to be placed. It is better to check for open orders with magic number and symbol.
//--- input parametersinputdouble takeprofit=0.1;
inputdouble stoploss= 0.1;
inputdouble LotSize = 0.01;
double point=Point;
//+------------------------------------------------------------------+//| Expert initialization function |//+------------------------------------------------------------------+intOnInit()
{
if(Digits==3 || Digits==5) point*=10;
return (INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| Expert tick function |//+------------------------------------------------------------------+voidOnTick()
{
if(OrdersTotal()<1)
{
int ticket;
int MyHigh=iHighest(Symbol(),0,MODE_HIGH,30,1);
double price_highest=High[MyHigh];
if(price_highest<0)
Print("Error :",GetLastError());
int MyLow=iLowest(Symbol(),0,MODE_LOW,30,1);
double price_lowest=Low[MyLow];
if(price_lowest<0)
Print(" Error :",GetLastError());
if(price_highest<Ask)
{
ticket=OrderSend(Symbol(),OP_BUY,LotSize,Ask,5,Ask-(stoploss*point),Ask+(takeprofit*point),NULL,0,0,Green);
if(ticket<0)
Print(" Error sending Buy order :",GetLastError());
}
if(Bid<price_lowest)
{
ticket=OrderSend(Symbol(),OP_SELL,LotSize,Bid,5,Bid+(stoploss*point),Bid-(takeprofit*point),NULL,0,0,Red);
if(ticket<0)
Print(" Error sendig Sell order number :",GetLastError());
}
}
return;
}
//+------------------------------------------------------------------+
Why use variables for Ask and Bid when you can just use Ask and Bid? If you have a lot of code, you can use RefreshRates() to make sure that they are current.
Why use the bools UpBreakThrough and DownBreakThrough when you can just test the condition and go straight to the code?
I would avoid using variable names such as point as it is too easy to mistakenly type Point.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
What I see in your code is that nothing is done if there are already order(s) open. So it is inefficient to do the calculations unnecessarily. OrdersTotal() should be the first check and bypass the calculation code if there are open order(s).
It would be better to loop through open orders and check for magic number and symbol
Note that by just using OrdersTotal() as a check, any manually opened trades or by another EA will not allow orders to be placed. It is better to check for open orders with magic number and symbol.
Why use variables for Ask and Bid when you can just use Ask and Bid? If you have a lot of code, you can use RefreshRates() to make sure that they are current.
Why use the bools UpBreakThrough and DownBreakThrough when you can just test the condition and go straight to the code?
I would avoid using variable names such as point as it is too easy to mistakenly type Point.
Check your calculations for TP and SL, they will not be calculating as you want