[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 660

 
Craft:


Anatoly, thank you very much, it's a pity you can't insert an icon here, like in Skype with a bow. Everything is simple and elegant. I understand from communication with other technical analysis programs that it should be that way, but I'm still out of practice in working with mql. Thanks for the tip on marking in the method - I will figure it out.

For my last tip how to avoid multiple order placements on one bar by this EA? I have already received tips from kind people but they did not help.

I tried to solve your problem and this is what I got. But first things first.

Who is guilty and what to do? Or where do the legs come from...

In your Expert Advisor, different settings of the CCI indicator are used for opening a position (and respectively, for closing the previous one). You have different settings for buying and different settings for selling. As far as I understood it, this is the trick. For example in up-trends, it is more profitable to use less sensitive settings to buy, to allow profits to "grow" (i.e. it makes sense to hold position (i.e. it makes sense to hold a position in a trend for longer). While selling (up-trend) requires more sensitive settings to enable quick entry/exits, e.g. when trying to catch a correction (and therefore staying in the market with a counter-trend position for less time). Everything is very logical and the idea makes sense, but there is one subtle point about this system - what to do if two opposite signals occur simultaneously because of differences in settings (in fact, for the terminal it is two indicators)?

About the blue arrows...

The Expert Advisor on one bar gets a signal for buy and for sell at the same time, and as I wrote above, when you open one position the opposite one should be closed. In this case, the buy signal is given and the sell signal is closed; if there is no sell by that time, the advisor opens BUY. On the next tick, the opposite signal is generated, to sell, and therefore just opened buy is closed. Another observation, have you noticed that only buying (a lot of blue arrows) "wobbles"? Implementation of buy/sell methods, as far as I understood, is taken from tutorial, but there is a feature, that after operation completion, exit from start() method by operator return, i.e. for one tick there can be only one opening/closing. So, when I get a "double signal", all deals are closed (block closing is described first), then block opening deals, and in it buying is described first!!!, and after buying, exit from start(), so that advisor just doesn't have time to get to sales :))) and loops until it gets a "normal" single order.

About solution methods...

There are several ways of solving this problem.
1. The old-fashioned one.
To begin with you can "kill" the idea, and simply set the same parameters for purchases and sales and the problem will disappear by itself.

2. Complicated.
The algorithm of determining the main trend should be written into the Expert Advisor, and, correspondingly, different "weights" of trades should be set. So, when opposite signals arrive, the preference should be given to the one that has a greater "weight" (i.e. the one that is trending).

3. untitled.
Upon receipt of differently directed signals...
Do nothing.

if(Opn_B && Opn_S)return;

This is exactly the option in the file attached below.
I hope I explained everything clearly.
Good luck :)))

Files:
11_3_1.mq4  13 kb
 

Volfram's post has been deleted for multiplying in several threads.

Volfram, you have created your own thread specifically for this purpose. You have already been answered; is that not enough?

P.S. Let me tell you a secret, Volfram: the absence of evident interest in your idea implicitly suggests that it isn't worthy of attention. Accordingly, no one was willing to implement it "for a fee".

 
ToLik_SRGV:

2. Complicated.
We should integrate the algorithm of determining the main trend into the Expert Advisor and hence give different "weights" to trades. So, when opposite signals arrive, the preference should be given to the one that has a greater "weight" (i.e. the one that is trending).

3. untitled.
Upon receipt of differently directed signals ...
Do nothing.

This is exactly the option in the attached file below.
I hope I explained everything clearly.
Good luck :)))

May I add my milestone too... :)

I also started from a textbook. You can make it simpler: It's enough to remove buy close on a sell signal and sell close on a buy signal, i.e. do not use swing trading, which was implemented in Sergey Kovalev's tutorial... Tracking positions should not be done by the ticket, but by the magician. At first I did so and quietly tested my ideas. Then I have written my own functions for work...

ZS. I haven't looked at the code, so I may be wrong about this EA...

 

I can't figure out how to find extrema of a function

I have a data array that stores values:

how to find the fractures - extrema using a data array of 250 elements and store only the numbers of the elements where these extrema are located

 

Guys, I have this question:

The trend detection function explicitly states that if the AC on the first bar is greater than the AC on the second bar (i.e. increasing), but the trend is downtrending (other indices show down), then in this case return zero, i.e. no downward trend... But the EA stubbornly ignores it, what may be the reason?


The function of trend reversal:

int Trend_BBOsMA (string sy, int tf)
{
   if (sy=="" || sy=="0") sy=Symbol();
double
   BB    =iCustom(sy,tf,"BB_MA",13,13,0,1),
   OsMA  =iOsMA  (sy,tf,9,21,5,PRICE_CLOSE,1),
   AC1   =iAC(sy,tf,1),
   AC2   =iAC(sy,tf,2),
   AC3   =iAC(sy,tf,3);
   
   if (BB>0 && OsMA>0 && AC1>AC2) return(1);
   if (BB<0 && OsMA<0 && AC1<AC2) return(-1);
   else return(0);
}

Checking for opening shares (in the beginning, trend check, to which it does not react: trH1 and trM15 ) - further experiments with conditions, don't mind, but the code works...

//============================================================================================== 
   // Доливка 1
//==============================================================================================  
//------------------------- Покупка 1 ------------------------   
   if (AddPose1 &&
         trH1==1 &&                  // Если часовой и 
         trM15==1 &&                 // пятнадцатиминутный тренды восходящие
         Mom5_1>Mom5_2 &&              // найден разворот
         Mom5_2<=Mom5_3 &&             // Моментума
//         Mom5_2<=100.0 &&
//         DeM5_1<=0.6 &&                  // и Демаркер в зоне перепроданности
//         AC1>AC2 &&                    // Ускорение вверх ----------------------- ВОТ ЗДЕСЬ УБРАЛ
         SecondsAfterOpenLastPos(NULL, OP_BUY, 511)>=4*60
      )
         {
            Magic=511;          // Задаём магик... 
            Lots=GetSizeLot();
            divider=1;
//            if (trH1==10 || trM15==10) divider=2;
            Lots_New=NormalizeLot(Lots/divider, true, NULL);
            New_Comm="Buy_M5_Стратегия_1_Доливка1";   // Задаём комментарий для позиции
            OpenPosition(NULL, OP_BUY, Lots_New, 0, 0, Magic, New_Comm);
         }
//------------------------- Продажа 1 ------------------------   
   if (AddPose1 && 
         trH1==-1 &&                 // Если часовой и 
         trM15==-1 &&                // пятнадцатиминутный тренды нисходящие
         Mom5_1<Mom5_2 &&              // найден разворот
         Mom5_2>=Mom5_3 &&             // Моментума
//         Mom5_2>=100.0 &&
//         DeM5_1>=0.4 &&                  // и Демаркер в зоне перекупленности
//         AC1<AC2 &&                    // Ускорение вниз ------------------------ ВОТ ЗДЕСЬ УБРАЛ
         SecondsAfterOpenLastPos(NULL, OP_SELL, 511)>=4*60
      )
         {
            Magic=511;          // Задаём магик... 
            Lots=GetSizeLot();
            divider=1;
//            if (trH1==-10 || trM15==-10) divider=2;
            Lots_New=NormalizeLot(Lots/divider, true, NULL);
            New_Comm="Sell_M5_Стратегия_1_Доливка1";   // Задаём комментарий для позиции
            OpenPosition(NULL,OP_SELL,Lots_New,0,0,Magic,New_Comm);
         }
//==============================================================================================

Maybe someone will see something that I can't see? Thanks.

 
The screenshot does not show the BB_MA indicator. And there are no trend direction checks in the upper code. The BB variable will always contain one value. As far as I understand, BB_MA indicator is a moving average. To determine the moving average direction one should have 2 values on different candlesticks, for example on the first and second candlesticks and compare these values to each other. Therefore we can say that the upper code performs its task only partially.
 
IgorM:

I can't figure out how to find extrema of a function

I have a data array that stores values:

how to find the fractures - extrema using a data array of 250 elements and store only the numbers of the elements where these extrema are located


We create a loop where we loop through the array values. We compare the value in the previous cell of the array with the value in the current cell. If it is higher, we pass to the next iteration of the loop. In brief, we continue the loop as long as the value in each subsequent cell of the array is incremented. As soon as the value becomes smaller than the previous one, we store the number of the previous cell in a pre-declared array, because a trend break has occurred - we have found the peak. Now the trend is going down. Now we run the search until the next cell finds a value higher than the previous one. Once this happens, the number of the previous cell is stored in a predefined array, because a trend reversal occurred - we have found the bottom of the trough. You can put numbers in different arrays, to filter out peaks from troughs. In short, after going through all the array values, we get sorted data (looking for cell numbers in one/two other arrays)
 
drknn:

We set up a loop, in which we loop through the values of the array. We compare the value in the previous cell of the array with the value in the current cell. If it is higher, we pass to the next iteration of the loop. In brief, we continue the loop as long as the value in each subsequent cell of the array is incremented. As soon as the value becomes smaller than the previous one, we store the number of the previous cell in a pre-declared array, because a trend break has occurred - we have found the peak. Now the trend is going down. Now we run the search until the next cell finds a value higher than the previous one. Once this happens, the number of the previous cell is stored in a predefined array, because a trend reversal occurred - we have found the bottom of the trough. You can put numbers in different arrays, to filter out peaks from troughs. In short, after going through all values of the array, we will get sorted data (numbers of cells in one/two other arrays)

yep, so we have to try while - that's up to the first peak, and then ........ - I can't figure it out.
 
drknn:
The screenshot doesn't show the BB_MA indicator. And there are no trend direction checks in the upper code. The BB variable will always contain one value. As far as I understood the BB_MA indicator is a moving average. To determine the moving average direction one should have 2 values on different candlesticks, for example on the first and second candlesticks and compare these values to each other. So we can say that the upper code only partly fulfills its purpose.

No, BB_MA is the Bears&Bulls_MA for short. It adds up the values of bulls and bears and displays them as a histogram, something like McDuck or something similar. Always when the histogram is above zero it is trending up, when it is below it is trending down...

Therefore, checking the direction of the trend is:

if (BB>0 && OsMA>0 && AC1>AC2) return(1);

for UP and

if (BB<0 && OsMA<0 && AC1<AC2) return(-1);

for DOWN, well and

 else return(0);

for Flat.

I.e. function returns 1 if Bears&Bulls_MA is above zero, OsMA is above zero and value of the first AC bar is greater than value of the second AC bar,

and vice versa for the downward trend. Well, for the flat, all the other differences in the charts (for now..., later, when I sort it out, I will connect checking the movement with acceleration/deceleration and reversal).

Positions should only beopened when there is an unambiguous "trend up" or "trend down"... Basically, everything was working, until I added AC to control the speed of currency movement, so as to exclude (partially) opening positions at the end of movement, on trend exhaustion or correction.

So far it's not working... and exactly AC.

 
IgorM:

yep so we have to try by while - that's until the first peak and then ........ - I can't figure it out.

No - the loop should be done through for. I'm going to try to make up a script. The idea is actually feasible.
Reason: