Can I capture the % price movement in EA?

 

Hi,

I'm new to EA and I've been using free EA builders online.
However I cannot find how to program the way I want, so I appreciate if I can get any advice.

What I want to capture is a sudden price movement due to news or any events.
Like if more than 2% price change from previous close price, then buy etc.

For Example:
Let's say USDJPY closed at 100.00
at next bar, USDJPY closed at 97.88 (more than 2% drop)
then BUY

Is this kind of EA possible?

Thanks.

 
Mochi888:

Hi,

I'm new to EA and I've been using free EA builders online.
However I cannot find how to program the way I want, so I appreciate if I can get any advice.

What I want to capture is a sudden price movement due to news or any events.
Like if more than 2% price change from previous close price, then buy etc.

For Example:
Let's say USDJPY closed at 100.00
at next bar, USDJPY closed at 97.88 (more than 2% drop)
then BUY

Is this kind of EA possible?

Thanks.


The last closed bar's price is Close[1].

The bar previous to that is Close[2]. 

You probably only want to check at the start of a new bar, otherwise it will fire off orders all through the bar.

   double threshold = 2.0;
   static datetime last_bar = 0;
   if(last_bar != Time[0])
     {   
      last_bar = Time[0];
      double change=((Close[1]-Close[2])/Close[2])*100;
      if(change <= -threshold)
        {
         /* code for OrderSend() buy */
        }
      else if(change >= threshold)
        {
         /* code for OrderSend() sell */
        }
     }
 
Mochi888: I've been using free EA builders online.
I want, ...
Is this kind of EA possible?
    • We hate EA builder
    • You couldn't be bothered to learn mql4, therefor there is no common language for us to communicate.
    • There are only two choices: learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem, but we are not going to debug your hundreds lines of code.
    • EA builder makes bad code counting up while closing multiple orders.
    • EA builder makes bad code Bars is unreliable (max bars on chart) volume is unreliable (miss ticks) Always use time. New candle - MQL4 forum
    • EA builder makes bad code Not adjusting for 4/5 digit brokers, TP/SL and slippage:
      double   pip          = StringFind(_Symbol,"JPY") < 0 ? 0.01 : 0.0001;
      int      pipDigits    = (int)MathLog10(pip/_Point);
      int      pipsToPoints = int(pip / _Point);
      int      slippage     = 3 * pipsToPoints;
    • EA builder makes bad code not adjusting for ECN brokers.
    • EA builder makes bad code not checking return codes.
    • EATree uses objects on chart to save values - not persistent storage (files or GV+Flush.) No recovery (crash/reboot.)
  1. You have only three choices: Search for it, learn to code it, or pay (Freelance) someone to code it. We're not going to code it for you. We are willing to help you when you post your attempt (using SRC) and the nature of your problem.
  2. Of course it is.