I had posted this along time ago ... 

You supply:

- The array in the first statement ( Assumedly Price )
- The Indicator in the Calc = statement
- The Goal in the Goal = statement

... It will return in Explore the value needed in the array in the 
next bar to have the indicator meet the goal in the next bar.

This is set up for use with a typical MACD but can be easily modified 
for use with any indicator you can design.

P0   = C;

Acc  = 0.00001;

LVBI = LastValue(BarIndex());
Mult = 1;

for (i = 0; i < 10; i++)
{ 
    If (P0[LVBI] >= 1) 
        i = 99; 
    else 
    {
        P0 = P0 * 10;           
        Mult = Mult * 10;
    }   
} 

P1   = Ref(P0, 1);
UpDn = 100 * P1[LVBI];

for (i = 0; i < 200; i++)
{
    Calc = EMA(P1,12)-EMA(P1,26);
    Goal = EMA(EMA(P1,12)-EMA(P1,26),9);

    if (Calc[LVBI] < Goal[LVBI])
        P1[LVBI] = P1[LVBI] + UpDn;
    else
        P1[LVBI] = P1[LVBI] - UpDn;
    UpDn = UpDn / 2;
    if (UpDn <= Acc)
    {
        j = i;
        i = 99999;
    }
}

Accuracy = 100 * (abs(Goal[LVBI] - Calc[LVBI]) / Goal[LVBI]);

Filter = BarIndex() == LVBI;

AddColumn(Mult,                  "Multiplier",    1.0);
AddColumn(Calc[LVBI - 1] / Mult, "Curr Ind Val",  1.9);
AddColumn(Goal / Mult,           "Goal Ind Val",  1.9);
AddColumn(Calc / Mult,           "Calc Ind Val",  1.9);
AddColumn(j,                     "Iterations",    1.0);
AddColumn(Accuracy,              "Accuray (%)",   1.9);
AddColumn(Ref(P1, -1) / Mult,    "Current Array", 1.9);
AddColumn(P1 / Mult,             "Needed Array",  1.9);

Reply via email to