[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 247

 
YES. The intermediate arrays should be the same as the main arrays. The options seem to have been suggested.
 
Swan >> :

but it is advisable to check)

The discrepancy is due to the use of arrays without a shift.


Thank you very much. I figured out the trick through your link. Warning. Gentlemen the situation was that I used BUFFERS under iMAONArray(). And the buffers were initialized in init(). When I ran a visual test, the initial size of the Bars was small. And all arrays are initialized with small size !!! I increased the initialization size to 6000 elements minimum. And that was it! Visual testing of the EA confirmed that the calculation of the indicators was correct. Ha, that's a deal. Now it remains to test on the bar delay. I wonder if the values of the indicators will be different. But we will see on Monday. If anyone has any suggestions for saving operation time and not to make the arrays so large, but for the calculation to be shorter than half a year - feel free to express any ideas, because he who does nothing makes no mistakes.

Please add my case to some FAQ.


It's finally working!

New version of the function:

//-----------------------------------------------------------------------------
int init()                         
{
    SetIndexBuffer(0, tsi);                                 // Назначение массива буферу
    SetIndexBuffer(1, ergodic);                             // Назначение массива буферу
    SetIndexBuffer(2, cross);                               // Назначение массива буферу
    
    SetIndexStyle (0, DRAW_LINE,        STYLE_SOLID, 1);    // Стиль линии DRAW_HISTOGRAM STYLE_SOLID
    SetIndexStyle (1, DRAW_LINE,        STYLE_SOLID, 1);    // Стиль линии        
    SetIndexStyle (2, DRAW_ARROW,       STYLE_SOLID, 0);    // Стиль линии
    SetIndexArrow (2, 161);
    
    SetIndexLabel(0, "TSI");
    SetIndexLabel(1, "Ergodic");
    SetIndexLabel(2, "Cross");
    IndicatorShortName("TSI("+ LengthMtm+","+ LengthSmooth+","+ LengthErgodic+")");    
    
    int BigBars                     = MathMax(Bars, 6000);
    
    ArrayResize(        mtm,        BigBars);
    ArrayResize(        base,       BigBars);
    ArrayResize(        mtmMA,      BigBars);
    ArrayResize(        mtmS,       BigBars);

    ArraySetAsSeries(   mtm,        true);
    ArraySetAsSeries(   base,       true);
    ArraySetAsSeries(   mtmMA,      true); 
    ArraySetAsSeries(   mtmS,       true);


    return(0);                                      
}
Thank you very much for your support. You can use the indicator any way you like. It's a little slow, though. :)))
 

Seems to be working

//--------------------------------------------------------------------
// TSI.mq4 
// Предназначен для использования в качестве трендового индикатора
//--------------------------------------------------------------------

#property indicator_separate_window         // indicator_chart_window, indicator_separate_window
#property indicator_buffers     3           // Количество буферов
#property indicator_color1      Red         // Цвет первой линии Red Blue Lime 
#property indicator_color2      Blue        // Цвет второй линии
#property indicator_color3      Yellow
#property indicator_level1      -20
#property indicator_level2       20
//#property indicator_minimum   -100
//#property indicator_maximum    100

extern int LengthMtm            = 21;
extern int LengthSmooth         = 5;
extern int LengthErgodic        = 5;
extern int HistoryLimit         = 2000;

double tsi[], ergodic[], cross[];           // Объявление массивов (под буферы индикатора)
double mtm[], base[], mtmMA[], mtmS[];


//-----------------------------------------------------------------------------
int MathSgn(double Value = 0.0)
{
    if ( Value < 0) return(-1); else return( 1);
}

//-----------------------------------------------------------------------------
int init()                         
{
    IndicatorBuffers(7);
    SetIndexBuffer(0, tsi);                                 // Назначение массива буферу
    SetIndexBuffer(1, ergodic);                             // Назначение массива буферу
    SetIndexBuffer(2, cross);                               // Назначение массива буферу
    
    SetIndexBuffer(3, mtm);
    SetIndexBuffer(4, base);
    SetIndexBuffer(5, mtmMA);
    SetIndexBuffer(6, mtmS);
        
    SetIndexStyle (0, DRAW_LINE,        STYLE_SOLID, 1);    // Стиль линии DRAW_HISTOGRAM STYLE_SOLID
    SetIndexStyle (1, DRAW_LINE,        STYLE_SOLID, 1);    // Стиль линии        
    SetIndexStyle (2, DRAW_ARROW,       STYLE_SOLID, 0);    // Стиль линии
    SetIndexArrow (2, 161);
    
    SetIndexLabel(0, "TSI");
    SetIndexLabel(1, "Ergodic");
    SetIndexLabel(2, "Cross");


    IndicatorShortName("TSI("+ LengthMtm+","+ LengthSmooth+","+ LengthErgodic+")");    
    
    return(0);                                      
}

//-----------------------------------------------------------------------------
int start()                         
{    
    if ( HistoryLimit == 0) HistoryLimit = Bars;
    
    int Counted_bars            = IndicatorCounted();
    int i, limit                = MathMin(Bars - Counted_bars - 1, HistoryLimit); 
    double tmp;
    for ( i= limit; i>=0; i--) {
        mtm[ i]                  = Close[ i] - Close[ i+1];
        base[ i]                 = High[ i]  - Low[ i];
   }
    for ( i= limit; i>=0; i--) {
        mtmMA[ i]                = iMAOnArray( mtm,   0, LengthMtm,     0, MODE_EMA, i) * 100;
        tmp                     = iMAOnArray( base,  0, LengthMtm,     0, MODE_EMA, i);
        mtmS[ i]=0;
        if ( tmp>0)  mtmMA[ i]   /= tmp;
        mtmS[ i]                 = iMAOnArray( mtmMA, 0, LengthSmooth,  0, MODE_EMA, i);
        tsi[ i]                  = mtmS[ i];
   }
   for ( i= limit; i>=0; i--) {
        ergodic[ i]              = iMAOnArray( mtmS,  0, LengthErgodic, 0, MODE_EMA, i); 
        
         cross[ i]           = EMPTY_VALUE;
        if ( MathSgn( tsi[ i+1] - ergodic[ i+1]) != MathSgn( tsi[ i] - ergodic[ i]) )       
            cross[ i]           = ergodic[ i];


        
    }
    
    return(0);                          
}
 
Check it out, it didn't compress the jpg picture. The png is much lighter, though.
 
Vinin >> :

>> It seems to be working.


Your version is faster than my new one. In EA it flies like that! :))) But I don't understand, if after the visual testing it is thrown on the chart again, the lines are not drawn. Can you suggest what might be the problem?
 
IlyaA писал(а) >>

Your version is faster than my new one. In EA it flies like that! :))) But I don't understand, if it is thrown on the chart again after visual testing, the lines are not drawn. Can you suggest what may be the problem?

I've already corrected it. The post above has been changed.

 
Vinin >> :

I've already corrected it. >> the post above has been changed.


Please re-post, something is not rendering for me again.
 
IlyaA писал(а) >>

Please re-post it, something is not rendering for me again.
Files:
tsi.mq4  4 kb
 
Vinin >> :


There's a trick, when you just take it out on a chart it doesn't draw, but recompiling it helps it learn the numbers, i.e. we do start to see it.
 
IlyaA писал(а) >>

There's a trick, when you just pull it out on a chart it doesn't draw, but recompiling it helps it learn the numbers, i.e. we do start to see it.

I'll have another look tomorrow. It's late today. >> and I'm tired.

Reason: