Closest Low under current market price

 

Hello all,

I am new to EA progamming.

I need help with finding the previous low under the current price value like in the pictured represented by ( x )


do any of you know how to do this,

thank you very much 

Files:
PreviousLow.png  16 kb
 
David Henriques:I am new to EA progamming. I need help with finding the previous low under the current price value like in the pictured represented by ( x ). do any of you know how to do this,

If you are new to MQL, then please first learn how to code the basics before attempting to code a specific task.

Take some of the examples in the codebase and study them, and then make small changes as you strive to reach your goal of a specific task, such as the one you describe.

Also, it is customary to first present your coding attempt at the task and then ask for advice.

MQL5 Code Base
MQL5 Code Base
  • www.mql5.com
MQL5 Source Code Library for MetaTrader 5
 

Until you can state your want in concrete terms, it can not be coded.

  1. You could go up hill, down, up, and down to find the second low.

         INDEX    iExtreme = iBeg++;   Datatype extreme  = arr[iExtreme], value;
          INDEX    iLimit   = MathMin(iEnd, iExtreme + size);
          for(; iBeg < iLimit; ++iBeg){
             value = arr[iBeg];
             if(comp.is_before(extreme, value) ){
                iExtreme = iBeg;  extreme = value;
                iLimit   = MathMin(iEnd, iExtreme + size);
          }  }
     

    If you use a small window, you would find the local low between your x and current candles.

    If you use a larger window, you would miss the local low and x and find the low at the left of your picture.

  2. You could use zig zag.
              How to get time or shift of zigzag top (or bottom) - Symbols - Expert Advisors and Automated Trading - MQL5 programming forum

 
William Roeder #:

Until you can state your want in concrete terms, it can not be coded.

  1. You could go up hill, down, up, and down to find the second low.

    If you use a small window, you would find the local low between your x and current candles.

    If you use a larger window, you would miss the local low and x and find the low at the left of your picture.

  2. You could use zig zag.
              How to get time or shift of zigzag top (or bottom) - Symbols - Expert Advisors and Automated Trading - MQL5 programming forum

Thank you very much for you reply, 

I am sorry if I didn't explain my self in a clear way

So in the picture I am including you can in green the Low I want to get, and marked with the red "X" are the one I want to not consider as the are above the current bid price.

I want to find the closest (in time) Low that is under the bid price. 

I only need it's value, like in this case it would be 1.03050.

Once I have the value I can compare it with the current bid price and open my position.

 
David Henriques #: I want to find the closest (in time) Low that is under the bid price.

So do it. What's the problem?

Easiest is to using iFractal

Not compiled, not tested, just typed.

int hFractal;
int OnInit(){ hFractal = iFractals(_Symbol,_Period); … }
void OnTick(){
   MqlTick last_tick;
   SymbolInfoTick(_Symbol,last_tick);
   double Bid=last_tick.bid;

   double down_arrows[];
   int Bars=Bars(_Symbol,_Period);
   if(CopyBuffer(hFractal,1,0,Bars,down_arrows)<0){
     //--- if the copying fails, tell the error code
      PrintFormat("Failed to copy data from the iFractals indicator to the FractalDownBuffer array, error code %d",
                  GetLastError());
      return;
   }
   int iX=0; for(; iX < Bars; ++i) if(down_arrows[i] < Bid) break;
   // Found bar X.

Not compiled, not tested, just typed.