expert advisor using MA

 

I want to have an expert advisor with following conditions. Somebody help please:

1- If the price is below of  MA10=NormalizeDouble(iMA(Symbol(),Period(),10,0,MODE_LWMA,PRICE_OPEN,0),digitz) put a BUYSTOP at MA10.

2- If the price is above the  MA10=NormalizeDouble(iMA(Symbol(),Period(),10,0,MODE_LWMA,PRICE_OPEN,0),digitz) put a SELLSTOP at MA10.

3- If the price touches MA10 ONLY with shadow, first close the current position and then put a reverse position at the beginning of next candle.

4- If the current candle ends but the Buy/Sell didn't triggered delete the pending order and open a new one.


I've prepared a code before and attach it, but it doesn't work properly. please correct it and help me.

Files:
2000.mq4  11 kb
 
  1. Move the code out of OnTimer and put it in OnTick.

    Filter the ticks by a new bar. There is no shadow until the bar closes.

    Now you can use the debugger and find out what your code is doing.

  2.   if(Volume[0]<=1)

    For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart), volume is unreliable (miss ticks), Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
              New candle - MQL4 programming forum #3 2014.04.04

  3. “Doesn't work” is meaningless — just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires — meaningless.
         How To Ask Questions The Smart Way. 2004
              When asking about code

Reason: