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
firstly, it is incorrect to compare real Stochast_ and integer 75, and secondly, it is more correct to compare their difference to zero.
Another problem arises with the Position Closing Block. I put this block in my favourite Expert Advisor. It only opens deals strictly in the direction of the trend (my congratulations to it for that...)
But depending on the strength of the trend, the Expert Advisor is (and does it!) consistently able to open several deals, - one after another! This is where I need the block of closing positions at the signal of the indicator. But here is the problem! When and if several positions are opened within a trend and correction against the trend starts, the indicator in the block gives a signal to close. As I need it.
However, for some reason, not all open positions are closed. Basically, only the earliest one. Those which have been opened later do not react to the closing signal - but continue movement. And further, - "history repeats itself like a farce"! With each closing signal, only one, the earliest open position is closed, and the others continue to move! The lot of all positions is constant.
Here is the visual mode chart. Closing by the signal of the indicator is marked with a green triangle. It is clearly seen that only one position is closed each time by the signal. I would like all open positions to be closed! Please advise me, what is the reason?
A reminder of code :
/********* Закрытие позиций **************************************** if (AutoClose) { //---------------------------------------------------------------------- if (ExpertOrder(MagicLong)) { //есть открытые ордера на покупку if(Stochast_1>=Up_lim && Stochast_0<Up_lim) { OrderClose(OrderTicket(),OrderLots(),Bid,3,Green);//закрываем позицию return(0); // выходим } } //-------------------------------------------------------- if (ExpertOrder(MagicShort)) { //есть открытые ордера на продажу if(Stochast_1<=Low_lim && Stochast_0>Low_lim) { OrderClose(OrderTicket(),OrderLots(),Ask,3,Green);//закрываем позицию return(0); // выходим } } //------------------------------------------------------- } //if (AutoClose)
Another problem arises with the Closing Block...
Where is the loop on OrdersTotal() ?
No, that's not the case here. Orders are defined - differently:
And this version of the code is more comfortable for me! Because my long and short positions open independently of each other.
However, it's still the same with the standard closure. ...
However, it's still the same with the standard closure. ...
You may want to try doing a reverse loop from OrdersTotal to 0. That should help.
How to do it? Please write, if it's not too much of a burden. Here's the chart by the way - with the above "standard": Everything is the same - only one position closes on the signal of the indicator -
How do you do that?
for (int v=0; v<OrdersTotal(); v++)
write:
for (int v=OrdersTotal()-1; v>0; v--)
It works for me.
How do you do it?
for (int v=0; v<OrdersTotal(); v++)
write:
for (int v=OrdersTotal()-1; v>0; v--)
It works for me.
You're absolutely right. Although KimV has scripts and libraries which implement all this. Maybe you should look for it on his forum.