//+------------------------------------------------------------------+//| MACD Sample.mq4 |//| Copyright 2005-2014, MetaQuotes Software Corp. |//| http://www.mql4.com |//+------------------------------------------------------------------+#property copyright"2005-2014, MetaQuotes Software Corp."#property link"http://www.mql4.com"inputdouble TakeProfit =3160;
inputdouble Lots =0.5;
inputdouble TrailingStop =1040;
inputint OpenLevel =22;
inputint CloseLevel=77;
inputintPeriod =85;
inputint Period1 =57;
int LastBars=0;
externint Magic = 110725;
//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+voidOnTick(void)
{
int cnt,ticket,total;
//---// initial data checks// it is important to make sure that the expert works with a normal// chart and the user did not make any mistakes setting external // variables (Lots, StopLoss, TakeProfit, // TrailingStop) in our case, we check TakeProfit// on a chart of less than 100 bars//---//--- Trade only if new bar has arrivedif(LastBars!=Bars) LastBars=Bars;
elsereturn(0);
if(Bars<100)
{
Print("bars less than 100");
return;
}
if(TakeProfit<10)
{
Print("TakeProfit less than 10");
return;
}
//--- to simplify the coding and speed up access data are put into internal variables
total=OrdersTotal();
if(total<1)
{
//--- no opened orders identifiedif(AccountFreeMargin()<(1000*Lots))
{
Print("We have no money. Free Margin = ",AccountFreeMargin());
return;
}
//--- check for long position (BUY) possibilityif(iRSI(NULL,0,OpenLevel,PRICE_LOW,Period)>iRSI(NULL,0,CloseLevel,PRICE_HIGH,Period1))
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid-TakeProfit*Point,Bid+TakeProfit*Point,"USDCADH4",Magic,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
Print("BUY order opened : ",OrderOpenPrice());
}
elsePrint("Error opening BUY order : ",GetLastError());
return;
}
//--- check for short position (SELL) possibilityif(iRSI(NULL,0,OpenLevel,PRICE_LOW,Period1)<iRSI(NULL,0,CloseLevel,PRICE_HIGH,Period))
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Ask+TakeProfit*Point,Ask-TakeProfit*Point,"USDCADH4",Magic,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
Print("SELL order opened : ",OrderOpenPrice());
}
elsePrint("Error opening SELL order : ",GetLastError());
}
//--- exit from the "no opened orders" blockreturn;
}
//--- it is important to enter the market correctly, but it is more important to exit it correctly... for(cnt=0;cnt<total;cnt++)
{
if(!OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
continue;
if(OrderType()<=OP_SELL && // check for opened position
OrderSymbol()==Symbol()) // check for symbol
{
//--- long position is openedif(OrderType()==OP_BUY)
{
//--- should it be closed?if(iRSI(NULL,0,OpenLevel,PRICE_LOW,Period1)<iRSI(NULL,0,CloseLevel,PRICE_HIGH,Period))
{
//--- close order and exitif(!OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet))
Print("OrderClose error ",GetLastError());
return;
}
//--- check for trailing stopif(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
//--- modify order and exitif(!OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green))
Print("OrderModify error ",GetLastError());
return;
}
}
}
}
else// go to short position
{
//--- should it be closed?if(iRSI(NULL,0,OpenLevel,PRICE_LOW,Period)>iRSI(NULL,0,CloseLevel,PRICE_HIGH,Period1))
{
//--- close order and exitif(!OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet))
Print("OrderClose error ",GetLastError());
return;
}
//--- check for trailing stopif(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
{
//--- modify order and exitif(!OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red))
Print("OrderModify error ",GetLastError());
return;
}
}
}
}
}
}
//---
}
//+------------------------------------------------------------------+
Hello. Please help me to understand... The Expert Advisor is closing other people's trades or not opening its own if there are other people's trades.
If it is written above, the Expert Advisor closes trades opened manually,
If I put it this way
if(!OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
continue;
if(OrderType()<=OP_SELL && // check for opened position
OrderSymbol()==Symbol()&& OrderMagicNumber()==Magic) // check for symbol
If there are any trades opened manually, then the Expert Advisor will not close other trades, but it will not open its own if there are any trades opened manually.
If it is written above, the Expert Advisor closes trades opened manually,
If I put it this way
If there are any trades opened manually, then the Expert Advisor will not close other trades, but it will not open its own if there are any trades opened manually.
What is this? The opening is indicated. The thing is that when you use several Expert Advisors, there is no problem. The problem occurs only when there is a manual opening of a position in the account.
As soon as there are opened deals on the account manually, the Expert Advisor stops working.
As soon as I remove this in the code, total=OrdersTotal();
What is this? The opening is indicated. The thing is that when you use several Expert Advisors, there is no problem. The problem occurs only when there is a manual opening of a position in the account.
As soon as there are opened deals on the account manually, the Expert Advisor stops working.
As soon as I remove this in the code, total=OrdersTotal();
if(total<1)
EAs go straight on, but open lots of trades.
This is what I am talking about - OrdersTotal() is for all orders and you need an EA order
if(CountOrders("", -1, Magic)<1)
{
открытие ордеров
}
//+----------------------------------------------------------------------------+//| Подсчет ордеров |//+----------------------------------------------------------------------------+//| -1 - Все типы ордеров |//| 0 - ордера типа BUY |//| 1 - ордера типа SELL |//| 2 - ордера типа BUYLIMIT |//| 3 - ордера типа SELLLIMIT |//| 4 - ордера типа BUYSTOP |//| 5 - ордера типа SELLSTOP |//+----------------------------------------------------------------------------+int CountOrders(string symb="", int or_ty=-1, int magiс=-1)
{
int cnt=0;
if(symb=="0") symb=_Symbol;
for(int pos=OrdersTotal()-1;pos>=0;pos--)
{
if(OrderSelect(pos,SELECT_BY_POS)==true)
{
if((OrderSymbol()==symb || symb=="")&&(or_ty<0 || or_ty==OrderType()))
{
if(magiс<0 || OrderMagicNumber()==magiс) cnt++;
}
}
}
return(cnt);
}
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.
I sent a request yesterday, more than a day has passed and silence.
1. Go to the nearest ATM, insert the card, enter the pin code...
2. Go to the nearest bank, make eye contact, then follow the situation...
3. Go to the market. 3) Go to the market. Go to the bank. Withdraw funds (you can withdraw them all, not just your own...) ...
4. If you have to withdraw money from MMM, then even the tank will not help you!
And seriously, you can't!
Hello. Please help me to understand... The Expert Advisor is closing other people's trades or not opening its own if there are other people's trades.
Hello. Please help me to understand... The Expert Advisor is closing other people's trades or not opening its own if there are other people's trades.
If it is written above, the Expert Advisor closes trades opened manually,
If I put it this way
If there are any trades opened manually, then the Expert Advisor will not close other trades, but it will not open its own if there are any trades opened manually.
If it is written above, the Expert Advisor closes trades opened manually,
If I put it this way
If there are any trades opened manually, then the Expert Advisor will not close other trades, but it will not open its own if there are any trades opened manually.
I also need selection on the magic number at opening
What is this? The opening is indicated. The thing is that when you use several Expert Advisors, there is no problem. The problem occurs only when there is a manual opening of a position in the account.
As soon as there are opened deals on the account manually, the Expert Advisor stops working.
As soon as I remove this in the code, total=OrdersTotal();
if(total<1)
EAs go straight on, but open lots of trades
What is this? The opening is indicated. The thing is that when you use several Expert Advisors, there is no problem. The problem occurs only when there is a manual opening of a position in the account.
As soon as there are opened deals on the account manually, the Expert Advisor stops working.
As soon as I remove this in the code, total=OrdersTotal();
if(total<1)
EAs go straight on, but open lots of trades.
This is what I am talking about - OrdersTotal() is for all orders and you need an EA order
That's what I'm talking about, OrdersTotal() is all orders and you want EA orders
This is instead of
total=OrdersTotal();
if(total<1) or do we leave this one as well?