Going back to the issue of determining stoplosses and takeprofits in the OnTradeTransaction event. I have the following log outputting all fields of the structures (taken from MetaQuotes example), and this is no longer a tester but an online contest. Here we have a buy:
ON 0 transactions (EURUSD,H1) 11:14:23 OrderSendWrapper:0.10 EURUSD BUY JK 0 transactions (EURUSD,H1) 11:14:23 _OrderSend price=1.23575 vol=0.10 GM 0 transactions (EURUSD,H1) 11:14:24 TRADE_TRANSACTION_REQUEST OH 0 transactions (EURUSD,H1) 11:14:24 ------------RequestDescription PK 0 transactions (EURUSD,H1) 11:14:24 TRADE_ACTION_DEAL DJ 0 transactions (EURUSD,H1) 11:14:24 Symbol: EURUSD FN 0 transactions (EURUSD,H1) 11:14:24 Magic Number: 0 PD 0 transactions (EURUSD,H1) 11:14:24 Order ticket: 11670896 PL 0 transactions (EURUSD,H1) 11:14:24 Order type: ORDER_TYPE_BUY JF 0 transactions (EURUSD,H1) 11:14:24 Order filling: ORDER_FILLING_FOK FM 0 transactions (EURUSD,H1) 11:14:24 Order time type: ORDER_TIME_GTC NG 0 transactions (EURUSD,H1) 11:14:24 Order expiration: 1970.01.01 00:00:00 HI 0 transactions (EURUSD,H1) 11:14:24 Price: 1.23579 EG 0 transactions (EURUSD,H1) 11:14:24 Deviation points: 10 DR 0 transactions (EURUSD,H1) 11:14:24 Stop Loss: 1.2354 PJ 0 transactions (EURUSD,H1) 11:14:24 Take Profit: 1.2361 ON 0 transactions (EURUSD,H1) 11:14:24 Stop Limit: 0 MK 0 transactions (EURUSD,H1) 11:14:24 Volume: 0.1 IQ 0 transactions (EURUSD,H1) 11:14:24 Comment: FG 0 transactions (EURUSD,H1) 11:14:24 MF 0 transactions (EURUSD,H1) 11:14:24 ------------ResultDescription JL 0 transactions (EURUSD,H1) 11:14:24 Retcode 10009 ME 0 transactions (EURUSD,H1) 11:14:24 Request ID: 1 RL 0 transactions (EURUSD,H1) 11:14:24 Order ticket: 11670896 NK 0 transactions (EURUSD,H1) 11:14:24 Deal ticket: 10809619 QS 0 transactions (EURUSD,H1) 11:14:24 Volume: 0.1 LJ 0 transactions (EURUSD,H1) 11:14:24 Price: 1.23579 RR 0 transactions (EURUSD,H1) 11:14:24 Ask: 1.23579 PI 0 transactions (EURUSD,H1) 11:14:24 Bid: 1.23566 GE 0 transactions (EURUSD,H1) 11:14:24 Comment: DS 0 transactions (EURUSD,H1) 11:14:24 GE 0 transactions (EURUSD,H1) 11:14:24 Pending Order Ticket 11670896 LR 0 transactions (EURUSD,H1) 1114:24 LG 0 transactions (EURUSD,H1) 11:14:24 ------------TransactionDescription FQ 0 transactions (EURUSD,H1) 11:14:24 TRADE_TRANSACTION_ORDER_ADD HF 0 transactions (EURUSD,H1) 11:14:24 Symbol: EURUSD HM 0 transactions (EURUSD,H1) 11:14:24 Deal ticket: 0 DK 0 transactions (EURUSD,H1) 11:14:24 Deal type: DEAL_TYPE_BUY DQ 0 transactions (EURUSD,H1) 11:14:24 Order ticket: 11670896 DI 0 transactions (EURUSD,H1) 11:14:2424 Order type: ORDER_TYPE_BUY CR 0 transactions (EURUSD,H1) 11:14:24 Order state: ORDER_STATE_STARTED RI 0 transactions (EURUSD,H1) 11:14:24 Order time type: ORDER_TIME_GTC JS 0 transactions (EURUSD,H1) 11:14:24 Order expiration: 1970.01.01 00:00 DE 0 transactions (EURUSD,H1) 11:14:24 Price: 1.23579 QN 0 transactions (EURUSD,H1) 11:14:24 Price trigger: 0 PG 0 transactions (EURUSD,H1) 11:14:24 Stop Loss: 1.2354 LM 0 transactions (EURUSD,H1) 11:14:24 Take Profit: 1.2361 EF 0 transactions (EURUSD,H1) 11:14:24 Volume: 0.1 JI 0 transactions (EURUSD,H1) 11:14:24 NS 0 transactions (EURUSD,H1) 11:14:24 ------------TransactionDescription HH 0 transactions (EURUSD,H1) 11:14:24 TRADE_TRANSACTION_ORDER_DELETE DR 0 transactions (EURUSD,H1) 11:14:24 Symbol: EURUSD LJ 0 transactions (EURUSD,H1) 11:14:24 Deal ticket: 0 PN 0 transactions (EURUSD,H1) 11:14:24 Deal type: DEAL_TYPE_BUY PD 0 transactions (EURUSD,H1) 11:14:24 Order ticket: 11670896 PL 0 transactions (EURUSD,H1) 11:14:24 Order type: ORDER_TYPE_BUY NJ 0 transactions (EURUSD,H1) 11:11:14:24 Order state: ORDER_STATE_FILLED PM 0 transactions (EURUSD,H1) 11:14:24 Order time type: ORDER_TIME_GTC HG 0 transactions (EURUSD,H1) 11:14:24 Order expiration: 1970.01.01 00:00 JI 0 transactions (EURUSD,H1) 11:14:24 Price: 1.23579 OJ 0 transactions (EURUSD,H1) 11:14:24 Price trigger: 0 NS 0 transactions (EURUSD,H1) 11:14:24 Stop Loss: 1.2354 JJ 0 transactions (EURUSD,H1) 11:14:24 Take Profit: 1.2361 FS 0 transactions (EURUSD,H1) 11:14:24 Volume: 0 HE 0 transactions (EURUSD,H1) 11:14:24 HN 0 transactions (EURUSD,H1) 11:14:24 ------------TransactionDescription FI 0 transactions (EURUSD,H1) 11:14:24 TRADE_TRANSACTION_HISTORY_ADD HN 0 transactions (EURUSD,H1) 11:14:24 Symbol: EURUSD HE 0 transactions (EURUSD,H1) 11:14:24 Deal ticket: 0 DS 0 transactions (EURUSD,H1) 11:11:14:24 Deal type: DEAL_TYPE_BUY DI 0 transactions (EURUSD,H1) 11:14:24 Order ticket: 11670896 DQ 0 transactions (EURUSD,H1) 11:14:24 Order type: ORDER_TYPE_BUY RF 0 transactions (EURUSD,H1) 1114:24 Order state: ORDER_STATE_FILLED LQ 0 transactions (EURUSD,H1) 11:14:24 Order time type: ORDER_TIME_GTC DK 0 transactions (EURUSD,H1) 11:14:24 Order expiration: 1970.01.01 00:00 FM 0 transactions (EURUSD,H1) 11:14:24 Price: 1.23579 CF 0 transactions (EURUSD,H1) 11:14:24 Price trigger: 0 RO 0 transactions (EURUSD,H1) 11:14:24 Stop Loss: 1.2354 NE 0 transactions (EURUSD,H1) 11:14:24 Take Profit: 1.2361 RO 0 transactions (EURUSD,H1) 11:14:24 Volume: 0 DQ 0 transactions (EURUSD,H1) 11:14:24 DJ 0 transactions (EURUSD,H1) 11:14:24 ------------TransactionDescription LQ 0 transactions (EURUSD,H1) 11:14:24 TRADE_TRANSACTION_DEAL_ADD FK 0 transactions (EURUSD,H1) 11:14:24 Symbol: EURUSD DR 0 transactions (EURUSD,H1) 11:14:24 Deal ticket: 10809619 PF 0 transactions (EURUSD,H1) 11:14:24 Deal type: DEAL_TYPE_BUY PL 0 transactions (EURUSD,H1) 11:14:24 Order ticket: 11670896 PD 0 transactions (EURUSD,H1) 11:14:24 Order type: ORDER_TYPE_BUY GN 0 transactions (EURUSD,H1) 11:11:14:24 Order state: ORDER_STATE_STARTED FE 0 transactions (EURUSD,H1) 11:14:24 Order time type: ORDER_TIME_GTC NO 0 transactions (EURUSD,H1) 11:14:24 Order expiration: 1970.01.01 00:00:00 HQ 0 transactions (EURUSD,H1) 11:14:24 Price: 1.23579 MR 0 transactions (EURUSD,H1) 11:14:24 Price trigger: 0 LK 0 transactions (EURUSD,H1) 11:14:24 Stop Loss: 1.2354 HR 0 transactions (EURUSD,H1) 11:14:24 Take Profit: 1.2361 QJ 0 transactions (EURUSD,H1) 11:14:24 Volume: 0.1 NR 0 transactions (EURUSD,H1) 11:14:24
And here it closes on Take Profit:
DJ 0 transactions (EURUSD,H1) 11:20:38 ------------TransactionDescription JN 0 transactions (EURUSD,H1) 11:20:38 TRADE_TRANSACTION_ORDER_ADD DH 0 transactions (EURUSD,H1) 11:20:38 Symbol: EURUSD PP 0 transactions (EURUSD,H1) 11:20:38 Deal ticket: 0 PH 0 transactions (EURUSD,H1) 11:20:38 Deal type: DEAL_TYPE_BUY LR 0 transactions (EURUSD,H1)20:38 Order ticket: 11670968 HG 0 transactions (EURUSD,H1) 11:20:38 Order type: ORDER_TYPE_SELL MO 0 transactions (EURUSD,H1) 11:20:38 Order state: ORDER_STATE_STARTED HF 0 transactions (EURUSD,H1) 11:20:38 Order time type: ORDER_TIME_GTC PN 0 transactions (EURUSD,H1) 11:20:38 Order expiration: 1970.01.01 00:00:00 JE 0 transactions (EURUSD,H1) 11:20:38 Price: 1.2361 MS 0 transactions (EURUSD,H1) 11:20:38 Price trigger: 0 MJ 0 transactions (EURUSD,H1) 11:20:38 Stop Loss: 0 IR 0 transactions (EURUSD,H1) 11:20:38 Take Profit: 0 QD 0 transactions (EURUSD,H1) 11:20:38 Volume: 0.1 NO 0 transactions (EURUSD,H1) 11:20:38 NP 0 transactions (EURUSD,H1) 11:20:38 ------------TransactionDescription LN 0 transactions (EURUSD,H1) 11:20:38 TRADE_TRANSACTION_ORDER_DELETE DE 0 transactions (EURUSD,H1) 11:20:38 Symbol: EURUSD PK 0 transactions (EURUSD,H1) 11:20:38 Deal ticket: 0 PM 0 transactions (EURUSD,H1) 11:20:38 Deal type: DEAL_TYPE_BUY LG 0 transactions (EURUSD,H1) 11:20:38 Order ticket: 11670968 HR 0 transactions (EURUSD,H1) 11:20:38 Order type: ORDER_TYPE_SELL HH 0 transactions (EURUSD,H1) 11:20:38 Order state: ORDER_STATE_FILLED FK 0 transactions (EURUSD,H1) 11:20:38 Order time type: ORDER_TIME_GTC NQ 0 transactions (EURUSD,H1) 11:20:38 Order expiration: 1970.01.01 00:00:00 HH 0 transactions (EURUSD,H1) 11:20:38 Price: 1.2361 KL 0 transactions (EURUSD,H1) 11:20:38 Price trigger: 0 GG 0 transactions (EURUSD,H1) 11:20:38 Stop Loss: 0 GI 0 transactions (EURUSD,H1) 11:20:38 Take Profit: 0 RS 0 transactions (EURUSD,H1) 11:20:38 Volume: 0 DJ 0 transactions (EURUSD,H1) 11:20:38 HO 0 transactions (EURUSD,H1) 11:20:38 ------------TransactionDescription JI 0 transactions (EURUSD,H1) 11:20:38 TRADE_TRANSACTION_HISTORY_ADD LN 0 transactions (EURUSD,H1) 11:20:38 Symbol: EURUSD HF 0 transactions (EURUSD,H1) 11:20:38 Deal ticket: 0 HR 0 transactions (EURUSD,H1) 11:20:38 Deal type: DEAL_TYPE_BUY DH 0 transactions (EURUSD,H1) 11:20:38 Order ticket: 11670968 PM 0 transactions (EURUSD,H1) 11:20:3838 Order type: ORDER_TYPE_SELL PF 0 transactions (EURUSD,H1) 11:20:38 Order state: ORDER_STATE_FILLED NQ 0 transactions (EURUSD,H1) 11:20:38 Order time type: ORDER_TIME_GTC FK 0 transactions (EURUSD,H1) 11:20:38 Order expiration: 1970.01.01 00:00 PO 0 transactions (EURUSD,H1) 11:20:38 Price: 1.2361 CF 0 transactions (EURUSD,H1) 11:20:38 Price trigger: 0 OM 0 transactions (EURUSD,H1) 11:20:38 Stop Loss: 0 OG 0 transactions (EURUSD,H1) 11:20:38 Take Profit: 0 JN 0 transactions (EURUSD,H1) 11:20:38 Volume: 0 LP 0 transactions (EURUSD,H1) 11:20:38 PE 0 transactions (EURUSD,H1) 11:20:38 ------------TransactionDescription MR 0 transactions (EURUSD,H1) 11:20:38 TRADE_TRANSACTION_POSITION JH 0 transactions (EURUSD,H1) 11:20:38 Symbol: EURUSD JP 0 transactions (EURUSD,H1) 11:20:38 Deal ticket: 0 FH 0 transactions (EURUSD,H1) 11:20:38 Deal type: DEAL_TYPE_BUY HQ 0 transactions (EURUSD,H1) 11:20:38 Order ticket: 0 DK 0 transactions (EURUSD,H1) 11:20:38 Order type: ORDER_TYPE_BUY GQ 0 transactions (EURUSD,H1) 11:20:38 Order state: ORDER_STATE_STARTED RH 0 transactions (EURUSD,H1) 11:20:38 Order time type: ORDER_TIME_GTC JL 0 transactions (EURUSD,H1) 11:20:38 Order expiration: 1970.01.01 00:00:00 HG 0 transactions (EURUSD,H1) 11:20:38 Price: 1.23579 QP 0 transactions (EURUSD,H1) 11:20:38 Price trigger: 0 LI 0 transactions (EURUSD,H1) 11:20:38 Stop Loss: 1.2354 HO 0 transactions (EURUSD,H1) 11:20:38 Take Profit: 1.2361 QD 0 transactions (EURUSD,H1) 11:20:38 Volume: 0.1 NO 0 transactions (EURUSD,H1) 11:20:38 NP 0 transactions (EURUSD,H1) 11:20:38 ------------TransactionDescription FO 0 transactions (EURUSD,H1) 11:20:38 TRADE_TRANSACTION_DEAL_ADD LE 0 transactions (EURUSD,H1) 11:20:38 Symbol: EURUSD EH 0 transactions (EURUSD,H1) 11:20:38 Deal ticket: 10809689 RQ 0 transactions (EURUSD,H1) 11:20:38 Deal type: DEAL_TYPE_SELL DF 0 transactions (EURUSD,H1) 11:20:38 Order ticket: 11670968 HN 0 transactions (EURUSD,H1) 11:20:38 Order type: ORDER_TYPE_BUY CD 0 transactions (EURUSD,H1) 11:20:38 Order state: ORDER_STATE_STARTED NK 0 transactions (EURUSD,H1) 11:20:38 Order time type: ORDER_TIME_GTC FQ 0 transactions (EURUSD,H1) 11:20:38 Order expiration: 1970.01.01 00:00:00 PI 0 transactions (EURUSD,H1) 11:20:38 Price: 1.2361 CL 0 transactions (EURUSD,H1) 11:20:38 Price trigger: 0 OG 0 transactions (EURUSD,H1) 11:20:38 Stop Loss: 0 OI 0 transactions (EURUSD,H1) 11:20:38 Take Profit: 0 KQ 0 transactions (EURUSD,H1) 11:20:38 Volume: 0.1
The only thing that unites these transactions is price(close price equals the TP price). Question - is that the way to determine the fact of TP? Imho, inconvenient and ambiguous (if I remember correctly, the exact TP price may not happen and TP will be closed at the nearest other price).
Good afternoon! I apologise in advance, maybe I'm being obtuse, or I don't understand some obvious things. I'm trying to use iMA indicator, trying to write according to examples I've read.
In general, I try to do it this way. I declare at the top, above all functions of EA.
double MA[]; // массив для индикатора iMA//---- handles for indicatorsint MA_handle; // указатель на индикатор iMA
Then I use a function that will work in OnTick() function. In the sample, the function itself is at the bottom. In fact, for now, I will use only the last-zero value of the array.
if (EURNZD_d1 != 0.0) countq++;
EURUSD_d1 = CalculateStrengthPairsTF("EURUSD"+dop_symb, PERIOD_D1);
if (EURUSD_d1 != 0.0) countq++;
EURCAD_d1 = CalculateStrengthPairsTF("EURCAD"+dop_symb, PERIOD_D1);
if (EURCAD_d1 != 0.0) countq++;
EURGBP_d1 = CalculateStrengthPairsTF("EURGBP"+dop_symb, PERIOD_D1);
if (EURGBP_d1 != 0.0) countq++;
EURAUD_d1 = CalculateStrengthPairsTF("EURAUD"+dop_symb, PERIOD_D1);
if (EURAUD_d1 != 0.0) countq++;
EURCHF_d1 = CalculateStrengthPairsTF("EURCHF"+dop_symb, PERIOD_D1);
if (EURCHF_d1 != 0.0) countq++;
if (countq != 0) D1_eur = NormalizeDouble((EURJPY_d1 + EURNZD_d1 + EURUSD_d1 + EURCAD_d1 + EURGBP_d1 + EURAUD_d1 + EURCHF_d1) / countq, 0);
}
int l_count_4 = 0;
AVG_eur = 0;
if (M1_eur != 0.0) l_count_4++;
if (M5_eur != 0.0) l_count_4++;
if (M15_eur != 0.0) l_count_4++;
if (M30_eur != 0.0) l_count_4++;
if (H1_eur != 0.0) l_count_4++;
if (H4_eur != 0.0) l_count_4++;
if (D1_eur != 0.0) l_count_4++;
if (l_count_4 != 0) AVG_eur = (M1_eur + M5_eur + M15_eur + M30_eur + H1_eur + H4_eur + D1_eur) / l_count_4;
}
double CalculateStrengthPairsTF(string a_symbol, int a_timeframe) {
int DIGITS_ = SymbolInfoInteger(a_symbol,SYMBOL_DIGITS);
//---MqlTick last_tick;
if(SymbolInfoTick(a_symbol,last_tick));
double BID_ = last_tick.bid;
BID_ = NormalizeDouble( BID_, DIGITS_);
MA_handle=iMA(a_symbol,a_timeframe,Period_,0,method_ma,price_applied);
//--- заполнение массива MA[] текущими значениями индикатора iMA//--- в массив будет записано 100 элементовCopyBuffer(MA_handle,0,0,100,MA);
//--- задаём порядок индексации массива MA[] как в MQL4ArraySetAsSeries(MA,true);
double iMA_ = NormalizeDouble(MA[0], DIGITS_);
Valmars: This is purely a tester bug. Trans.price_tp field in case of TRADE_TRANSACTION_DEAL_ADD may contain 0 or any rubbish. On-line trading outputs everything correctly.
Thank you. Fixed. A fix will be available in the next build.
Please advise why the request.type_filling=ORDER_FILLING_AON; line in the EA contains the error 'ORDER_FILLING_AON' - undeclared identifier cs2011.mq5 127 28 in version 697
Please advise why the request.type_filling=ORDER_FILLING_AON; line in the EA contains the error 'ORDER_FILLING_AON' - undeclared identifier cs2011.mq5 127 28 in version 697
Because the language has changed since the EA was written.
put request.type_filling=ORDER_FILLING_AON in this line;
request.type_filling=ORDER_FILLING_FOK; and good luck.
Or you can just put 0
request.type_filling=0;
will also work.
PS or alternatively (to avoid having to edit the entire EA) you can put a patch at the very top of everything
#define ORDER_FILLING_AON ORDER_FILLING_FOK
This is just in case ORDER_FILLING_AON is mentioned several times.
For some reason I see the following picture: when I paste in the terminal an indicator from the Navigator to a chart, but the chart shows an empty area for the indicator, the indicator itself is not displayed, but if I open the list of chart indices, it appears there with the note "Debugging". What is this bug and how do I fight it?
marketeer: For some reason I see the following picture: when I paste in the terminal an indicator from the Navigator to a chart, an empty area for the indicator appears on the chart, the indicator itself is not displayed, but if I open the list of chart indices, it appears there with the note "Debugging". What is this bug and how do I cope with it?
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.
Going back to the issue of determining stoplosses and takeprofits in the OnTradeTransaction event. I have the following log outputting all fields of the structures (taken from MetaQuotes example), and this is no longer a tester but an online contest. Here we have a buy:
And here it closes on Take Profit:
The only thing that unites these transactions is price(close price equals the TP price). Question - is that the way to determine the fact of TP? Imho, inconvenient and ambiguous (if I remember correctly, the exact TP price may not happen and TP will be closed at the nearest other price).
Good afternoon! I apologise in advance, maybe I'm being obtuse, or I don't understand some obvious things. I'm trying to use iMA indicator, trying to write according to examples I've read.
In general, I try to do it this way. I declare at the top, above all functions of EA.
Then I use a function that will work in OnTick() function. In the sample, the function itself is at the bottom. In fact, for now, I will use only the last-zero value of the array.
I will only use the last-zero-value.
Error 'a_timeframe' - can't convert enum Owl.mq5 2009 28
Regarding this imino variable, it's in the string-type instruction, you see it's glowing blue itself...
Writes error 'a_timeframe' - can't convert enum Owl.mq5 2009 28
Thank you!!! Is it the same as double, string or int? I don't understand, sorry, where do I put this type?
Alright, thanks!
This is purely a tester bug. Trans.price_tp field in case of TRADE_TRANSACTION_DEAL_ADD may contain 0 or any rubbish. On-line trading outputs everything correctly.
Please advise why the request.type_filling=ORDER_FILLING_AON; line in the EA contains the error 'ORDER_FILLING_AON' - undeclared identifier cs2011.mq5 127 28 in version 697
Please advise why the request.type_filling=ORDER_FILLING_AON; line in the EA contains the error 'ORDER_FILLING_AON' - undeclared identifier cs2011.mq5 127 28 in version 697
Because the language has changed since the EA was written.
put request.type_filling=ORDER_FILLING_AON in this line;
request.type_filling=ORDER_FILLING_FOK; and good luck.
Or you can just put 0
request.type_filling=0;
will also work.
PS or alternatively (to avoid having to edit the entire EA) you can put a patch at the very top of everything
#define ORDER_FILLING_AON ORDER_FILLING_FOK
This is just in case ORDER_FILLING_AON is mentioned several times.
For some reason I see the following picture: when I paste in the terminal an indicator from the Navigator to a chart, an empty area for the indicator appears on the chart, the indicator itself is not displayed, but if I open the list of chart indices, it appears there with the note "Debugging". What is this bug and how do I cope with it?
Good people, help!
Take the simplest code.
#property copyright "Copyright 2011,"
#property link "http://www.mql5.com"
#property version "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
double Vhod;
Vhod=linfunc(15);
//---
return(0);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
}
//+------------------------------------------------------------------+
double linfunc(int b) // имя функции и список параметров
{
double a;
while((a/b)<1 && !IsStopped())//---------
{
a=a+1;
}
double f=a+b;
// составной оператор
return(a+b); // возвращаемое значение
}
We compile it on the 687 build and get Vhod=0 in the debugger.
How do you understand it? At the same time, sometimes I got Vhod=30. (strange but true).
return returns some nonsense...
What are these glitches or am I missing something?