Stuck On worlds simplest Problem! Help!

 

Hi! thanks for giving my post a click. I'm Stuck on the world easiest problem that I cant find the answer to.

I'm testing a super simple EA that just tells me to buy or sell based on a normal Stochastic Oscillator.

Every time I run it the first for loop gets triggered and the first print command returns 57.00

void OnTick()
  {
   double StochPrev=iStochastic(NULL,0,5,3,3,MODE_SMA,STO_LOWHIGH,MODE_BASE,1);
   Print(StochPrev);
   if (StochPrev > 80.0)
   {
      Print("Sell!");
   }
   if (StochPrev < 20.0)
   {
      Print("Buy!");
   }
  }

That's all the code, Thanks!

 
kaderator:

Hi! thanks for giving my post a click. I'm Stuck on the world easiest problem that I cant find the answer to.

I'm testing a super simple EA that just tells me to buy or sell based on a normal Stochastic Oscillator.

Every time I run it the first for loop gets triggered and the first print command returns 57.00

That's all the code, Thanks!

Hi   ...Please click on iStochastics in Your code and press F1    ...then read really properly what this function returns   :)  , or read documentation

 :

https://www.mql5.com/en/docs/indicators/istochastic


and then read how to use indicators in mql code, but first  find out if You are using mql5 or mql4  because there is a difference between those two


HINT:

StochPrev  // is NOT a value of the schohastic in your case
Documentation on MQL5: Technical Indicators / iStochastic
Documentation on MQL5: Technical Indicators / iStochastic
  • www.mql5.com
//|                                             Demo_iStochastic.mq5 | //|                        Copyright 2011, MetaQuotes Software Corp. | //|                                             https://www.mql5.com | "The method of creation of the handle is set through the 'type' parameter (function type...
 
kaderator: Every time I run it the first for loop gets triggered and the first print command returns 57.00
  1. You didn't post any for loop.

  2. Why did you post your MT4 question in the Root / MT5 General section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  3.    if (StochPrev > 80.0){ Print("Sell!");
    You are looking at a signal. Act on a change of signal.
              MQL4 (in Strategy Tester) - double testing of entry conditions - Strategy Tester - Expert Advisors and Automated Trading - MQL5 programming forum
Reason: