Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 934

 
Aleksei Beliakov:

Why is the last line without a slash, and is it possible to return a value from a macro

this is macro substitution syntax, string gluing

here is an example of how to return a valuehttps://www.mql5.com/ru/forum/318246/page10#comment_12652228

 
Please, can someone help me?
 
jaffer wilson:
Please, can someone help me?
instead of lyrics - ask questions. Whoever is on the air will consider and help with the substance of the forum.
 
if (MA5>MA20)
{
Signal=1;
}

if(Signal>TradeLevel) // TradeLevel is set to 0.
{
ticket=OrderSend(Symbol(),OP_BUY,Lot,Ask,3,Ask-SL*Point,Bid+TP*Point, "Optim",16384,0,Blue);
}



Can you please tell me why this logic doesn't work? (mql4)
Deals do not open

(everything else, variables, everything is described - standard owl template in MT, no compilation errors)
 
Ivan Butko:

   if (MA5>MA20)
     {
      Signal=1;
     }
   if(Signal>TradeLevel) // TradeLevel установлен в 0.
     {
      ticket=OrderSend(Symbol(),OP_BUY,Lot,Ask,3,Ask-SL*Point,Bid+TP*Point,"Optim",16384,0,Blue);
     } 


Please advise why this logic does not work? (mql4)
The trades do not open

(everything else, variables, everything is described - standard owl template in MT, no compilation errors)

So is the logic not working or are the EA positions not opening?

It is a good habit to look at the "Experts" magazine first - there is a lot to write about. And I would also like to check the "Journal".

I see exactly two errors and one uncertainty when sending a trade request.

 
Artyom Trishkin:

So is the logic not working or are the EA positions not opening?

It is a good habit to look at the "Experts" magazine first - there is a lot to write about. And it does not hurt to look at the "Journal" too.

Just off the top of my head, I see exactly two errors and one uncertainty when sending a trade request.

Thank you, it's working!

Just re-flipped this logic into the standard MACD EA.
Just needed a base to deploy different signals and summarise them.

Apologies for the hassle. (log was empty by the way, no errors either, just didn't open trades and that's it).

If you don't mind, please still point out the error

 

There is a primitive code

templ(T)class CData{
public:CData(){};~CData(){};
       T Total(T &mas[]  ,int y){return(ArraySize(mas));}    
       T Total(T &mas[][],int y){return(ArraySize(mas));}}

Question how to callTotal() function, I want to call it for example in OnInit(), guys please don't be rude, I'm a jackass, I don't understand the help? Do I need to delete the memory of the class, and if so, where and how?

 

GLITCH WHEN CALCULATING RISK PER TRADE.

TASK: Calculate the lot size for an allowable risk per trade of $250 for any instrument (including forex, mullions, CFDs).

MY REALIZATION (for BUY, snippet of function code):

//valSL - размер стопа
//price - цена открытия ордера
//iLots - размер лота
SL_punkt=(price-valSL)/MarketInfo(currencySelect,MODE_POINT); //Переводим денежное выражение в пункты
 double pricePunkt=NormalizeDouble(iLots*MarketInfo(symb,MODE_TICKVALUE)*SL_punkt,MarketInfo(symb,MODE_DIGITS)); //Вычисляем уровень убытка при заданном размере лота

THE PROBLEM: This code correctly calculates losses for all assets, including currency pairs (including crosses), gold, oil, BUT INDEXes, nq100, EXAMPLE,DOES NOT CALCULATE correctly. Namely, my script data (potential deal losses) is consistently 10 times LESS THAN what the MT4 STRATEGY Tester reads!

SOME NOTES:

1. testing was conducted in Alpari terminal.

2. According to the terminal, the way of profit calculation for XAUUSD, BRN (oil) and NQ100 is "CFD", for currency pairs, respectively, "forex".

I think the problem is in the contract size, which I do not take into account (for oil - 1000, for XAUUSD - 100, for NQ100 - 10). But then why XAUUSD, BRN are counting correctly (and currency pairs too), but NQ100 isn't? Maybe, in spite of the fact that in the properties of the Alpari terminal symbol the profit calculation method is "CFD", but in reality it is counted as "Forex"? Is this even possible?

In general, I would appreciate it if somebody would explain me my script error and how to fix it.

THANK YOU!

 
Сергей Михеев:

GLITCH WHEN CALCULATING THE RISK PER TRANSACTION.

MODE _TICKSIZE

 
Yurij Kozhevnikov 2019.08.10 17:57 EN
Сергей Михеев:

GLITCH IN CALCULATION OF RISK PER TRADE.

MODE _TICKSIZE

Read xxxxxxxx

This does not solve the problem, unfortunately. I have

MODE_TICKVALUE равно MODE_POINT и равно MODE_TICKSIZE (для NQ100 это 0.1)

Tried also this variant of code:

double StoimPunkt(string B){
double S = MarketInfo(B,MODE_TICKVALUE)/(MarketInfo(B,MODE_TICKSIZE)/MarketInfo(B,MODE_POINT));return(S);
}
//valSL - размер стопа
//price - цена открытия ордера
//iLots - размер лота
SL_punkt=(price-valSL)/MarketInfo(symb,MODE_POINT); //Переводим денежное выражение в пункты
 double pricePunkt=NormalizeDouble(iLots*StoimPunkt(symb)*SL_punkt,MarketInfo(symb,MODE_DIGITS)); //Вычисляем уровень убытка при заданном размере лота

THE RESULT IS EXACTLY THE SAME AS IN MY EXAMPLE ABOVE.

Any other ideas?

Reason: