Nikolay Gaylis: Please advise how to select a symbol in the tester for testing in
You can't. Only manually select in the settings.
In the tester, of course, you can request data on other symbols, but for this you will have to work hard enough to ensure the synchronization of data (the tester itself will not do it for you, because by default it works with one symbol). Trade on the symbol, different from the selected, in general, can not.
P. S. All this is for MT4. In MT5 situation is different.
EA works withOnTimer()EventSetTimer(1).I miss many ticks. The eventOnTick() is not suitable for me, because I analyze multiple currency pairs at once ... Even Sleep(200) in loop will load system...What to do?
Nikolay Gaylis: The Expert Advisor works inOnTimer() EventSetTimer(1). I miss many ticks. TheOnTick() event does not fit me because I analyze several currency pairs at once ... Even Sleep(200) in loop will load system...What to do?
There is also EventSetMillisecondTimer() - it can reduce periodicity of OnTimer() execution.
The message "Array out of range" appears in the allocated space during the test. It does not indicate an error during compilation. What is the essence of the error and how can we fix it?
double TD_Close=Close[1];
for (int i=2; i<=Period_bars; i++)
{
if (ABS_High<High[i]) ABS_High=High[i];
}
if (TD_Close>ABS_High)
{
if(OrdersTotal () <= 1 && newCandle != Time[0]) int tiket=OrderSend(Symbol(),OP_BUY,volume,Ask,3,sl,tp,",magic,0);
The message "Array out of range" appears in the highlighted place during the test. It does not indicate an error during compilation. What is the essence of the error and how can we fix it?
double TD_Close=Close[1];
for (int i=2; i<=Period_bars; i++)
{
if (ABS_High<High[i]) ABS_High=High[i];
}
if (TD_Close>ABS_High)
{
if (OrdersTotal () <= 1 && newCandle != Time[0]) int tiket=OrderSend(Symbol(),OP_BUY,volume,Ask,3,sl,tp,",magic,0);
Hello, friends, help me solve the following problem: I am trying to write a simple Expert Advisor and I have faced the following: if the SL is set to a value different from 0, then trades are not opened at all, as well as the TP, TStop and TrailingStep functions do not work at all.
What should I fix in the code?
//+------------------------------------------------------------------+//| MA.mq4 |//| Sergey |//| http://www.mql4.com |//+------------------------------------------------------------------+#property copyright"Sergey Karev"#property link"http://www.mql4.com"#property description"Moving Average sample expert advisor"//#property strict#define MAGICMA 23101987//--- Inputsinputdouble Lots = 0.01; // Объем лотаinputint SL = 0; // Stop Lossinputint TP = 0; // Take profitinputint TStop = 0; // Пунктыinputint TrailingStep = 0; // Шаг TS в пунктахinputint MA_per1 = 5; // MA быстраяinputint MA_per2 = 55; // MA медленнаяinputint Timeframe = 60; // Таймфрейм inputdouble MaximumRisk = 0.02;
inputdouble DecreaseFactor = 3;
inputint MovingShift = 0; // Cдвиг среднейinputint Shift = 0; // Сдвиг баровinputint Magic_number = 1987; // Если Magic = 0, то работает + ручные ордерыbool TSProfitOnly = true;
int NumberOfTry = 5;
bool UseSound = True;
string NameFileSound = "expert.wav";
//+------------------------------------------------------------------+//| Calculate open positions |//+------------------------------------------------------------------+int CalculateCurrentOrders(string symbol)
{
int buys=0,sells=0;
//---for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
{
if(OrderType()==OP_BUY) buys++;
if(OrderType()==OP_SELL) sells++;
}
}
//--- return orders volumeif(buys>0) return(buys);
elsereturn(-sells);
}
//+------------------------------------------------------------------+//| Calculate optimal lot size |//+------------------------------------------------------------------+double LotsOptimized()
{
double lot=Lots;
int orders=HistoryTotal(); // history orders totalint losses=0; // number of losses orders without a break//--- select lot size
lot=NormalizeDouble(AccountFreeMargin()*MaximumRisk/1000.0,1);
//--- calcuulate number of losses orders without a breakif(DecreaseFactor>0)
{
for(int i=orders-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false)
{
Print("Error in history!");
break;
}
if(OrderSymbol()!=Symbol() || OrderType()>OP_SELL)
continue;
//---if(OrderProfit()>0) break;
if(OrderProfit()<0) losses++;
}
if(losses>1)
lot=NormalizeDouble(lot-lot*losses/DecreaseFactor,1);
}
//--- return lot sizeif(lot<0.1) lot=0.1;
return(lot);
}
//+------------------------------------------------------------------+//| Check for open order conditions |//+------------------------------------------------------------------+void CheckForOpen()
{
double ma1;
double ma2;
int res;
//+------------------------------------------------------------------+//| Приводим SL и TP к единым целым |//+------------------------------------------------------------------+ double sl=0, tp=0;
sl=NormalizeDouble(SL*Point(),_Digits);
tp=NormalizeDouble(TP*Point(),_Digits);
//--- go trading only for first tiks of new barif(Volume[0]>1) return;
//--- get Moving Average
ma1=iMA(NULL, Timeframe, MA_per1, MovingShift, MODE_SMMA, PRICE_CLOSE,Shift);
ma2=iMA(NULL, Timeframe, MA_per2, MovingShift, MODE_SMMA, PRICE_CLOSE,Shift);
// имя символа, таймфрейм, период, сдвиг средней, метод усреднения, тип цены, сдвиг//--- sell conditionsif(ma1 < ma2) //[1] - номер свечи
{
res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,sl,tp,"",MAGICMA,0,Red);
return;
}
//--- buy conditionsif(ma1 > ma2)
{
res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,sl,tp,"",MAGICMA,0,Blue);
return;
}
//---
}
//+------------------------------------------------------------------+//| Check for close order conditions |//+------------------------------------------------------------------+void CheckForClose()
{
double ma1;
double ma2;
//--- go trading only for first tiks of new barif(Volume[0]>1) return;
//--- get Moving Average
ma1=iMA(NULL,Timeframe,MA_per1,MovingShift,MODE_SMMA,PRICE_CLOSE,Shift);
ma2=iMA(NULL,Timeframe,MA_per2,MovingShift,MODE_SMMA,PRICE_CLOSE,Shift);
//---for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
//--- check order type if(OrderType()==OP_BUY)
{
if(ma1 < ma2)
{
if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,White))
Print("OrderClose error ",GetLastError());
}
break;
}
if(OrderType()==OP_SELL)
{
if(ma1 > ma2)
{
if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,White))
Print("OrderClose error ",GetLastError());
}
break;
}
}
//---
}
//+------------------------------------------------------------------+//| OnTick function |//+------------------------------------------------------------------+voidOnTick()
{
//--- check for history and tradingif(Bars<100 || IsTradeAllowed()==false)
return;
//--- calculate open orders by current symbolif(CalculateCurrentOrders(Symbol())==0) CheckForOpen();
else CheckForClose();
//+------------------------------------------------------------------+//| Trailing Stop / Step |//+------------------------------------------------------------------+double tr=0, ts=0, op=0, sl=0,
ask=NormalizeDouble(Ask,_Digits),
bid=NormalizeDouble(Bid,_Digits);
tr=NormalizeDouble(TStop*Point(),_Digits);
ts=NormalizeDouble(TrailingStep*Point(),_Digits); // Приводим к единым величинам (включая центовые счета)double ma2 = iMA(NULL,Timeframe,MA_per2,MovingShift,MODE_SMMA,PRICE_CLOSE,Shift);
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS)==true)
{
if(OrderSymbol()==Symbol())
{
if(OrderMagicNumber()==Magic_number) // Если Magic = 0, то работает + ручные ордеры
{
op=NormalizeDouble(OrderOpenPrice(),_Digits);
sl=NormalizeDouble(OrderStopLoss(),_Digits);
if(OrderType()==OP_BUY)
{
if((bid-op)>tr)
if((bid-sl)>tr)
if((bid-tr)>ma2)
if(OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(ma2,_Digits),OrderTakeProfit(),0, clrGreen)==false)
Print("Error BUY OrderModify");
}
if(OrderType()==OP_SELL)
{
if((op-ask)>tr)
if((sl-ask)>tr || sl==0)
if((ask+tr)<ma2)
if(OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(ma2,_Digits),OrderTakeProfit(),0, clrGreen)==false)
Print("Error SELL OrderModify");
}
}
}
}
}
}
//+----------------------------------------------------------------------+
Hello, friends, help me solve the following problem: I am trying to write a simple Expert Advisor and was faced with the following: if the SL is set to a value different from 0, then trades are not opened at all, as well as the TP, TStop and TrailingStep do not work at all.
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.
Please advise how to select a symbol in the tester for testing in
You can't. Only manually select in the settings.
In the tester, of course, you can request data on other symbols, but for this you will have to work hard enough to ensure the synchronization of data (the tester itself will not do it for you, because by default it works with one symbol). Trade on the symbol, different from the selected, in general, can not.
P. S. All this is for MT4. In MT5 situation is different.
NO DECOMPILING ALLOWED!
The Expert Advisor works inOnTimer() EventSetTimer(1). I miss many ticks. TheOnTick() event does not fit me because I analyze several currency pairs at once ... Even Sleep(200) in loop will load system...What to do?
There is also EventSetMillisecondTimer() - it can reduce periodicity of OnTimer() execution.
There is also EventSetMillisecondTimer() - so you can reduce the periodicity of OnTimer().
Thanks, I'll try it...
Good afternoon.
The message "Array out of range" appears in the allocated space during the test. It does not indicate an error during compilation. What is the essence of the error and how can we fix it?
double TD_Close=Close[1];
for (int i=2; i<=Period_bars; i++)
{
if (ABS_High<High[i]) ABS_High=High[i];
}
if (TD_Close>ABS_High)
{
if(OrdersTotal () <= 1 && newCandle != Time[0]) int tiket=OrderSend(Symbol(),OP_BUY,volume,Ask,3,sl,tp,",magic,0);
else newCandle = Time[0];
}
Good afternoon.
The message "Array out of range" appears in the highlighted place during the test. It does not indicate an error during compilation. What is the essence of the error and how can we fix it?
double TD_Close=Close[1];
for (int i=2; i<=Period_bars; i++)
{
if (ABS_High<High[i]) ABS_High=High[i];
}
if (TD_Close>ABS_High)
{
if (OrdersTotal () <= 1 && newCandle != Time[0]) int tiket=OrderSend(Symbol(),OP_BUY,volume,Ask,3,sl,tp,",magic,0);
else newCandle = Time[0];
}
Period_bars should be <= Bars - 1
Hello, friends, help me solve the following problem: I am trying to write a simple Expert Advisor and I have faced the following: if the SL is set to a value different from 0, then trades are not opened at all, as well as the TP, TStop and TrailingStep functions do not work at all.
What should I fix in the code?
Hello, friends, help me solve the following problem: I am trying to write a simple Expert Advisor and was faced with the following: if the SL is set to a value different from 0, then trades are not opened at all, as well as the TP, TStop and TrailingStep do not work at all.
What should I fix in the code?