Questions from Beginners MQL4 MT4 MetaTrader 4 - page 255
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
How do you calculate tp?
I specify in the variable double tp=50;
I specify in the variable double tp=50;
now writes
2021.12.04 13:56:09.509 TestGenerator: unmatched data error (high value 1.13110 at 2021.12.03 23:45 is not reached from the lowest timeframe, high price 1.13104 mismatches)
put it on for a minute... it works...
but the stop level is different -
1 2021.09.16 05:59 sell 1 0.01 1.18190 51.18192 1.18140 0.00 10000.00
now writes
2021.12.04 13:56:09.509 TestGenerator: unmatched data error (high value 1.13110 at 2021.12.03 23:45 is not reached from the lowest timeframe, high price 1.13104 mismatches)
All rules are online, so check it yourself.
Rules all online, so check for yourself.
Thank you!
Good evening gentlemen, could you please advise why the advisor gives an error when opening a second order?
The text of the advisor itself
//+----------------------Параметры-----------------------------------+
input int TakeProfit = 100; // Profit in pips
input int StopLoss = 50; // Loss in pips
input double Lot = 0.01; // Start lot
input double Multilot = 1.95; // multiplier for starting lot
input int Slippage =30; // Slippage
input int MagicNumber = 333 ; // Unique number
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
double tp=0;
double sl=0;
int OnInit()
{
tp=NormalizeDouble(TakeProfit*Point(),Digits());
sl=NormalizeDouble(StopLoss*Point(),Digits());
return(INIT_SUCCEED);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//--the loop checks for open orders when the Expert Advisor is activated and calculates them.
int buy=0; //Number of BUY orders
int sell=0; //Number of SELL orders
for(int i = OrdersTotal()-1; i>=0; i--)
if(OrderSelect(i, SELECT_BY_POS,MODE_TRADES))
if(OrderSymbol()==Symbol())
if(OrderMagicNumber()== MagicNumber)
{
if(OrderType()==OP_BUY)
buy++;
if(OrderType()==OP_SELL)
sell++;
}
//--the loop receives the data of the last closed order when the EA is activated
int type=-1; //the type of a closed order
int history_close_orders=0; //number of closed orders
double lot=0; //Lot of the last closed order
double profit=0; //Profit at which the last order was closed
datetime time=0; //Closing time of the last order
for(int i = OrdersHistoryTotal()-1; i>=0; i--)
if(OrderSelect(i, SELECT_BY_POS,MODE_HISTORY))
if(OrderSymbol()==Symbol())
if(OrderMagicNumber()== MagicNumber)
if(OrderCloseTime()>time)
{
history_close_orders++;
time = OrderCloseTime();//the last order close time
lot= OrderLots();//Lot of the last closed order
type=OrderType();// Type of the last closed order
profit=OrderProfit()*OrderSwap()*OrderCommission();//Profit of the last closed order
}
//calculate the lot with which the EA will work
double Lots_Work=0;// working lot
if(history_close_orders==0 || profit>0)// if there are no closed orders or the last order closed on the profit
Lots_Work=Lot;// working lot is equal to the initial lot
if(history_close_orders>0 && profit<0) // if the last order closed in the red
Lots_Work=1;// working lot will be equal to the lot of the last order multiplied by the multiplier
//open the first buy order
if(buy==0 || profit>0)
{
int ticket=OrderSend(Symbol(),OP_BUY,Lots_Work,Ask,Slippage,0,0, "Expert Advisor Test fair",MagicNumber,0,clrGreen);
if(ticket<0)
Print("OrderSend failed with error #",GetLastError());
else
Print("OrderSend completed successfully");
}
// Opening of the second and the subsequent Buy orders
if(buy==0 && type==OP_BUY && profit<0)
{
int ticket=OrderSend(Symbol(),OP_BUY,Lots_Work,Ask,Slippage,0,0, "EA Test fair",MagicNumber,0,clrGreen);
if(ticket<0)
Print("OrderSend failed with error #",GetLastError());
else
Print("OrderSend completed successfully");
}
// Opening of the first Sell order
if(sell==0 || profit>0)
{
int ticket=OrderSend(Symbol(),OP_SELL,Lots_Work,Bid,Slippage,0,0, "EA Test fair",MagicNumber,0,clrRed);
if(ticket<0)
Print("OrderSend failed with error #",GetLastError());
else
Print("OrderSend completed successfully");
}
// Opening of the second and the subsequent Buy orders
if(sell==0 && (type==OP_SELL && profit<0))
{
int ticket=OrderSend(Symbol(),OP_SELL,Lots_Work,Bid,Slippage,0,0, "Expert Advisor Test fair",MagicNumber,0,clrRed);
if(ticket<0)
Print("OrderSend failed with error #",GetLastError());
else
Print("OrderSend completed successfully");
}
//--Modify the order by adding Take Profit and Stop Loss
for(int i = OrdersTotal()-1; i>=0; i--)
if(OrderSelect(i, SELECT_BY_POS))
if(OrderSymbol()==Symbol())
if(OrderMagicNumber()== MagicNumber)
{
if(OrderType()==OP_BUY)
{
if(OrderStopLoss()==0 || OrderTakeProfit()==0)
if(OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-sl,Digits(),NormalizeDouble(OrderOpenPrice()+tp,Digits(),0,clrGreen))
Print("OrderModify OK!");
else
Print("OrderModify BUY failed #", GetLastError());
}
if(OrderType()==OP_SELL)
{
if(OrderStopLoss()==0 || OrderTakeProfit()==0)
if(OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()+sl,Digits(),NormalizeDouble(OrderOpenPrice()-tp,Digits(),0,clrRed))
Print("OrderModify OK!");
else
Print("OrderModify SELL failed #", GetLastError());
}
}
}
//+------------------------------------------------------------------+
My old laptop with i3 processor still had WinXP 32 bit installed, unsupported MT5. Recently increased memory to 6GB, I want to install 64 bit OS that would run MT4 and MT5. Which is preferable - Win7 or Win8.1 ?
10
10