I need advice on the code: I took an adviser from the database, tested it, added it, subtracted it, changed the coefficients to get a good picture, the picture seems to turn out, but nothing works on the demo, it’s the other way around, it’s like evil, I adjust everything as according to the articles taught and charts good for a month by 100% increases. So it’s only for the tester and it’s suitable or should it be tested somehow differently ??? I would also like to remake TreilingParabolikSAR so that not stop losses move along it, but laymen at a given distance from the price, maybe someone will tell you where to get it, so far it has not come across. Here is one of the resulting codes with good graphs - tell me what is wrong, what to fix, although everything may be wrong here ...
Is there a relatively easy way to convert a date from a "non-standard" string format to datetime or at least an easily convertible string format?
In particular, if the month in the string is Jan/Jeb/..., how do I feed it to the script? I mean, only by manually picking the month from the string, by replacing it with the appropriate number in 12 variations? Or am I missing somewhere how to specify the format for StringToTime etc?
I've got a construction like this handling it right now:
int nmonth = buff[1]=="Jan"?01:buff[1]=="Feb"?02:buff[1]=="Mar"?03:buff[1]=="Apr"?04:buff[1]=="May"?05:buff[1]=="Jun"?06:
buff[1]=="Jul"?07:buff[1]=="Aug"?08:buff[1]=="Sep"?09:buff[1]=="Oct"?10:buff[1]=="Nov"?11:buff[1]=="Dec"?12:01;
...but somehow I don't like it, although it works conventionally.
#property copyright""#property link""#property version"1.00"//--- input parametersinputushort StopLoss=600;
inputushort TakeProfit=450;
inputint EA_Magic=12345; // Magic Number советникаinputuchar ma_period_1=5;
inputuchar ma_period_2=15;
inputuchar ma_period_3=30;
inputdouble Lot=0.01;
//--- глобальные переменныеint STP,TKP; // будут использованы для значений Stop Loss и Take Profit//+------------------------------------------------------------------+//| Expert initialization function |//+------------------------------------------------------------------+intOnInit()
{
//--- Для работы с брокерами, использующими 5-ти значные котировки,//--- умножаем на 10 значения SL и TP
STP = StopLoss;
TKP = TakeProfit;
//---return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| Expert deinitialization function |//+------------------------------------------------------------------+voidOnDeinit(constint reason)
{
}
//+------------------------------------------------------------------+//| Expert tick function |//+------------------------------------------------------------------+voidOnTick()
{
double MA_1_t = iMA(NULL,0,ma_period_1,0,MODE_EMA,PRICE_CLOSE);
double MA_2_t = iMA(NULL,0,ma_period_2,0,MODE_EMA,PRICE_CLOSE);
double MA_3_t = iMA(NULL,0,ma_period_3,0,MODE_EMA,PRICE_CLOSE);
//---MqlTick latest_price; // Будет использоваться для текущих котировокMqlTradeRequest mrequest; // Будет использоваться для отсылки торговых запросовMqlTradeResult mresult; // Будет использоваться для получения результатов выполнения торговых запросовMqlRates mrate[]; // Будет содержать цены, объемы и спред для каждого бараZeroMemory(mrequest); // Инициализация полей структуры mrequest//--- Получить текущее значение котировки в структуру типа MqlTickif(!SymbolInfoTick(_Symbol,latest_price))
{
Alert("Ошибка получения последних котировок - ошибка:",GetLastError(),"!!");
return;
}
//--- есть ли открытые позиции?bool Buy_opened=false; // переменные, в которых будет храниться информация bool Sell_opened=false; // о наличии соответствующих открытых позицийif(PositionSelect(_Symbol)==true) // есть открытая позиция
{
if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
{
Buy_opened=true; //это длинная позиция
}
elseif(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
{
Sell_opened=true; // это короткая позиция
}
}
bool Buy_Condition_1=(MA_1_t > MA_2_t && MA_2_t > MA_3_t);
//--- собираем все вместеif(Buy_Condition_1)
{
// есть ли в данный момент открытая позиция на покупку?if(Buy_opened)
{
Alert("Уже есть позиция на продажу!!!");
return; // не добавлять к открытой позиции на продажу
}
mrequest.action = TRADE_ACTION_DEAL; // немедленное исполнение
mrequest.price = NormalizeDouble(latest_price.ask,_Digits); // последняя цена ask
mrequest.sl = NormalizeDouble(latest_price.ask - STP*_Point,_Digits); // Stop Loss
mrequest.tp = NormalizeDouble(latest_price.ask + TKP*_Point,_Digits); // Take Profit
mrequest.symbol = _Symbol; // символ
mrequest.volume = Lot; // количество лотов для торговли
mrequest.magic = EA_Magic; // Magic Number
mrequest.type = ORDER_TYPE_BUY; // ордер на покупку
mrequest.type_filling = ORDER_FILLING_FOK; // тип исполнения ордера - все или ничего
mrequest.deviation=100; // проскальзывание от текущей цены//--- отсылаем ордерOrderSend(mrequest,mresult);
// анализируем код возврата торгового сервераif(mresult.retcode==10009 || mresult.retcode==10008) //запрос выполнен или ордер успешно помещен
{
Alert("Ордер Buy успешно помещен, тикет ордера #:",mresult.order,"!!");
}
else
{
Alert("Запрос на установку ордера Buy не выполнен - код ошибки:",GetLastError());
return;
}
}
}
MA_1_t - small period, MA_2_t - medium period, MA_3_t - large period.
If I do the following conditions:
then trades are opened.
The conditions are reversed:
Not a single trade. What could be the reason?
EA code:
To get an indicator value, you need to create an indicator handle in OnInit, and then copy the value into an array using CopyBuffer in OnTick. The article Trading Operations in MQL5 just shows you how to write easier code to open/close a position/order.
paladin800: To get the value of the indicator you need to create an indicator handle in OnInit, and then copy the value into an array using CopyBuffer in OnTick. The article Trading Operations in MQL5 just shows how to write easier code for opening/closing a position/order.
Thank you! It's quite different in MQL4, it's simpler. But MQL5 is faster and more accurate, in my opinion.
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 don't understand why the data on the zero bar is not correct, please advise
I get this result
2013.10.27 17:45:26 Core 1 2013.01.01 00:00:00 369878 2012.12.31 19:00:00 2012.01.02 00:00:00
2013.10.27 17:45:26 Core 1 2013.01.01 00:00:00 369878
I forgot to tell the whole thing in the expert.
Or in other words when testing EA from XXX date to YYY date, to what depth from XXX data can be downloaded?????????????????
I need advice on the code: I took an adviser from the database, tested it, added it, subtracted it, changed the coefficients to get a good picture, the picture seems to turn out, but nothing works on the demo, it’s the other way around, it’s like evil, I adjust everything as according to the articles taught and charts good for a month by 100% increases. So it’s only for the tester and it’s suitable or should it be tested somehow differently ??? I would also like to remake TreilingParabolikSAR so that not stop losses move along it, but laymen at a given distance from the price, maybe someone will tell you where to get it, so far it has not come across. Here is one of the resulting codes with good graphs - tell me what is wrong, what to fix, although everything may be wrong here ...
Testing a certain value, above which a trade is opened.
Parameters for entry:
bool Sell_Condition = (signal >= sgl);I choose the value of variable sgl in the tester:
variable type "signal" double.
When running a single test I see that with sgl=0.003 the entry is performed at 0.0024, 0.0027, 0.0015, etc.
The triggering logic is correct, but the execution accuracy is not.
How can I improve the execution accuracy?
...
How do you improve the accuracy of your performance?
Try it:
Is there a relatively easy way to convert a date from a "non-standard" string format to datetime or at least an easily convertible string format?
In particular, if the month in the string is Jan/Jeb/..., how do I feed it to the script? I mean, only by manually picking the month from the string, by replacing it with the appropriate number in 12 variations? Or am I missing somewhere how to specify the format for StringToTime etc?
I've got a construction like this handling it right now:
...but somehow I don't like it, although it works conventionally.
MA_1_t - small period, MA_2_t - medium period, MA_3_t - large period.
If I do the following conditions:
bool Buy_Condition_1=(MA_1_t < MA_2_t && MA_2_t < MA_3_t);then trades are opened.
The conditions are reversed:
bool Buy_Condition_1=(MA_1_t > MA_2_t && MA_2_t > MA_3_t);Not a single trade. What could be the reason?
EA code:
MA_1_t - small period, MA_2_t - medium period, MA_3_t - large period.
If I do the following conditions:
then trades are opened.
The conditions are reversed:
Not a single trade. What could be the reason?
EA code:
To get the value of the indicator you need to create an indicator handle in OnInit, and then copy the value into an array using CopyBuffer in OnTick. The article Trading Operations in MQL5 just shows how to write easier code for opening/closing a position/order.
Can you tell me how to close a pending order that did not open? I am trying to do it this way:
Or in line mrequest.price=NormalizeDouble(Bid-(SL-45) *_Point,_Digits); should I write other information? Thank you.Can you tell me how to close a pending order that has not opened? I am trying to do it this way:
Or in line mrequest.price=NormalizeDouble(Bid-(SL-45) *_Point,_Digits); should I write other information? Thank you.