cannot get the buffer value from i custom

 

Hi,

   I am not able to get the buffer value from icustom ..can someone help me to check the codes:

//2 Moving Average Signal  indicator inputs

input int ExtPeriodFastMA   =7; // Fast MA Period

input int ExtPeriodSlowMA   =20; // Slow MA Period

input int ExtModeFastMA     =1;  

input int ExtModeSlowMA     =1;

input int ExtPriceFastMA    =0;

input int ExtPriceSlowMA    =1;



input double InpOrderSize  =0.01; // order size

input int   InpMagicNumber =2000001;   // Magic number


double   TakeProfit;          //After conversion from points

double   StopLoss;

// Identify the Buffer number

//

const string IndicatorName = "2 Moving Average Signal";

const int   BufferBuy =1;

const int   BufferSell =0;



int OnInit () {

  

   

   return(INIT_SUCCEEDED);

}

void OnDeinit(const int reason) {

   TakeProfit = 0;

   StopLoss = 0;

   

}


void OnTick() {

   //

   // Where thisis to only run once per bar

   //

   if (!NewBar()) return;

   //

   //Perform any calculations and analysis here

   //

   static double lastBuy =0;

   static double lastSell =0;

   

   double   currentBuy = iCustom(Symbol(),Period(),IndicatorName,BufferBuy,1);

   double   currentSell = iCustom(Symbol(),Period(),IndicatorName,BufferSell,1);

   

   //

   //Execute the strategy here

   //Buy if MACD is Negative and MACD from bar 2 is below signal

   //and MACD from bar 1(just closed) is above signal(MACD has just crossed up)

   //sell if MACD is positive

   // and MACD from bar 2 is above signal

   // and MACD from bar 1 (just closed) is below signal(MACD has just crossed down)

   //

  

   

   if (currentBuy != EMPTY_VALUE){

       CloseAll(ORDER_TYPE_SELL);

       OrderOpen(ORDER_TYPE_BUY,StopLoss, TakeProfit);

      }else

   if (currentSell != EMPTY_VALUE) {

       CloseAll(ORDER_TYPE_BUY);

       OrderOpen(ORDER_TYPE_SELL,StopLoss, TakeProfit);

      }

    //

    // save any information for next time

    //

    lastBuy = currentBuy;

    lastSell=currentSell;

    

    return;

    }

 bool NewBar() {

 

   static datetime   prevTime =0;

   datetime          currentTime=iTime(Symbol(),Period(),0);

   if(currentTime!=prevTime){

      prevTime = currentTime;

      return(true);

      }

      return(false);

      }

      

void CloseAll(ENUM_ORDER_TYPE orderType){


   int cnt =OrdersTotal();

   for (int i=cnt-1;i>=0; i--){

      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){

       if(OrderSymbol()==Symbol() && OrderMagicNumber()==InpMagicNumber

          && OrderType()==orderType){

          OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0);

          }

         }

      }

  }


    bool OrderOpen(ENUM_ORDER_TYPE orderType,double stopLoss,double takeProfit){

      int ticket;

      double openPrice;

      double stopLossPrice;

      double takeProfitPrice;

      

    if (orderType==ORDER_TYPE_BUY) {

      openPrice   = SymbolInfoDouble(Symbol(),SYMBOL_ASK);

      stopLossPrice = openPrice - stopLoss;

      takeProfitPrice = openPrice + takeProfit;

     } else

    if (orderType==ORDER_TYPE_SELL){

      openPrice   = SymbolInfoDouble(Symbol(),SYMBOL_BID);

      stopLossPrice  = openPrice + stopLoss;

      takeProfitPrice= openPrice - takeProfit;

     } else{

       return(false);

    }

    ticket = OrderSend(Symbol(), orderType, InpOrderSize, openPrice,0,stopLossPrice,takeProfitPrice);

    return(ticket>0);    

     }


<ex4 Deleted>

 

Forum on trading, automated trading systems and testing trading strategies

When you post code please use the CODE button (Alt-S)!

Use the CODE button



 
Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I have moved your topic to the MQL4 and Metatrader 4 section.
 
zaman16:    I am not able to get the buffer value from icustom ..
   double   currentBuy = iCustom(Symbol(),Period(),IndicatorName,BufferBuy,1);
   double   currentSell = iCustom(Symbol(),Period(),IndicatorName,BufferSell,1);
  1. “Can't get” 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

  2. Make sure the name is correct in the «DataFolder»\MQL4\Indicators and that you compiled it.
  3. Print out last error and find out why.
 
William Roeder:
  1. “Can't get” 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

  2. Make sure the name is correct in the «DataFolder»\MQL4\Indicators and that you compiled it.
  3. Print out last error and find out why.

 Hi William,

    I am very new to mql4 and also to this forum. Appreciate your help and will try to add the datafolder and test.

thank you

 
zaman16:

 Hi William,

    I am very new to mql4 and also to this forum. Appreciate your help and will try to add the datafolder and test.

thank you

You forgot the extern of your indicator :

double   currentBuy = iCustom(Symbol(),Period(),IndicatorName,BufferBuy,1);
double   currentBuy = iCustom(Symbol(),Period(),IndicatorName, extern1, extern2, estern3 .....BufferBuy,1);
 
ffoorr: You forgot the extern of your indicator :

If you "forget" you get the indicator's defaults.