bands

 

hello im trying to code an expert advisor that does trade after moving average is higher than bands main (after bar closes. shift 1)

if(iBands(NULL,0,20,2,1,PRICE_CLOSE,MODE_MAIN,1)<iMA(NULL,0,PERIOD_CURRENT,1,MODE_SMA,PRICE_CLOSE,1)&&
   OrdersTotal()==0)

   OrderSend(Symbol(),OP_BUY,lots,Ask,3,Ask-stoploss*Point,0,"",magic_number,0,Blue);

‌the code does not do what i want it to do. i read documentation but it does not give detailed information

https://docs.mql4.com/indicators/ibands

‌‌

iBands - Technical Indicators - MQL4 Reference
iBands - Technical Indicators - MQL4 Reference
  • docs.mql4.com
iBands - Technical Indicators - MQL4 Reference
 

Do you know what MODE_MAIN means in iBands()?

For you code you don't need iBands() an iMA(..) would be enough - guess why!


	          
 
bands exampleCarl Schreiber:

Do you know what MODE_MAIN means in iBands()?

For you code you don't need iBands() an iMA(..) would be enough - guess why!

i think mode_main means middle line inside two lines above below

i‌ want to place trade after ma period 1 shift 1 is above bands middle line. can you show me some code please

 
  1. Your code
    Documentation
    iMA(
       NULL,
       0,
       PERIOD_CURRENT,
       1,
       MODE_SMA,
       PRICE_CLOSE,
       1
    )
    double  iMA(
       string       symbol,           // symbol
       int          timeframe,        // timeframe
       int          ma_period,        // MA averaging period
       int          ma_shift,         // MA shift
       int          ma_method,        // averaging method
       int          applied_price,    // applied price
       int          shift             // shift
       );
    What is the length of your moving average?
  2. Why did you post in the Root / MT5 General section instead of the MQL4 section (bottom of the Root page?)
 
whroeder1:
  1. Your code
    Documentation
    What is the length of your moving average?
  2. Why did you post in the Root / MT5 General section instead of the MQL4 section (bottom of the Root page?)

the moving average has a period of 1. the moving average is same as price. i posted in the root just because it was at the top of the page

iMA(Symbol(),PERIOD_CURRENT,1,0,MODE_SMA,PRICE_CLOSE,1);
iBands(Symbol(),PERIOD_CURRENT,20,2,1,PRICE_CLOSE,MODE_MAIN,1);
 
boopa26: the moving average has a period of 1.
No, it does not! That is you problem.
 
whroeder1:
No, it does not! That is you problem.

maybe you can show me some code please

if(iBands(Symbol(),PERIOD_CURRENT,20,2,1,PRICE_CLOSE,MODE_MAIN,1)<iMA(Symbol(),PERIOD_CURRENT,1,0,MODE_SMA,PRICE_CLOSE,1)&&
   OrdersTotal()==0)

   OrderSend(Symbol(),OP_BUY,lots,Ask,3,Ask-stoploss*Point,0,"",magic_number,0,Blue);

bands2

i think its fixed now. thanks all
Reason: