Stochastic indicator. A curious observation. - page 6

 
leonid553:

Without trailing, it would still be possible to track a prohibited LONG trade by its stoploss and takeprofit.

But with trailing.... I don't even know how to approach the solution.

Apparently, we need to provide a block that imitates a prohibited trade. I looked through the examples, but didn't find anything similar.


What are we talking about, a specific Expert Advisor or in general?

In my opinion, you could just comment out the block for opening long positions and that's it.

 

No. It won't work that way. If we comment out the long position opening block, this is what will happen:

For example, we opened a short position. It is closed. Then we have a signal for a long position but it is not opened because it is prohibited (or commented out). But after a certain amount of time we get a signal to enter a short position and the long position is opened again.

But we don't need it. For at this time (for example) there must be in the market the long one that we interdicted (commented out).

Thus, upon commenting we will always open short positions - those that we need. AND PLUS THOSE THAT WE DO NOT NEED! Because instead of long commented positions will often open additional short positions, which we do not need!

and we need a time when there would be a prohibited (commented) long position - so that at the same time not to open short positions!

That's why we need to simulate long....

 
leonid553:
That's why you need a long.... simulation
It seems to me that the simplest solution would be to reduce the lots of long positions to the minimum permitted by the broker (down to 0.01), and open short positions with the normal lot. Trailing and everything else would work properly, and the impact of unprofitable (long) positions on the financial result would be virtually eliminated.
 

Thank you, granit77 ! Indeed. It could be done like this.

Well, here's one solution already....!

 

In principle, the solution could be as follows:

Introduce a whole flag, say F. When there are no positions F=0, when long is open F=1, when short F=-1. The value of F changes upon arrival of the corresponding signal, but only by 1. That is, a change from F=1 to F=-1 is impossible. This should be placed after the operators that open the position (we can even insert a condition that F changes only on successful operation).

The main point: if the BUY signal has arrived, at F=1 nothing happens (it is already opened), at F=0 the long position is opened, at F=-1 the short one is closed. Correspondingly, it is vice versa at SELL. With this code structure, just comment out BUY or SELL. Or both at once (for example, to collect statistics on signals, but without trading). The only subtlety - F change upon the signal arrival should be unconditional. Therefore, if there is a check for successful opening-closingof a position, it should also be commented out.

 
Thanks, Yurix ! I think I've got the idea. I'll try to think about it here...
 
Yurixx:

As a matter of principle, the solution could be as follows:

What about the triggering of SL/TP positions? If SL buy is triggered, F should become = 0, and it would remain == 1.

If you want to trade with a virtual Expert Advisor, please contact me.
You will be able to do anything with positions.
 

I guess I'll have to do that. Have you remembered, komposter, that my positions are opened with a trailing stop? And with calling trailing library, too!

Will this imitation work?

 
leonid553:

I guess I'll have to do that. Have you remembered, komposter, that my positions are opened with a trailing stop? And with calling trailing library, too!

Will this imitation work?

My virtual trading completely replaces all trading functions.
Therefore any changes in orders are handled as in real (only there are no server errors).

- the trailing stop will move the virtual SL
- the library will check if the SL is too close to the current price
- When the price approaches the virtual SL it (SL) will trigger (virtually)

Full simulation of real operation ;)
 
komposter:
Yurixx:

As a matter of principle, the solution could be as follows:

What about the triggering of SL/TP positions? If the SL buy is triggered, F should become = 0 and it will remain == 1.

If you want to trade with a virtual Expert Advisor, please contact me.
You will be able to do anything with positions.


I offered Leonid an elementary solution to the problem. It requires a minor modification of the code, which can be done by someone not too experienced in MQL. Including Leonid. And he did it for free. And I haven't even seen the Expert Advisor's code. And I can still say that your question is being solved.

Can you do cooler? For cheap ? :-) I don't doubt it. Me neither. For free. Shall we compete?

Reason: