THE IDEA EXCHANGE - page 9

 
FION:
Experts can work simultaneously - each with its own wizard, and recognition of market conditions and resetting should be in every expert. If this condition is not met, when the market situation changes, losses are inevitable, because the targets and stops should be different in a flat and a trend. Besides, we should consider intermediate conditions - the low flat, or "slippage" with low activity. Basically, the set of profitable Expert Advisors should show the best results due to locking of losing Expert Advisor positions.

Almost everyone has its own realization. But many EAs do not have error correction. I certainly don't. I just try to avoid them. If we do something standard, we should allow for that. I would add a symbol() to magician, although it may be unnecessary. Theoretically, an order with one ticket cannot be repeated, although it may be.
 

Yes, of course. That's exactly what I did in the code. In the external parameters we also set Magic _n, and each version with its own magician will work according to its own algorithm.

 

On trend detection. The ProtoType-IV Expert Advisor provides an example for a multi-currency Expert Advisor that identifies a trend by four last extrema. I have scrupulously penetrated into it and "half-heartedly" allocated this bit of code and now it can be inserted into any Expert Advisor. If necessary. If you set it in external parameters

extern int     PeriodWPR=8;
extern double  CriteriaWPR=25;
extern int     ATRPeriod=40;// период ATR для индикатора 
extern double  kATR=0.5;
//-------------------------------------
int  LastUpArray[13,7];
int  PreLastUpArray[13,7];
int  LastDownArray[13,7];
int  PreLastDownArray[13,7];

Here is the "qualifier" itself:

/-------------------------------------------------------------------+
//| определение тренда по четырем последним экстремумам              |
//+------------------------------------------------------------------+
int TrendByWPR()
  {
//----
   int res=0;
   int curPos,LastUpPos,PreLastUpPos,LastDownPos,PreLastDownPos,LastPeak,newPos;
   bool FindUp=true,FindDown=true,SearchCompleted=false;
   double CurWPR=iWPR(NULL,0,PeriodWPR,0);
//----
   //=======  определим - где мы находимся в данный момент
   if (CurWPR<=CriteriaWPR-100)
      {
      FindDown=false;
      LastPeak=0;
      }   
   if (CurWPR>=-CriteriaWPR)
      {
      FindUp=false;
      LastPeak=0;
      }   
   // ================   начианем поиск пичков-донышков
   while(!SearchCompleted && curPos<Bars)
      {
      if (iWPR(NULL,0,PeriodWPR,curPos)>=-CriteriaWPR && LastPeak<0)
         {
         FindUp=false;
         LastPeak=curPos;
         curPos++;
         continue;
         }
         
      if (iWPR(NULL,0,PeriodWPR,curPos)<=CriteriaWPR-100 && LastPeak<0)
         {
         FindDown=false;
         LastPeak=curPos;
         curPos++;
         continue;
         }
         
      if (iWPR(NULL,0,PeriodWPR,curPos)>=-CriteriaWPR && FindUp)
         {//искали верхушку и нашли
         newPos=curPos; 
         while(iWPR(NULL,0,PeriodWPR,curPos)>CriteriaWPR-100 && curPos<Bars)
            {// теперь нужно найти донышко, чтобы между ними найти точный пичок
            curPos++;
            }
         if (LastUpPos==0) 
            {
            LastUpPos=Highest(NULL,0,MODE_HIGH,curPos-LastPeak,LastPeak);   
            LastPeak=LastUpPos;
            }
         else 
            {
            PreLastUpPos=Highest(NULL,0,MODE_HIGH,curPos-LastPeak,LastPeak);
            LastPeak=PreLastUpPos;
            }
         curPos=newPos;
         FindUp=false;
         FindDown=true;
         curPos++;
         continue;
         }//==============
 
      if (iWPR(NULL,0,PeriodWPR,curPos)<=CriteriaWPR-100 && FindDown)
         {
         newPos=curPos; 
         while(iWPR(NULL,0,PeriodWPR,curPos)<-CriteriaWPR && curPos<Bars)
            {
            curPos++;
            }
         if (LastDownPos==0) 
            {
            LastDownPos=Lowest(NULL,0,MODE_LOW,curPos-LastPeak,LastPeak);
            LastPeak=LastDownPos;
            }   
         else 
            {
            PreLastDownPos=Lowest(NULL,0,MODE_LOW,curPos-LastPeak,LastPeak);
            LastPeak=PreLastDownPos;
            }
         curPos=newPos;
         FindDown=false;
         FindUp=true;
         curPos++;
         continue;
         }
      if (PreLastDownPos!=0 && PreLastUpPos!=0) SearchCompleted=true;
      curPos++;
      }
  /* if (Symbol()==StringSymbol && Period()==PeiodMinute)
      {
      Comment("LastUpPos=",LastUpPos,"  PreLastUpPos",PreLastUpPos,"  
 LastDownPos=",LastDownPos,"  PreLastDownPos=",PreLastDownPos,
" Время ",TimeToStr(CurTime()));
      SetUpArrows(LastUpPos,PreLastUpPos,LastDownPos,PreLastDownPos);*/
   LastUpArray[NULL,0] =LastUpPos;   
   PreLastUpArray[NULL,0]=PreLastUpPos;   
   LastDownArray[NULL,0]=LastDownPos;   
   PreLastDownArray[NULL,0]=PreLastDownPos;   
  if (High[LastUpPos]-High[PreLastUpPos]>=kATR*iATR(NULL,0,ATRPeriod,LastUpPos)
&&Low[LastDownPos]>Low[PreLastDownPos]) res=1;     
  if (Low[PreLastDownPos]-Low[LastDownPos]>=kATR*iATR(NULL,0,ATRPeriod,LastDownPos)
&&High[PreLastUpPos]>High[LastUpPos]) res=-1;    
   
   return(res);
  }

The graph in the corner shows the function=0,, or =1, or=-1

 
I think it is more convenient to define the trend with the help of linear regression, the script of linear regression from MT-4 standard set is very good, I would like to make an indicator based on it, may be somebody knows where to get the source code? All known implementations poorly operate in the dynamics of price changes.I need a channel of set length from 1 to N bar with recalculation when a new bar appears and the possibility to output its width in pips and its slope in pips to the length.And the same channel of standard deviation with a given deviation would be nice to make. We could start digging from scratch, but if someone has a source from MT it would be much easier.
 

I didn't just post the code for trend detection, though. Another idea came up...(I'll explain it later)

Maybe this indicator will work for starters:

On the chart iPeriod=20, MASoot=20

I have not got into its work. But in visual mode it's easy to see how it works...

Files:
 
Thanks Leonid, but it does not work correctly for reversals, I tried it long ago. Here is a good indicator, but it works by How-low, the idea is the same but based on linear regression.
Files:
 
FION:
In my opinion, it is more convenient to define the trend using linear regression, the script of linear regression from MT-4 standard set is very good, I would like to make an indicator based on it, may be somebody knows where to get the source code? All known implementations do not work well with price trend. I need a channel of set length from 1 to N bar with recalculation when a new bar appears and the possibility to output its width in pips and its slope in pips to the length. It would be nice to have the same channel of standard deviation with the given deviation. We can start from scratch, but if someone has a source from MT it would be much easier.


I've posted it somewhere before. I can post the new version. One error has been fixed.

And here is the indicator.

The number of bars is displayed on the screen. 3 sigmas are displayed. If the price is within one SCO, recalculation is not performed, as everything is in permissible limits. When the price breaks through it, it will be recalculated.

Files:
 

Vinin , your channel is very decent and adjusts correctly. Thank you. I'll share one idea about the filter for the flat. We all remember Rev. Reshetov and his perceptrons. In principle a perceptron is a linear filter. I want to try to filter the fllet with a perceptron. I want to input width and slope of 2 linear regression channels of different length, Bolinger width and price change rate. I think what to use as an optimization criterion. Perhaps a rebound from the Bollinger Boundaries to the inside - with the target of 75% of the width.

 
FION:

Vinin , your channel is very decent and adjusts correctly. Thanks, I'll share one idea about the filter for the flat. We all remember Rev. Reshetov and his perceptrons. In principle a perceptron is a linear filter. I want to try to filter out flying by perceptron. I want to input width and slope of 2 linear regression channels of different length, Bolinger width and price change speed. I think what to use as an optimization criterion. Perhaps a rebound from the Bollinger Boundaries to the inside - with the target of 75% of the width.


Reshetov's perceptron will not do. We should make a Kohonen layer of at least 4-5 non-Roynes. But there will be only one problem - all values must be of the same order.
 
I want to create a new topic, Neural analysis of candlesticks. I'm going to post all of my work, I can't do it alone. I will be able to do it all by myself.