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

 
Vinin >> :

Each case has its own solution


Let me give you the program code for constructive criticism of the public (please refrain from constructive criticism of the indicator itself). But first a description. This is TSI (true force index). It is based on 1-day Momentum. These increments are smoothed by the correspondential average (21 periods). Now let's add a scaling. To do this, take the difference of high - low and smooth them with the same exponential average (21 periods). Let us divide the smooth momentum by the smooth spread. This ratio is smoothed by a short exponential average (5 periods). We obtained the main line. Now let's smoothen the main line with a hedge (EMA(, 5)) and rejoice, having obtained a signal line. In fact, let's rejoice once again, because we have TSI - a typical trend indicator. In my implementation I have 3 more buffers for "circles", which I use to mark the intersection of the main and signal lines. Gentlemen, let's see the code:

//--------------------------------------------------------------------
// 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()                         
{
    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+")");    
    
    ArrayResize(        mtm,        Bars);
    ArrayResize(        base,       Bars);
    ArrayResize(        mtmMA,      Bars);
    ArrayResize(        mtmS,       Bars);

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


    return(0);                                      
}

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


Let me remind you of the reason for the appeal. If you take the indicator out onto the chart, skip a few candles and add another one of the same kind, you and I will get a divergence in the indicator values. There is also a very strong divergence when this indicator is drawn during visual testing of the EA and later the same indicator is added to the chart. Could you help me with articles or personal experience on this type of error in the indicator? Thank you.
 
The Stop/Play button and speed slider are missing from the tester. What to do?
 
VAM_ >> :
Stop/Play button and speed slider are missing in the tester. What to do?

Raise the tester control panel a little higher... using left mouse button...

 
Dmido >> :

Good day to all)


I have an Expert Advisor. I have an Expert Advisor, it is able to detect big trends and has a good edge on them, but I can barely cover the slippage on the fishless market.

My question is: How do I write the signal for scaling in? The idea is this - I`m adding when there is more than a stop above the first position and the trend is showing.


I am interested in the unit itself which sends a signal to make a deal. I am using the code copied from the standard MACD Sample EA.

How to correct it to perform a long position and then simultaneously close both open and long positions?


But deals multiply like flies and the result is a fucking grail with a thousand open trades((((


Alternatively: visually monitor the EA's performance in real time and refill manually, that's what granite is (art), but it's not a grail...

 
IlyaA >> :
        mtmMA[ i]                = iMAOnArray( mtm,   0, LengthMtm,     0, MODE_EMA, i) * 100;
        mtmMA[ i]               /= iMAOnArray( base,  0, LengthMtm,     0, MODE_EMA, i);

mtmMA - there should be two different arrays. when dividing it, it is desirable to check for inequality to zero.


For intermediate calculations it is more convenient to use a buffer.

If 8 is not enough, one of the solutions is here.

 
Swan >> :

mtmMA - there should be two different arrays. when dividing it, it is desirable to check for inequality to zero.


For intermediate calculations it is more convenient to use a buffer.

If 8 pieces are not enough, one of the solutions is here.






Thank you for your comment. Notice we are talking about the average of the high - low difference. It's always positive. And the average reinforces that trend. I wanted to check, but then I think I'll see in the logbook if anything. Do you think a division error by zero could cause a divergence of graphs added at different intervals.
 
IlyaA >> :


Thanks for the comment. Note we are talking about the average of the high - low difference. It's always positive. And the average reinforces that trend. I wanted to check, but then I think I'll see in the logbook if anything. Do you think a division error by zero could cause a divergence of graphs added at different intervals.

but it is advisable to check)

the discrepancy is due to the use of arrays without shifts.

 
IlyaA писал(а) >>

Let me give the program code for constructive criticism of the public (please refrain from constructive criticism of the indicator itself). But first a description. This is TSI (true force index). It is based on 1-day Momentum. These increments are smoothed by the correspondential average (21 periods). Now let's add a scaling. To do this, take the difference of high - low and smooth them with the same exponential average (21 periods). Let us divide the smooth momentum by the smooth spread. This ratio is smoothed by a short exponential average (5 periods). We obtained the main line. Now let's smoothen the main line with a hedge (EMA(, 5)) and rejoice, having obtained a signal line. In fact, let's rejoice once again, because we have TSI - a typical trend indicator. In my implementation I have 3 more buffers for "circles", which I use to mark the crossing of the main and signal lines. Gentlemen, please send me the code:

Let me remind you the reason of address. If you pull the indicator onto the chart, skip a few candles and add another one like it, we will get a divergence in indicator values. There is also a very strong divergence when this indicator is drawn during visual testing of the EA and later the same indicator is added to the chart. Could you help me with articles or personal experience on this type of error in the indicator? Thank you.

The indicator is fine. If iMAOnArray() is called in a separate loop, you can achieve correct operation of the indicator regardless of its setting time.

You need to break your one loop into three loops.

iMAOnArray() will work more correctly.

 
Swan >> :

but it is advisable to check)

The discrepancy is due to using arrays without a shift.

I don't really understand what it means without a shift. Could you add words, please?

 
IlyaA >> :

I don't really understand what it means without a shift. Add words, please.

Buffer array is shifted when new bar appears. indexes are incremented by 1. normal is not.

the above link describes it in more detail.

Reason: