Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1559
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
Good afternoon gentlemen programmers!!!
Please help a newbie with a function.
The function counts the total profit by history.
The problem is that it works for one broker and it doesn't want to work for another one.
It works on Hercic but not on RoboForex. I have an ECN account on RoboForex.
I don't know what the problem is. Here is the code:
double lastloss()
{
int typ = -1,cnt = 0;
double lastloss = 0;
for(int i = OrdersHistoryTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
{
if(cnt == 0) typ = OrderType();
if(cnt > 0 && OrderType()!= typ) break;
lastlos += OrderProfit() + + OrderSwap() + OrderCommission();
cnt++;
}
}
}
return(lastlos);
}
I wonder if the compiler doesn't swear at this line?
lastlos += OrderProfit() + + OrderSwap() + OrderCommission();
Maybe one + needs to be removed, for it to work correctly?
And why are you adding swap and commission to profits? Even thoughCould be negative too...
And what kind of total profit are we talking about if you process only 1 or few matching orders but not all of them?
Next:
cycle stopping.
1)At high speed or if not on ticks in the tester it will close at the first available price.
2)You have a lot increase going on and with a big lot 1 point may be more than the allowable level.
3)I don't understand what you want, what do you need to track if zeroing after every trade?
3)I don't understand what you want to track if zeroing out after every trade?
I'm talking about tracking the profit/loss "inside" each trade, that is, while the price is "hovering" between stop and take, the amount of profit and loss from the current trade changes as well. It often happens so that the price comes to the profit zone but does not reach the take point - it turns around and the deal is closed at the stop. I need tracing of profit and loss (in money) in order to be able to timely fix it without shifting a stop and take, i.e. without breaking set parameters of take and stop. This is relevant for large lots with an enabled Martin.
When a deal is closed - the tracking stops and starts over for a new deal.
3)I don't understand what you want to track if zeroing out after every trade?
I'm talking about tracking the profit/loss "inside" each trade, i.e. while the price is "waffling" between the stop and the take, the amount of profit and loss of the current trade changes. It often happens so that the price comes to the profit zone but does not reach the take point - it turns around and the deal is closed at the stop. I need tracing of profit and loss (in money) in order to be able to timely fix it without shifting a stop and take, i.e. without breaking set parameters of take and stop. This is relevant for large lots with an enabled Martin.
When a trade is closed, the tracking stops and starts over for a new trade.
You only need to specify parameters of profit and loss less stoploss and takeprofit, i.e.
if TakeProfit is 200 pips 0.1 lot, then the profit is $20, set the profit level of $15 and the trade will close earlier
And why are you adding swap with commission to profit? With
can also be negative...
Thank you for that, I' ve been doing this stupid thing too
All you have to do is specify the profit and loss parameters less stoploss and takeprofit, i.e.
If TakeProfit is 200 pips 0.1 lot, then the profit is $20, set the profit level at $15 and the trade will close earlier
Ok, thanks, I will think about it and run it in the tester.
I'm asking for help from the community...
How to declare and create MQL5 global objects correctly?
If I do it this way:
The compiler complains about the line in OnTick(): 'NB_M1' - undeclared identifier, which is logical, because a local variable is created in OnInit().
If you insert the global declaration before OnInit():
it compiles without errors and expert works. It seems that the object is created twice - during the global declaration and in OnInit().
But thecompiler has thiswarning
declaration of 'NB_M1' hides global variable -> per line in OnInit()
see previous declaration of 'NB_M1'
Does it mean that a local variable (within a function) is created in OnInit() that hides a global variable with the same name ?
And if so, how can this local variable be "seen" by another function, OnTick() ?
Thank you for that, I did that stupid thing too.
Makar, you used to do the right thing and now you want to do the stupid thing...
Think back to your 5th or so grade maths. How much is (-3)-(-7) and how much is (-3)+(-7)?
It's hard to check on a calculator, Excell to help you.
Hello. Do you know any library available in MQL for writing data structures to a file and loading them afterwards? Ideally a library that works with json format,json parser, etc.
I don't know how to tell you to read the documentation. If you have read it and the standard function is not suitable for some reason, you should have said so...
Makar, you used to do the right thing and now you want to do the stupid thing...
Think back to your 5th or so grade maths. How much is (-3)-(-7) and how much is (-3)+(-7)?
It's hard to check on a calculator, Excell to help you.
Yes, thank you. I jumped to conclusions. I got it right)