isNewBar() not producing the right time Stochastic value onTick MQL5

To add comments, please log in or register
jaffer wilson
1491
jaffer wilson  

Check this program I am trying to get the values of the Stochastic

#include <Lib CisNewBar.mqh>
CisNewBar current_chart; // instance of the CisNewBar class: detect new tick candlestick

void OnTick()
{
if(current_chart.isNewBar() > 0)
{
int stoch = iStochastic(_Symbol,PERIOD_M1,5,3,3,MODE_SMA,STO_LOWHIGH);
double K[],D[];
ArraySetAsSeries(K,true);
ArraySetAsSeries(D,true);
CopyBuffer(stoch,0,0,5,K);
CopyBuffer(stoch,1,0,5,D);
ArrayPrint(K);
}

Here is the output I got:

95.97315 90.40000 74.11765 49.25373 25.00000
73.68421 81.87919 90.40000 74.11765 49.25373
74.34211 80.70175 81.87919 90.40000 74.11765
90.24390 78.94737 80.70175 81.87919 90.40000
78.33333 84.05797 78.94737 80.70175 81.87919

The above values represents Array elements as 0th, 1st,2nd,3rd & 4th
What is the 0th in the initial print will become the previous for the next and will be placed at the 1st position in the next print.
But I see the values has changed and is drastic.

Previously the iStochastic() was giving the right and correct values. But it was working OnTick()and hence was giving the output for every change. I only need the values when the bar is complete or after minute. So, I tried the solution from the community. Here is the link: solution for newbar

But the output is infront and is changing the equation of my trade which is why I am losing it.

Please help me. How I can make it work for me?

Here are the files needed: Lib CisNewBar.mqh  

Placed the same questioon here: https://stackoverflow.com/questions/49550100/isnewbar-not-producing-the-right-time-stochastic-value-ontick-mql5

Icham Aidibe
11613
Icham Aidibe  
jafferwilson:

Check this program I am trying to get the values of the Stochastic

Here is the output I got:

The above values represents Array elements as 0th, 1st,2nd,3rd & 4th
What is the 0th in the initial print will become the previous for the next and will be placed at the 1st position in the next print.
But I see the values has changed and is drastic.

Previously the iStochastic() was giving the right and correct values. But it was working OnTick()and hence was giving the output for every change. I only need the values when the bar is complete or after minute. So, I tried the solution from the community. Here is the link: solution for newbar

But the output is infront and is changing the equation of my trade which is why I am losing it.

Please help me. How I can make it work for me?

Here are the files needed: Lib CisNewBar.mqh  

Placed the same questioon here: https://stackoverflow.com/questions/49550100/isnewbar-not-producing-the-right-time-stochastic-value-ontick-mql5

Stochastic calculation to be done at each tick, data retrieve at each new bar : 

#include <Lib CisNewBar.mqh>
CisNewBar current_chart; // instance of the CisNewBar class: detect new tick candlestick
double K[],D[]; // declare it once

void OnInit()
{
int stoch = iStochastic(_Symbol,PERIOD_M1,5,3,3,MODE_SMA,STO_LOWHIGH); // load it once !!!!!
ArraySetAsSeries(K,true); // set it once
ArraySetAsSeries(D,true); // set it once
}

void OnTick()
{
CopyBuffer(stoch,0,0,5,K); // there
CopyBuffer(stoch,1,0,5,D);

if(current_chart.isNewBar() > 0)
{
CopyBuffer(stoch,0,0,5,K); // or there ... 
CopyBuffer(stoch,1,0,5,D);
ArrayPrint(K); // ask for value at each new bar
}
}
Alain Verleyen
39041
Alain Verleyen  
jafferwilson:

Check this program I am trying to get the values of the Stochastic

Here is the output I got:

The above values represents Array elements as 0th, 1st,2nd,3rd & 4th
What is the 0th in the initial print will become the previous for the next and will be placed at the 1st position in the next print.
But I see the values has changed and is drastic.

All is normal. You element 0 is stochastic value at bar 0, so the value at current (new) bar...this value will change until the bar will be close.

Previously the iStochastic() was giving the right and correct values. But it was working OnTick()and hence was giving the output for every change. I only need the values when the bar is complete or after minute. So, I tried the solution from the community. Here is the link: solution for newbar

But the output is infront and is changing the equation of my trade which is why I am losing it.

Please help me. How I can make it work for me?

Here are the files needed: Lib CisNewBar.mqh  

Placed the same questioon here: https://stackoverflow.com/questions/49550100/isnewbar-not-producing-the-right-time-stochastic-value-ontick-mql5

What's the point to ask question when you don't follow the answers you got.
jaffer wilson
1491
jaffer wilson  
Icham Aidibe:

Stochastic calculation to be done at each tick, data retrieve at each new bar : 

Sorry but I am still get the values, the same as in the question. I don't understand how to fix this issue?

Icham Aidibe
11613
Icham Aidibe  
jafferwilson:

Sorry but I am still get the values, the same as in the question. I don't understand how to fix this issue?

The code is clean. Periods ? SMA/EMA ? On what do you base to say these values are wrong ? 

jaffer wilson
1491
jaffer wilson  

Alain Verleyen:
All is normal. You element 0 is stochastic value at bar 0, so the value at current (new) bar...this value will change until the bar will be close.

What's the point to ask question when you don't follow the answers you got.

How I can get the values of the close bar only, using the current library?

And I didn't got any answer yet. The person is helping me with comments that are of no use as I am unable to understand the meaning. If you have any solution for my issue. Please let me know.

Icham Aidibe
11613
Icham Aidibe  
jafferwilson:

How I can get the values of the close bar only, using the current library?

And I didn't got any answer yet. The person is helping me with comments that are of no use as I am unable to understand the meaning. If you have any solution for my issue. Please let me know.

int stoch = iStochastic(_Symbol,PERIOD_M1,5,3,3,MODE_SMA,STO_CLOSECLOSE); // load it once !!!!!
jaffer wilson
1491
jaffer wilson  
Icham Aidibe:

The code is clean. Periods ? SMA/EMA ? On what do you base to say these values are wrong ? 

I guess my code gives clear understanding for your questions.

see I want to have the current value of the line.

See the below image and the related values you will understand what I want and what I am getting.

my image with output and expected.

jaffer wilson
1491
jaffer wilson  
Icham Aidibe:

I tried this too not working for me.

Icham Aidibe
11613
Icham Aidibe  
jafferwilson:

I tried this too not working for me.

Returned value are from a bar to another one. 

Display it on tick, you'll see the same values. 

To add comments, please log in or register