Problem with bollinger bands

 
input int volume, rsiP, bandP;
input double sl, bandD;
input ENUM_TIMEFRAMES tf;
input ENUM_APPLIED_PRICE bandAP;
bool ok = false, closing = false;
//+---------------------START TIME CLASS-----------------------+
datetime cStartTime(int pstartHour= 0, int pstartMinute= 0)
{
MqlDateTime timeStruct;
TimeToStruct(TimeCurrent(), timeStruct);

timeStruct.hour= pstartHour;
timeStruct.min= pstartMinute;

datetime stTime= StructToTime(timeStruct);

return(stTime);
}
//+----------------------END TIME CLASS------------------------+
datetime cEndTime(int pendHour= 0, int pendMinute= 0)
{
MqlDateTime timeStruct;
TimeToStruct(TimeCurrent(), timeStruct);

timeStruct.hour= pendHour;
timeStruct.min= pendMinute;

datetime EndTime= StructToTime(timeStruct);

return(EndTime);
}

//+-------------------------CURRENT TIME-------------------------------------+
datetime cCurrentTime()
{
MqlDateTime timeStruct;
TimeToStruct(TimeCurrent(), timeStruct);
datetime CurrentTime= StructToTime(timeStruct);

return(CurrentTime);
}

//+----------------------------CLOSE TIME------------------------------------+

datetime cCloseTime(int pCloseHour, int pCloseMinute){
MqlDateTime timeStruct;
TimeToStruct(TimeCurrent(), timeStruct);
timeStruct.hour = pCloseHour;
timeStruct.min = pCloseMinute;
datetime closeTime = StructToTime(timeStruct);
return(closeTime);
}

//+-------------------------ONTICK-----------------------------------------+


void OnTick(){

double rsi[];
ArraySetAsSeries(rsi, true);
double rsiH = iRSI(_Symbol,tf,rsiP,PRICE_CLOSE);
CopyBuffer(rsiH,0,0,3,rsi);

double uBand[], lBand[], mBand[];
ArraySetAsSeries(uBand, true);
ArraySetAsSeries(lBand, true);
ArraySetAsSeries(mBand, true);

double bandH = iBands(_Symbol,tf,bandP,0,bandD,PRICE_CLOSE);

CopyBuffer(bandH,0,0,3,lBand);
CopyBuffer(bandH,1,0,3,mBand);
CopyBuffer(bandH,2,0,3,uBand);


double close[];
ArraySetAsSeries(close, true);
CopyClose(_Symbol,tf,0,3,close);

datetime startTime = cStartTime(10,0);
datetime endTime= cEndTime(12,0);
datetime currentTime= cCurrentTime();
datetime closeTime = cCloseTime(16,50);

if(currentTime <= endTime && currentTime >= startTime){
ok = true;
}
else ok = false;

if(currentTime >= closeTime){
closing = true;
}
else closing = false;

long pType = PositionGetInteger(POSITION_TYPE);
double currentBid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
double currentAsk = SymbolInfoDouble(_Symbol, SYMBOL_ASK);

MqlTradeRequest request;
MqlTradeResult result;

if(ok = true && PositionSelect(_Symbol) == false && close[1] <= lBand[1] && rsi[1] < 30){
    ZeroMemory(request);
    request.action= TRADE_ACTION_DEAL;
    request.symbol= _Symbol;
    request.volume= volume;
    request.type= ORDER_TYPE_BUY;
    request.price= currentAsk;
    request.sl= close[1] - (close[1] * sl);
    request.tp= 0;
    OrderSend(request,result);
}

if(ok == true && PositionSelect(_Symbol) == false && close[1] >= uBand[1] && rsi[1] > 70){
    ZeroMemory(request);
    request.action= TRADE_ACTION_DEAL;
    request.symbol= _Symbol;
    request.volume= volume;
    request.type= ORDER_TYPE_SELL;
    request.price= currentBid;
    request.sl= close[1] + (close[1] * sl);
    request.tp= 0;
    OrderSend(request,result);
}

if(PositionSelect(_Symbol) == true && closing == true){
ZeroMemory(request);
    request.action= TRADE_ACTION_DEAL;
    request.symbol= _Symbol;
    request.volume= volume;
    if(pType == ORDER_TYPE_BUY){    
        request.type= ORDER_TYPE_SELL;
        request.price= currentBid;
        }
    if(pType == ORDER_TYPE_SELL){
        request.type= ORDER_TYPE_BUY;
        request.price= currentAsk;
    }    
    request.sl= 0;
    request.tp= 0;
    OrderSend(request,result);
}



}

Hello traders and programmers, 

 I'm trying to build a simple EA based on rsi and bollinger bands, but i'm having a problem. When i test it, the bollinger bands appear as vertical lines in the chart. Could someone look for any mistakes

on my code? Thank you!

 

IBands() returns an int, not a double.

Always check the returned value when you are using a function. Your code has no error checking it's a very bad practice.

 
Alain Verleyen:

IBands() returns an int, not a double.

Always check the returned value when you are using a function. Your code has no error checking it's a very bad practice.


I'm gonna fix that, thank you!

 
gabriel.lucas.9:

I'm gonna fix that, thank you!

While at it do the same for rsi too :)