EA for last week high/low

 

Hi guys,

I'm learning mql4. I was able to print the last weeks high and low.

Now I like to go a bit further but I guess I need help.

Here's what I want to achieve with an EA;

If bar closed aboved last week high, then if price close below last week high: BUY when price hits last week high again (optional x-pips above last week high)

So basically buy on the restest. I don't know if I have to use price or bar close, I like to test this so should be an option when adding the ea to the chart.

Can somebody help me with this line of code please?

Thanks in advance.

Tony.

 
trietrader2: I'm learning mql4. I was able to print the last weeks high and low. Now I like to go a bit further but I guess I need help. Here's what I want to achieve with an EA; If bar closed aboved last week high, then if price close below last week high: BUY when price hits last week high again (optional x-pips above last week high) So basically buy on the restest. I don't know if I have to use price or bar close, I like to test this so should be an option when adding the ea to the chart. Can somebody help me with this line of code please?

That is not a single line of code, but many lines of code.

Show your own code where you attempt to do just that, and explain the exact difficulties you wish to resolve.

Alternatively, search in the CodeBase for something that is similar to what you want, and then slowly change the code step by step until you have what you want.

 
trietrader2:

Hi guys,

I'm learning mql4. I was able to print the last weeks high and low.

Now I like to go a bit further but I guess I need help.

Here's what I want to achieve with an EA;

If bar closed aboved last week high, then if price close below last week high: BUY when price hits last week high again (optional x-pips above last week high)


if(iClose(shift 1) > iHigh(shift 2))
  if(iClose(shift 0) < iHigh(shift 1)) 
    OrderSend(... Buy...);

The above is a quuck answer. However, you must keep studying and reading.. 


Good Luck
 

Hi, I have this code now, but does not work...


//Evaluate if there is an entry signal
void EvaluateEntry(){
   SignalEntry=SIGNAL_ENTRY_NEUTRAL;
   //if(!IsSpreadOK) return;    //If the spread is too high don't give an entry signal
   //if(UseTradingHours && !IsOperatingHours) return;      //If you are using trading hours and it's not a trading hour don't give an entry signal
   //if(!IsNewCandle) return;      //If you want to provide a signal only if it's a new candle opening
   if(IsTradedThisBar) return;   //If you don't want to execute multiple trades in the same bar
   if(TotalOpenOrders>0) return; //If there are already open orders and you don't want to open more
   
   //This is where you should insert your Entry Signal for BUY orders
   //Include a condition to open a buy order, the condition will have to set SignalEntry=SIGNAL_ENTRY_BUY
   //When H4 bar closed above last week high, then when H4 bar closed below last week high, Open a buy order when price hits last week high
   
   if(iClose (Symbol (), PERIOD_H4, 0) > iHigh (Symbol (), PERIOD_W1, 1)) // H4 closed above last week high
   if(iClose (Symbol (), PERIOD_H4, 0) < iHigh (Symbol (), PERIOD_W1, 1)) // H4 closed below last week high
   if(Ask == iHigh (Symbol (), PERIOD_W1,1)) //H4 hits last week high
   SignalEntry=SIGNAL_ENTRY_BUY;  
   
   
   
   //This is where you should insert your Entry Signal for SELL orders
   //Include a condition to open a sell order, the condition will have to set SignalEntry=SIGNAL_ENTRY_SELL
   //When H4 bar closed below last week low, then when H4 bar closed above last week low, Open a sell order when price hits last week low
   
   
   if(iClose (Symbol (), PERIOD_H4, 0) < iLow (Symbol (), PERIOD_W1, 1)) // H4 closed below last week low
   if(iClose (Symbol (), PERIOD_H4, 0) > iLow (Symbol (), PERIOD_W1, 1)) //H4 closed above last week low
   if(Bid == iLow (Symbol (), PERIOD_W1, 1)) //H4 hits last week low
   SignalEntry=SIGNAL_ENTRY_SELL;
   
   
}


The img example shows what I want for a BUY;

BUY;