Download MetaTrader 5

problems with ima call function

To add comments, please log in or register
Filippo Pozzebon
149
Filippo Pozzebon 2012.11.10 09:21 

Hi eberybody,

i 've the following problems about the return valure of the iMA function.

Here's my code, without any errors:

int OnInit()
 {
 mediaexp=iMA(NULL,0,10,0,MODE_EMA,PRICE_CLOSE);
 return(0);
 }

void OnTick()
 {
  CopyBuffer(mediaexp,0,0,3,Expmedia);
  ArraySetAsSeries(Expmedia,true);
  Print("la media è",Expmedia[0]);
 }

the iMA function return always the value 10.0 and the copybuffer doesn't work because it don't fill the buffer,

can someone help me?

thanks a lot

phi nuts
2184
phi nuts 2012.11.10 10:03  
pippuz:

Hi eberybody,

i 've the following problems about the return valure of the iMA function.

Here's my code, without any errors:

int OnInit()
  {
  mediaexp=iMA(NULL,0,10,0,MODE_EMA,PRICE_CLOSE);
  return(0);
  }

void OnTick()
  {
  CopyBuffer(mediaexp,0,0,3,Expmedia);
  ArraySetAsSeries(Expmedia,true);
  Print("la media è",Expmedia[0]);
 } 

the iMA function return always the value 10.0 and the copybuffer doesn't work because it don't fill the buffer,

can someone help me?

thanks a lot

Please use SRC button and edit your post. Write the code completely (how big is the Expmedia variable ?), do error checking, execute ArraySetAsSeries before CopyBuffer() and not after it,

 

Filippo Pozzebon
149
Filippo Pozzebon 2012.11.10 19:45  
phi.nuts:

Please use SRC button and edit your post. Write the code completely (how big is the Expmedia variable ?), do error checking, execute ArraySetAsSeries before CopyBuffer() and not after it,

 

 

int OnInit()
  {
   //controlmarkets = iBearsPower("EURUSD",PERIOD_M5,14);
   //mediaexp = iMA(NULL,PERIOD_M5,10,0,MODE_EMA,PRICE_CLOSE);
   //indicatore = IndicatorRelease(mediaexp);
   conto = AccountInfoDouble(ACCOUNT_BALANCE);
   lotti = 0.20 * conto; 
   rsiHandle = iRSI(NULL,0,RSIPeriod,PRICE_CLOSE);
   account = AccountInfoInteger(ACCOUNT_TRADE_ALLOWED);
   //---
   
   //---
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
  //---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   printf("ACCOUNT_LOGIN =account");
   CopyBuffer(rsiHandle,0,0,3,rsival);
   ArraySetAsSeries(rsival,true);
   Print("l'RSi è ",rsival[0]);
   //CopyBuffer(mediaexp,0,0,3,Expmedia);
   ArraySetAsSeries(Expmedia,true);
   Expmedia[0]=mediaexp;
   Print("la media è",Expmedia[0]);

   if(Expmedia[0]==0.0) 
     {
     Alert("Error in creation of indicator. Please try again");
     }

   //Print("la media è60",Expmedia[1]);
   Ask = SymbolInfoDouble("EURUSD", SYMBOL_ASK);
   Bid = SymbolInfoDouble("EURUSD", SYMBOL_BID); 
   //controlmarkets=iBearsPower("EURUSD",PERIOD_M5,14);
   //Print(" il valore di bear è " ,controlmarkets);
   //Print(" il prezzo è ",Ask);
   price = (Ask + Bid)/2;
   //Print(" la media è ",mediaexp," il prezzo è ",price);

   if (price > mediaexp)
     {
     Print("buy");
     //printf(segnale,mediaexp,price);
     segnale = "buy";
     }

   if (price< mediaexp)
     {
     Print("sell");
     segnale = "sell";
     // printf(segnale,mediaexp,price);
     }  

   // SEGNALE BUY 
 
   if (PositionsTotal() < 1)
     {
     //if (signal == 1.0)
     if (rsival[0] < 30) 
        {
         request.action = TRADE_ACTION_DEAL;
         request.symbol ="EURUSD";
         request.volume = NormalizeDouble(volume()/3,2);
         request.price = SymbolInfoDouble(Symbol(), SYMBOL_ASK);
         request.sl = 10.0;
         request.tp = 40.0;
         request.deviation=10;
         request.type=ORDER_TYPE_BUY;
         request.type_filling=ORDER_FILLING_FOK;
         OrderSend(request,result);
         ordine=request.order;
         //Buyentry=1;
         //printf(segnale);
         Print("retcode=",result.retcode," error=", GetLastError());
         }
  
    ordine=OrderGetTicket(pos);
    Print("l'ordine è",ordine);
  
    //SEGNALE SELL  

    //if (signal==2.0)
    if (rsival[0]>70)
       {
        request.action = TRADE_ACTION_DEAL;
        request.symbol = "EURUSD";
        request.volume = NormalizeDouble(volume()/3,2);
        request.price = SymbolInfoDouble(Symbol(), SYMBOL_ASK);
        request.sl = 10.0;
        request.tp = 40.0;
        request.deviation = 10;
        request.type = ORDER_TYPE_SELL;
        request.type_filling = ORDER_FILLING_FOK;
        OrderSend(request,result);
        //Sellentry = 1;
        ordine=request.order;
        //printf(segnale);
        //Print("retcode=",result.retcode," error=", GetLastError());
       } 
    }


Filippo Pozzebon
149
Filippo Pozzebon 2012.11.10 19:48  

I try to execute ArraySetAsSeries before CopyBuffer()  but it doesn't work aswell...the problem that i don't understand is why the rsi ( usign the same code) is ok and work, instead of iMA!

do i'm missing something to do in the code before the Ima function?

please help me..

phi nuts
2184
phi nuts 2012.11.11 00:02  
phi.nuts:

Please use SRC button and edit your post. Write the code completely (how big is the Expmedia variable ?), do error checking, execute ArraySetAsSeries before CopyBuffer() and not after it,

 

Sorry, I wasn't clear enough :(. This is SRC button, I'll edit your post then.

 

Slava
Moderator
6913
Slava 2012.11.12 12:45  
pippuz:

Hi eberybody,

i 've the following problems about the return valure of the iMA function.

Here's my code, without any errors:

the iMA function return always the value 10.0 and the copybuffer doesn't work because it don't fill the buffer,

can someone help me?

thanks a lot


Show your declaration of Expmedia array
Filippo Pozzebon
149
Filippo Pozzebon 2012.11.12 19:47  
stringo:
Show your declaration of Expmedia array

Hi,

here the declaration:


double rsival[3],Expmedia[1000];

Slava
Moderator
6913
Slava 2012.11.13 08:47  

Try to use dynamic array without dimension declaration

double Expmedia[];
Filippo Pozzebon
149
Filippo Pozzebon 2012.11.13 21:01  
I try Without dimension but it return "internal error, Array out of range"
Documentation on MQL5: MQL5 programs / Runtime Errors
Documentation on MQL5: MQL5 programs / Runtime Errors
  • www.mql5.com
MQL5 programs / Runtime Errors - Documentation on MQL5
To add comments, please log in or register