Download MetaTrader 5

CustomIndicatorNotCalling Properly

To add comments, please log in or register
Rock-Trader.com
197
Rohit Sharma  

Dear Traders,

I have some problem here i know that,How super trend works.

iCustom(NULL,0,"SuperTrend",10,3,0,1) //buffer 0 ie uptrend
 
iCustom(NULL,0,"SuperTrend",10,3,1,1) //buffer 1 ie downtrend

But My Trading Condition is When ATR rising and Super trend give BUY signal A Blue Buy arrow should come,

but i find some problem in my coding, can anybody help me please

//+------------------------------------------------------------------+
//|                                                 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 int   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=Bars-Counted_bars;                
  
     {
      if((iATR(Symbol(),0,Magic_Value,i)>iATR(Symbol(),0,Magic_Value,i+1))&& (iCustom(NULL,0,"Supertrend",10,3,0,i+1)))
      {
         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)))
      {
         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))))
      {
         NewBuyBuffer[i] = Low[i] - 10 * Point;
         Buy = false;
         if (Time[i] == Time[1])
         {
            Alert ("Rock Trader: ",Symbol()+" : Sell @ "+Open[0]);
            Alert ("Rock Trader: ",Symbol()+" : Sell StopLoss @ "+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))))
      {
         NewSellBuffer[i]=High[i] + 10 * Point;
         Sell = false;
         if (Time[i] == Time[1])
         {
            Alert ("Rock Trader: ",Symbol()+" : Sell @ "+Open[0]);
            Alert ("Rock Trader: ",Symbol()+" : Sell StopLoss @ "+SelVal);
         }
      }         
      i--;                          // Calculating index of the next bar
      WindowRedraw();
     }
   
   return(rates_total);
  }



//+------------------------------------------------------------------+
honest_knave
Moderator
2296
honest_knave  
//+------------------------------------------------------------------+
//|                                                    Myversion.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              https://www.mql5.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      Magic_Value=4;

input int      Periods = 3;
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");
//---
   Calls();
   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);
   i=Bars-Counted_bars;           // Index of the first uncounted
   while(i>=0)                      // Loop for uncounted bars
     {
      if((iATR(Symbol(),0,Magic_Value,i)>iATR(Symbol(),0,Magic_Value,i+1))&& iCustom(NULL,0,"SuperTrend",10,3,0,i+1))
      {
         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))
      {
         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)))
      {
         NewBuyBuffer[i] = Low[i] - 10 * Point;
         Buy = false;
         if (Time[i] == Time[1])
         {
            Alert ("Rock Trader: ",Symbol()+" : Sell @ "+Open[0]);
            Alert ("Rock Trader: ",Symbol()+" : Sell StopLoss @ "+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)))
      {
         NewSellBuffer[i]=High[i] + 10 * Point;
         Sell = false;
         if (Time[i] == Time[1])
         {
            Alert ("Rock Trader: ",Symbol()+" : Sell @ "+Open[0]);
            Alert ("Rock Trader: ",Symbol()+" : Sell StopLoss @ "+SelVal);
         }
      }         
      i--;                          // Calculating index of the next bar
      WindowRedraw();
     }
   
   return(rates_total);
  }
void Calls()
{
double j =  iCustom(Symbol(),0,"Rock-Trader-1","9048034884",0,1);
double h = iCustom(Symbol(),0,"Rock-Trader-2","8590301300",0,1);
double i = iCustom(Symbol(),0,"Rock-Trader-3","9388301300",0,1);
double b = iCustom(Symbol(),0,"Rock-Trader-4","8590301300",0,1);
double c = iCustom(Symbol(),0,"Rock-Trader-5","9388301300",0,1);
}


//+------------------------------------------------------------------+
Keith Watford
Moderator
10566
Keith Watford  

I posted in your other thread

GumRai 2014.05.07 23:42 #

   i=Bars-Counted_bars;           // Index of the first uncounted

"When Counted_bars==0, i will be out of range.

ie. if there are 100 bars on the chart, this will calculate as 100-0, equals 100.

But the chart bars are indexed 0 to 99, so anything that tries to calculate with bar index [100+] will result in "Array out of range"

Curiously, this doesn't seem to matter with iCustom calls, as they return 0.00 instead of an Error.

Also "Array out of range" doesn't always result in a critical error. It does seem to if changing time-frames though.

Make sure that if Counted_bars==0 you reduce i by an amount that will more than cover any possible look back in the code."

Rock-Trader:



Could you Please Provide me the code, which should I replace ? I have Posted the pic off error I getting in Journel and Experts .

Please help me sir.


Thank You

Alex


Well, you use [i+1] in your code and for some strange reason, you decided to name the period in the iATR call "Magic_Value"

Try something like this

   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=Bars-Counted_bars;           // Index of the first uncounted

Why ask for help and then ignore the advice that you are given?

.

.

.

.

iCustom(NULL,0,"SuperTrend",10,3,0,1) is not a proper boolean expression.

if((iATR(Symbol(),0,Magic_Value,i)>iATR(Symbol(),0,Magic_Value,i+1))&& iCustom(NULL,0,"SuperTrend",10,3,0,1))

//iCustom(NULL,0,"SuperTrend",10,3,0,1) If the buffer holds a calculated value or EMPTY_VALUE, it will always return true
Rock-Trader.com
197
Rohit Sharma  
honest_knave:

Thanks For your Replay,

But its not working Brother,i dont know why, theres no arrows comming on screen.

honest_knave
Moderator
2296
honest_knave  

I didn't look through the code - I just spotted an obvious error.

Take a look at GumRai's suggestions - that should get you going in the right direction.

Ian Venner
2584
Ian Venner  

i+1 would be fine because the loop is counting down, but the main loop should begin from Bars - 2 to allow for that lookback and as GumRai pointed out the if condition is not going to work as expected that way

whroeder1
16349
whroeder1  
  1. GumRai: I posted in your other thread

    Why ask for help and then ignore the advice that you are given?
    As did I Look back is 1.
  2. Rock-Trader: Could you please provide me the Full code, sir ?
    I DID
Rock-Trader.com
197
Rohit Sharma  
GumRai:

I posted in your other thread

GumRai 2014.05.07 23:42 #

"When Counted_bars==0, i will be out of range.

ie. if there are 100 bars on the chart, this will calculate as 100-0, equals 100.

But the chart bars are indexed 0 to 99, so anything that tries to calculate with bar index [100+] will result in "Array out of range"

Curiously, this doesn't seem to matter with iCustom calls, as they return 0.00 instead of an Error.

Also "Array out of range" doesn't always result in a critical error. It does seem to if changing time-frames though.

Make sure that if Counted_bars==0 you reduce i by an amount that will more than cover any possible look back in the code."

Rock-Trader:



Could you Please Provide me the code, which should I replace ? I have Posted the pic off error I getting in Journel and Experts .

Please help me sir.


Thank You

Alex


Well, you use [i+1] in your code and for some strange reason, you decided to name the period in the iATR call "Magic_Value"

Try something like this

Why ask for help and then ignore the advice that you are given?

.

.

.

.

iCustom(NULL,0,"SuperTrend",10,3,0,1) is not a proper boolean expression.


Dear Traders and Programers,

I am not a professional Programmer, i could do something before 2 years back, after an accident i have some memory lose,

my new code is not working properly i don't get any arrows on the screen, if somebody can help please help me.

i did some programming few years back now i canot remember anything, so i need ur help friends,

https://www.mql5.com/en/code/164

//+------------------------------------------------------------------+
//|                                                 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 int   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=Bars-Counted_bars;                
  
     {
      if((iATR(Symbol(),0,Magic_Value,i)>iATR(Symbol(),0,Magic_Value,i+1))&& (iCustom(NULL,0,"Supertrend",10,3,0,i+1)))
      {
         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)))
      {
         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))))
      {
         NewBuyBuffer[i] = Low[i] - 10 * Point;
         Buy = false;
         if (Time[i] == Time[1])
         {
            Alert ("Rock Trader: ",Symbol()+" : Sell @ "+Open[0]);
            Alert ("Rock Trader: ",Symbol()+" : Sell StopLoss @ "+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))))
      {
         NewSellBuffer[i]=High[i] + 10 * Point;
         Sell = false;
         if (Time[i] == Time[1])
         {
            Alert ("Rock Trader: ",Symbol()+" : Sell @ "+Open[0]);
            Alert ("Rock Trader: ",Symbol()+" : Sell StopLoss @ "+SelVal);
         }
      }         
      i--;                          // Calculating index of the next bar
      WindowRedraw();
     }
   
   return(rates_total);
  }



//+------------------------------------------------------------------+
qjol
3243
qjol  
since we don't have your custom indicators "Supertrend", "Rock-Trader-1" - "Rock-Trader-5" we cant checked out for you, even if we would try harder to help you
Rock-Trader.com
197
Rohit Sharma  
qjol:
since we don't have your custom indicators "Supertrend", "Rock-Trader-1" - "Rock-Trader-5" we cant checked out for you, even if we would try harder to help you

qjol:
since we don't have your custom indicators "Supertrend", "Rock-Trader-1" - "Rock-Trader-5" we cant checked out for you, even if we would try harder to help you


Dear, thanks for your help, i updated new code, it was my mistake i uploaded a wrong one,

Actually i am looking for a Buy arrow with alert when ATR rising and supertrend give a buy, When atr rise and supertrend signal sell give a sell arrow with alert.

i am posting supertrend indicator also. Please help if you need money for your help i am happy to give.

Files:
qjol
3243
qjol  

in your code:

&& (iCustom(NULL,0,"Supertrend",10,3,0,i+1)

what do you want to check ?

12
To add comments, please log in or register