CustomIndicatorNotCalling Properly - page 2

 
it's taking a very long time to calculate

so, i reduce the bars (to 200) for calculation

//+------------------------------------------------------------------+
//|                                                 Mynewversion.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 4       // Number of buffers

//--- input parameters
input int      Magic_Value=4;
input int Magic_Period=20;
input int      Periods = 3;
input double   Multiplier = 1.25;

int limit, counted_bars;
double BuyVal, SelVal;
double BuyBuffer[];
double SellBuffer[];
double NewBuyBuffer[];
double NewSellBuffer[];
bool Buy = false;
bool Sell = false;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0, BuyBuffer);
   SetIndexStyle(0,DRAW_ARROW,2,1,clrBlue);
   SetIndexArrow(0,119);
   SetIndexLabel(0,"RT Buy SL");
  
   SetIndexBuffer(1, SellBuffer);
   SetIndexStyle(1,DRAW_ARROW,2,1,clrRed);
   SetIndexArrow(1,119);
   SetIndexLabel(1,"RT Sell SL");
   
   SetIndexBuffer(2, NewBuyBuffer);
   SetIndexStyle(2,DRAW_ARROW,2,3,clrBlue);
   SetIndexArrow(2,221);
   SetIndexLabel(2,"RT Buy Now");
   
   SetIndexBuffer(3, NewSellBuffer);
   SetIndexStyle(3,DRAW_ARROW,2,3,clrRed);
   SetIndexArrow(3,222);
   SetIndexLabel(3,"RT Sell Now");
//---
   
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---

int i, Counted_bars;                // Number of counted bars
//--------------------------------------------------------------------
    Counted_bars=IndicatorCounted(); // Number of counted bars
   if(Counted_bars<0)return(-1);
   int startbar=1+1+Magic_Value;
   if(Counted_bars<startbar)
      Counted_bars=startbar;
   i=200;//Bars-Counted_bars; 
   
  while(i>=0)
      {
      if((iATR(Symbol(),0,Magic_Value,i)>iATR(Symbol(),0,Magic_Value,i+1))&& (iCustom(NULL,0,"Supertrend",10,3,0,i+1) != EMPTY_VALUE))
         {
         BuyBuffer[i]=Low[i];
         BuyVal = High[i];
         Buy = true;
         }

      if((iATR(Symbol(),0,Magic_Value,i)>iATR(Symbol(),0,Magic_Value,i+1)) && (iCustom(NULL,0,"Supertrend",10,3,1,i+1) != EMPTY_VALUE))
         {
         SellBuffer[i]=High[i];
         SelVal = Low[i];
         Sell = true;
         }

      if ((BuyVal !=0) && (Close[i] > BuyVal) && Buy == true &&  (iATR(Symbol(),0,Magic_Value,i)>iATR(Symbol(),0,Magic_Value,i+1)&& (iCustom(NULL,0,"Supertrend",10,3,0,i+1) != EMPTY_VALUE)))
      {
         NewBuyBuffer[i] = Low[i] - 10 * Point;
         Buy = false;
         if (Time[i] == Time[1])
         {
            Alert ("Rock Trader: ",Symbol()+" : Sell @ "+ (string)Open[0]);
            Alert ("Rock Trader: ",Symbol()+" : Sell StopLoss @ "+ (string)BuyVal);
         }         
      }
      if ((iClose(Symbol(),0,i)<SelVal)&& Sell == true && (iATR(Symbol(),0,Magic_Value,i)>iATR(Symbol(),0,Magic_Value,i+1)&& (iCustom(NULL,0,"Supertrend",10,3,1,i+1) != EMPTY_VALUE)))
      {
         NewSellBuffer[i]=High[i] + 10 * Point;
         Sell = false;
         if (Time[i] == Time[1])
         {
            Alert ("Rock Trader: ",Symbol()+" : Sell @ "+ (string)Open[0]);
            Alert ("Rock Trader: ",Symbol()+" : Sell StopLoss @ "+ (string)SelVal);
         }
      }         
      i--;                          // Calculating index of the next bar
   }
      WindowRedraw();
   
   return(rates_total);
  }



//+------------------------------------------------------------------+
 
qjol:
it's taking a very long time to calculate

so, i reduce the bars (to 200) for calculation



Dear Friend,

Why its not giving any arrows ?

Still its works in the same way, Any hope ?

Thanks

suresh

 

there is no error

and the code i uploaded is working just fine for me

it takes time (it took me about a minute and 55 seconds) ("200 bars only")

i think you should send the code to service desk to check it out

 

This superTrend is properly coded, and already has arrow :

Files:
 

Dear Traders,

Please help me again, now I have some problem with ADX,

When I added ADX in the code my system get hang ! ?

MT4 terminal get hand like Buffering, please check my code is correct .


BUY Condition- ATR rising, AdX value Must be more than 22 Leval, Supertrend(Rocking-Trend) Buy Buffer. (ADX +DI>-DI I don't know hoe to program this)

SELL Condition - ATR Rising, ADX Level > 22, Supertrend Sell Buffer (ADX -DI>+DI Please help me to program this)

Please check my code, and suggest if there is any mistake

//+------------------------------------------------------------------+
//|                                         RockTrader Indicator.mq4 |
//|                            Copyright 2014, Scorpion IT Solutions |
//|                               http://www.scorpionitsolutions.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, Scorpion IT Solutions"
#property link      "http://www.scorpionitsolutions.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 4       // Number of buffers

//--- input parameters
input int      ATR = 14;
input int      Periods = 10;
input double   Multiplier = 3.0;
input int      ADX_Period=14;
input double   Adx_Min=22.0;

int i, Counted_bars,limit;
bool Buy = false;
bool Sell = false;
double BuyBuffer[];
double SellBuffer[];
double BuyStopLoss[];
double SellStopLoss[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   IndicatorBuffers(4);

   SetIndexBuffer(0, BuyBuffer);
   SetIndexStyle(0,DRAW_ARROW,2,3,clrBlue);
   SetIndexArrow(0,221);
   SetIndexLabel(0,"Rock Trader Buy");
  
   SetIndexBuffer(1, SellBuffer);
   SetIndexStyle(1,DRAW_ARROW,2,3,clrRed);
   SetIndexArrow(1,222);
   SetIndexLabel(1,"Rock Trader Sell");
   
   SetIndexBuffer(2, BuyStopLoss);
   SetIndexStyle(2,DRAW_ARROW,2,1,clrGold);
   SetIndexArrow(2,119);
   SetIndexLabel(2,"RT Buy Stoploss");
   
   SetIndexBuffer(3, SellStopLoss);
   SetIndexStyle(3,DRAW_ARROW,2,1,clrGold);
   SetIndexArrow(3,119);
   SetIndexLabel(3,"RT Sell Stoploss");
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   int counted_bars = IndicatorCounted();
   if(counted_bars < 0) return(-1);
   if(counted_bars > 0) counted_bars--;
   limit=Bars-counted_bars;
//----
   for (i = Bars; i >= 0; i--) {

      if( iATR(Symbol(),0,ATR,i)>iATR(Symbol(),0,ATR,i+1) &&
         iCustom(Symbol(),0,"SuperTrend",Periods,Multiplier,0,i+1) != EMPTY_VALUE &&
          iADX(Symbol(),0,ADX_Period,PRICE_HIGH,MODE_MAIN,i)>Adx_Min )
      {
         BuyBuffer[i]=Low[i];
         BuyStopLoss[i+1]=Low[i+1];
         Buy = true;
         Sell = false;
         if (Time[i] == Time[1])
         {
            Alert ("Rock Trader: ",Symbol()+" : Sell @ "+DoubleToStr(Open[0]));
            Alert ("Rock Trader: ",Symbol()+" : Sell StopLoss @ "+DoubleToStr(Low[i+1]));
         }         
      }
      
      if( iATR(Symbol(),0,ATR,i) > iATR(Symbol(),0,ATR,i+1) && 
iCustom(Symbol(),0,"SuperTrend",Periods,Multiplier,1,i+1) != EMPTY_VALUE && 
iADX(Symbol(),0,ADX_Period,PRICE_HIGH,MODE_MAIN,i)>Adx_Min )

      {
         SellBuffer[i]=High[i];
         SellStopLoss[i+1]=High[i+1];
         Buy = false;
         Sell = true;
         if (Time[i] == Time[1])
         {
            Alert ("Rock Trader: ",Symbol()+" : Sell @ "+DoubleToStr(Open[0]));
            Alert ("Rock Trader: ",Symbol()+" : Sell StopLoss @ "+DoubleToStr(High[i+1]));
         }
         //Alert(High[i]);
      }
     }

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
   int counted_bars = IndicatorCounted();
   if(counted_bars < 0) return(-1);
   if(counted_bars > 0) counted_bars--;
   limit=Bars-counted_bars;
//----
   for (i = Bars; i >= 0; i--) {

      if( iATR(Symbol(),0,ATR,i)>iATR(Symbol(),0,ATR,i+1) &&
 
  1. No need for decrement Contradictory information on IndicatorCounted() - MQL4 forum
  2. Why are you recalculating every bar?
  3. when i is Bars or or Bars - 1 iATR(i+1) is meaningless
  4. when i is [Bars-2 .. Bars-ATR-1] iATR(ATR, i+1) is not defined. Handle look backs.
       int counted_bars = IndicatorCounted();
       if(counted_bars < 0) return(-1);
       if(counted_bars < ATR+1 ) counted_bars = ATR+1; iATR( ATR, i+1)
    // limit=Bars-counted_bars;                                       
    //----
       for (i = Bars - 1 -counted_bars; i >= 0; i--) {
    
          if( iATR(Symbol(),0,ATR,i)>iATR(Symbol(),0,ATR,i+1) &&
     

 
Rock-Trader:

Dear Traders,

Please help me again, now I have some problem with ADX,

When I added ADX in the code my system get hang ! ?

MT4 terminal get hand like Buffering, please check my code is correct .


BUY Condition- ATR rising, AdX value Must be more than 22 Leval, Supertrend(Rocking-Trend) Buy Buffer. (ADX +DI>-DI I don't know hoe to program this)

SELL Condition - ATR Rising, ADX Level > 22, Supertrend Sell Buffer (ADX -DI>+DI Please help me to program this)

Please check my code, and suggest if there is any mistake



You have already been told numerous times that you cannot use i = Bars as the index in Time[i] etc.

People will not be willing to help you if you continue to repeat the same mistake.

 
WHRoeder:
  1. No need for decrement Contradictory information on IndicatorCounted() - MQL4 forum
  2. Why are you recalculating every bar?
  3. when i is Bars or or Bars - 1 iATR(i+1) is meaningless
  4. when i is [Bars-2 .. Bars-ATR-1] iATR(ATR, i+1) is not defined. Handle look backs.

I get an Error on this line 'iATR wrong parameters count'

if(counted_bars < ATR+1 ) counted_bars = ATR+1; iATR( ATR, i+1)
 
Rock-Trader: I get an Error on this line 'iATR wrong parameters count'
When in doubt, THINK.
if(counted_bars < ATR+1 ) counted_bars = ATR+1; // iATR( ATR, i+1)
 
WHRoeder:
When in doubt, THINK.



Dear WHRoeder,

Please Don't get Irate or Angry on my silly Droughts, its really hearts me.

Thanks for your helping mind.

Suresh

Reason: