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

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
I'm still refining it:
if the condition is true
open order 1
if price has moved where it should or not
open order 2
LastLot= order 2 (or greater number)
LastPrice= order2 (or greater number)
If price has or has not moved where it should have...
LastLot= order 3 (or greater number)
LastPrice= order 3 (or number greater)
The problem is that the last (or not) order will always be between a StopLoss and a TakeOut, which means it won't reset when the others close because the order itself will still be there. How do we bound it to the others if we do not know the number of orders?
The mechanism of binding the last first or penultimate one to the others has proved to be inefficient since their number changes together with the numbers.
The result should be something like "if any order of the given series has closed, close all the others".
Series check - the first order of the current direction (another order will not open) - either an additional identifier or some other binding methods should be used here. The key - the first order is opened according to the conditions, the rest of the orders are auxiliary ones.
any thoughts?
I'm still refining it:
if the condition is true
open order 1
if price has moved where it should or not
open order 2
LastLot= order 2 (or greater number)
LastPrice= order2 (or greater number)
If price has or has not moved where it should have...
LastLot= order 3 (or greater number)
LastPrice= order 3 (or number greater)
The problem is that the last (or not) order will always be between a StopLoss and a TakeOut, which means it won't reset when the others close because the order itself will still be there. How do we bound it to the others if we do not know the number of orders?
The mechanism of binding the last first or penultimate one to the others has proved to be inefficient since their number changes together with the numbers.
The result should be something like "if any order of the given series has closed, close all the others".
Series check - the first order of the current direction (another order will not open) - either an additional identifier or some other binding methods should be used here. The key - the first order is opened according to the conditions, the rest of the orders are auxiliary ones.
Any thoughts?
It is unclear. Try to express your thoughts more clearly.
This is the following:"If the price goes the right way or not, we should open order 2" - how should we understand thatwe should open order 2 in any case?
And we'll get more and more "or else".
And if we don't want to have questions such as"How to connect it with the rest orders when the amount of price is unknown", we should figure out the amount first.
It's confusing, incomprehensible. Try to make your thoughts more clear.
This "if the price moved in the right direction or not - to open order2" - how should we understand that in any case"to open order2"?
And we'll get more and more "or else".
And if we don't want to get into questions like"How to connect it with the rest orders if we don't know the amount", we should first find out the amount.
OK, with numbers
EURUSD=1.10000
a command to open a buy order according to the current order (already written)
if EURUSD=1.10200 we give an order to buy (already written)
if EURUSD=1.09800 to "buy" (it is already written)
and so on with a step of 200
if any of the orders is closed (stops and takeovers are set, but not at all of them)
Close the entire grid
looking for a way to identify the gridOK, with numbers
EURUSD=1.10000
command to open a buy order according to the TP at the current price (already written)
if EURUSD=1.10200 to add to buy order (already written)
if EURUSD=1.09800 to "buy" (it is already written)
and so on with a step of 200
if any of the orders closes (stops and takeovers have already been placed)
close the entire grid
searching for a way to identify the gridComments with the order number can be added. And if the entire series of orders of one type - then they should simply recalculate them and fix the quantity.
I thought about comments, but judging from the feedback the chef thinks they are inedible and either delete them or change them to their own
And as for counting, so I have to count and record the number when adding another one?
and about counting, do I have to count and record the quantity when I add another one?
Yes. And if the number has decreased since the last time - close all the remaining ones.
You can also monitor the closed orders in the history. And close the series when a new order that meets the specified characteristics appears.
You can also not set TP/SL in the order, but calculate the total TP/SL in the Expert Advisor for the entire series. Use them to close the series. The advantages - the brokerage company does not see the breakpoint levels, and the problem of finding the series remains remains if a TP or a SL has triggered at one order.double volume(string symbol,double risk,double sl)
{
double lot=0.0;
double procent=0.0;
double balans=0.0;
double tc = SymbolInfoDouble(symbol,SYMBOL_TRADE_CONTRACT_SIZE);
double tv = SymbolInfoDouble(symbol,SYMBOL_TRADE_TICK_VALUE);
double ts=SymbolInfoDouble(symbol,SYMBOL_TRADE_TICK_SIZE);
double point=SymbolInfoDouble(symbol,SYMBOL_POINT);
if(Type_Balanse==Balance) balans=AccountInfoDouble(ACCOUNT_BALANCE);
if(Type_Balanse==Equity) balans=AccountInfoDouble(ACCOUNT_EQUITY);
if(Type_Balanse==FreeMargin) balans=AccountInfoDouble(ACCOUNT_FREEMARGIN);
procent=(balans/100.0)*risk;
switch((int)MarketInfo(symbol,MODE_PROFITCALCMODE))
{
case 0: if(sl!=0 && tv!=0) lot=procent/(sl*tv);break;
case 1: if(sl!=0 && point!=0 && tc!=0) lot=procent/(sl*point*tc);break;
case 2: if(sl!=0 && point!=0 && tv!=0 && ts!=0) lot=procent/(sl*point*(tv/ts));break;
}
return(NormalizeVolume(symbol,lot));
}
OK, let me ask you a simple question. How do I set the EA to automatically calculate the lot depending on the leverage...say leverage 1:50 deposit 3000...
Try it like this:
{
Comment( cLot(100) );
}
//===============================================================================================
//------------------------------------ Расчет лота по риску ------------------------------------+
//===============================================================================================
double cLot(double Percent=0) {
double Free=AccountFreeMargin(),
One_Lot=MarketInfo(_Symbol,MODE_MARGINREQUIRED),
Min_Lot=MarketInfo(_Symbol,MODE_MINLOT),
cStep=MarketInfo(_Symbol,MODE_LOTSTEP),
Lots_New=0;
if(Percent > 100) {
Percent = 100;
}
if(Percent == 0) {
Lots_New = 0;
return(0);
} else {
Lots_New = MathFloor(Free*Percent/100/One_Lot/cStep)*cStep;
}
if(Lots_New < Min_Lot) {
Lots_New = Min_Lot;
}
if(Lots_New*One_Lot > Free) {
return(0);
}
return(NormalizeDouble(Lots_New,LotDigit()));
}
//===============================================================================================
//-------------------- Кол-во знаков после точки в значении торгового лота ---------------------+
//===============================================================================================
int LotDigit(){
double lotStep = MarketInfo(_Symbol,MODE_LOTSTEP);
return((int)MathCeil(MathAbs(MathLog(lotStep)/MathLog(10))));
}