Questions from Beginners MQL5 MT5 MetaTrader 5 - page 833

 
Vladimir Karputov:

First, formulate clearly:

  • the condition for opening a position
  • close position condition

The main conditions for position opening on the example of opening to buy (for sales - mirror):

  1. the fast stochastic line crosses the slow stochastic line upwards
  2. we need to add a condition - if there is an open position to buy, at a new signal (see point above) a trade is opened only when the opening price of the new trade is higher than the opening price of the last open position by a given number of points, for example 30.

The conditions for closing a position (to buy), both conditions must be met

  1. the slow stochastics line crosses the 80 stochastics level from above downwards
  2. a condition needs to be added - this is the second crossing (see point above) for each previously opened position.
Sorry if I didn't explain the closing, on the chart the closing looks like this: two signals to close the trade are marked with red crosses, because the slow (red) stochastic line crosses the 80 level downwards. But the trade is closed only at the second signal/crossing


 
gastinets:

basic conditions for opening a position using the example of a buy opening (for selling mirrored):

  1. the fast stochastic line crosses the slow stochastic line from below to above
  2. We need to add a condition - if there is an open position to buy, at a new signal (see above) a position is opened only when the opening price of a new position is higher than the price of the last open position by a given number of points, for example 30.

***


It seems we missed a condition to open a position: in what range should the indicator be (or a level above or below which the indicator should be) ...

 
Vladimir Karputov:

We seem to have missed the condition for opening a position: in which range the indicator should be (or the level above or below which the indicator should be) ...

If we can lower the level for the sake of simplicity), i.e. the stochastic level is not important for opening

 
gastinets:

If we can lower the level for the sake of simplicity), i.e. the stochastic level is not important for opening

Can we move it to a separate topic, something like "Stochastic Expert Advisor, indented positions"?

 

Let's reschedule.

Shall I make a new topic or will you?

 
gastinets:

let's move it

Should I make a new topic or you do?

Please create a thread in the section:Automated Trading Systems

 
Comments not related to this topic have been moved to "Questions from MQL4 MT4 MetaTrader 4 beginners".
 
Vladimir Karputov:

I think you can make it much simpler - in the Expert Advisor, the threshold for CLOSE set to 100, and give the signal a weight of 0.5 - thus the signal with a weight of 0.5 will NEVER overcome the threshold of 100


Thank you! Seems to be working!

 
Please explain what the problem is. The function is supposed to look through all open positions and count the number of open positions with a given magic number. But in fact it chooses only one from the entire list opened by another EA with the same ticket and magic number, so count is always =0.
int OpenPositions()//проверка открытых позиций
  {
   int count=0;
   for(int z=PositionsTotal()-1; z>=0; z --)
     {
      if(!PositionSelect(_Symbol))
        {
         Print(__FUNCSIG__" позиция не выбрана ",GetLastError()); continue;
        }
      long  ticket = PositionGetInteger(POSITION_TICKET);
            Print(__FUNCSIG__" ТИКЕТ ", IntegerToString(ticket));
      ulong myMN=PositionGetInteger(POSITION_MAGIC);
            Print(__FUNCSIG__" МАГИК ", IntegerToString(myMN));
      if(myMN==Magic)
            count++;
     }
   return(count);
  }