Calling the Sto out of another indicator

 

Hi,

 I am writing an indicator and at each new bar I need the last 10 Stochastic values.

For testing I put in my loop the following code in my indicator:

 

   for(int i=1; i<rates_total && !IsStopped(); i++)

     {  

if(i==1) 

Print("Sto = "+iStochastic(NULL,TF,5,3,3,MODE_SMA,0,MODE_MAIN,i)+" dt="+TimeCurrent()); 

...

 

When I put the indicaor on a runing chart (in the strategie tester) I see my time is runnig, but I am getting allways the same value for the stochastic[i].

Of course, this isn't what I want Where is the problem so that I am not getting the correct value of the stochastic?

First I thought, that I am getting always the Sto-Value absolute (I mean from the aktuall time-1bar), but this isn't the case.

 
sunshineh: When I put the indicaor on a runing chart (in the strategie tester) I see my time is runnig, but I am getting allways the same value for the stochastic[i].
You are only printing the stochastic of bar 1. Bar 1 has closed, nothing will ever change. The value will NOT change until a new bar forms and there is a new bar 1.
 

Here is the hole code from my test indicator. And below are the pictures from testing this indicator at M5 = same Period, and at M1 = Period below Sto-Period. So normaly I think in the second chart must be the Sto-Value always for 5 candles be the same. But it shows the same value for the hole chart?!

//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
    for(int i=1; i<rates_total && !IsStopped(); i++)
     {          
         datetime dtTime;
   
         if(i==1 && dtTime !=Time[0])
         {
            dtTime = Time[0];
            double Value = iStochastic(NULL,PERIOD_M5,5,3,3,MODE_SMA,0,MODE_MAIN,i);
            Print("iStochastic(NULL,TF,5,3,3,MODE_SMA,0,MODE_MAIN,1)="+iStochastic(NULL,PERIOD_M5,5,3,3,MODE_SMA,0,MODE_MAIN,i)+" Time = "+TimeCurrent());
            ObjectCreate ("sto"+dtTime,OBJ_TEXT,1,dtTime,Value);   //I put the Sto-Indicator on the Chart
            ObjectSetText("sto"+dtTime,CharToStr(108),7,"Wingdings",clrRed);
         }
     }

   return(rates_total);
  }
 

Same TF

Lower TF 

 

Hello Sunshineh,

as far as I see, WHRoeder is completely right. If you need the 10 last Stochastic values, you'll have to make a loop that allows to go back the last 10 finished bars.

So change

i==1

to

i <= 10

and check, if the result fits your request.

 
That's clear! I only put "i==1" in this indicator as example to show, that the stochastic value is always the same when I call the sto-value from M5 out of my M1 test.
 

In other words, I get in my indicator the Sto-Values from another timeframe to work with it.

The Values from another timeframe out of my Expert Advisor is no problem.

 

Would you mind to post the non-functioning code? With something modified it would be more a guessing game.

 

Have you tried the indicator about at the strategy-tester? 

Once at M1 and once at M5 (and put the sto- below the chart).

Than you will get the results shown on my screenshots. 

 

I think, I realized my error.

I can't explain,why it is acting that way, but I see, that my testing steps cause this error!

That was my way:

1.I created an empty EA, for visual testing.

2.I started this EA in visual mode

3.I put my programmed indicator on this chart (which is calling the sto from the other timeframe)

>>> here I am always getting the same value, as you can see on my error "picture".

 

 Correct way:

1.I integrate the indicator into my test EA and start the visual test. Now I get the following correct picture:

Indicator Call out of my EA 

 
Great that you found a solution for this strange behaviour. I have no explanation either, but I also haven't yet tested in this special constellation you describe.
Reason: