Download MetaTrader 5

mql5 Stochastic Readings on different Timeframes

To add comments, please log in or register
Find out how your rating can be improved
Richard Read
322
Richard Read 2016.08.30 09:45 

Hi,

 

I have the below piece of code, which is supposed to read the values of the stochastic at different timeframes. When the chart is on the same timeframe as the requested stochastic timeframe, it gives the correct reading, however when it is on a different timeframe to the one requested it generates incorrect values. What am I doing wrong? result[] caries the different timeframe values, candle represents 1.

 

      for(int l=ArraySize(result)-1;l>=0;l--)
        {
         int to_copy=Bars(Symbol(),TFMigrate(result[l]));
         double StoMain[],StoSignal[];
         int Sto_Handle=iStochastic(Symbol(),TFMigrate(result[l]),perck,percd,slowings,mamethod,STO_LOWHIGH);
         if(CopyBuffer(Sto_Handle,MAIN_LINE,0,to_copy,StoMain)<=0)return;
         if(CopyBuffer(Sto_Handle,SIGNAL_LINE,0,to_copy,StoSignal)<=0)return;
         ArraySetAsSeries(StoMain,true);
         ArraySetAsSeries(StoSignal,true);
         if(result[l]==180 && i==4)
            Alert(StoMain[candle]);
         if(StoMain[candle]<
            StoSignal[candle])
           {
            ObjectSetInteger(0,"TC"+IntegerToString(i+1)+results[l],OBJPROP_BGCOLOR,clrRed);
            ObjectSetInteger(0,"TC"+IntegerToString(i+1)+results[l],OBJPROP_COLOR,clrRed);
           }
         if(StoMain[candle]>=
            StoSignal[candle])
           {
            ObjectSetInteger(0,"TC"+IntegerToString(i+1)+results[l],OBJPROP_BGCOLOR,clrGreen);
            ObjectSetInteger(0,"TC"+IntegerToString(i+1)+results[l],OBJPROP_COLOR,clrGreen);
           }
        }
Ernst Van Der Merwe
4732
Ernst Van Der Merwe 2016.08.30 12:51  

It's giving me the same value on any timeframe so maybe it's the TFMigrate() function.

   ENUM_TIMEFRAMES result[]={PERIOD_H1,PERIOD_H3,PERIOD_H6};
   
   for(int l=ArraySize(result)-1;l>=0;l--)
     {
      int to_copy=2;
      double StoMain[],StoSignal[];
      int Sto_Handle=iStochastic(Symbol(),result[l],7,3,3,MODE_SMA,STO_LOWHIGH);
      if(CopyBuffer(Sto_Handle,MAIN_LINE,0,to_copy,StoMain)<=0)return(0);
      if(CopyBuffer(Sto_Handle,SIGNAL_LINE,0,to_copy,StoSignal)<=0)return(0);
      ArraySetAsSeries(StoMain,true);
      ArraySetAsSeries(StoSignal,true);
      if((int)result[l]==16387 /*&& i==4*/)
         printf("Timeframe:%s StochMain:%f",EnumToString(result[l]),StoMain[1]);
      if(StoMain[1]<
         StoSignal[1])
        {
         //ObjectSetInteger(0,"TC"+IntegerToString(i+1)+results[l],OBJPROP_BGCOLOR,clrRed);
         //ObjectSetInteger(0,"TC"+IntegerToString(i+1)+results[l],OBJPROP_COLOR,clrRed);
        }
      if(StoMain[1]>=
         StoSignal[1])
        {
         //ObjectSetInteger(0,"TC"+IntegerToString(i+1)+results[l],OBJPROP_BGCOLOR,clrGreen);
         //ObjectSetInteger(0,"TC"+IntegerToString(i+1)+results[l],OBJPROP_COLOR,clrGreen);
        }
     }
Richard Read
322
Richard Read 2016.08.31 08:18  
Ernst Van Der Merwe:

It's giving me the same value on any timeframe so maybe it's the TFMigrate() function.

Thanks Ernst, you were correct it was an issue with the TFMigrate().

 

Regard

 

Richard 

To add comments, please log in or register