code works on xxxJPY pairs but not others

 

I can't think why this code would work on JPY pairs but not on the 5 decimal place pairs.

Any ideas?


The indicator "testwindow" works on both so why doesn't iCustom pick up the value?


//+------------------------------------------------------------------+
//|                                                         test.mq4 |
//|                      Copyright © 2011, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
double CrossUp[];
double CrossDown[];

#property indicator_buffers 2
#property indicator_color1 LimeGreen
#property indicator_width1 1
#property indicator_color2 Red
#property indicator_width2 1

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0, DRAW_ARROW, EMPTY); 
   SetIndexArrow(0, 233);
   SetIndexBuffer(0, CrossUp);
   SetIndexStyle(1, DRAW_ARROW, EMPTY);
   SetIndexArrow(1, 234);
   SetIndexBuffer(1, CrossDown);

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   string newestArrow = "";
string name;
int j;
int i;
for(j = 0; j < Bars-1 ; j++){
   for(i = ObjectsTotal()-1; i >= 0; i--){
      name = ObjectName(i);
      if(ObjectType(name) == OBJ_ARROW && ObjectGet(name, OBJPROP_TIME1) >= Time[i]){
         newestArrow = name;
         break;
      }
   }
   if(newestArrow != "") break;
}

for(i = ObjectsTotal()-1; i >= 0; i--){
   name = ObjectName(i);
   if(name == newestArrow) continue;
   if(ObjectType(name) == OBJ_ARROW) ObjectDelete(name);
}
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//----
   //double val=iCustom(Symbol(), Period(), "testwindow",4,7,0,0);
   //Comment(DoubleToStr(val,5));
//----


//ARROWS ON CHARTS

   int limit, i, counter; 
   //int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   
   for(i = 0; i <= limit; i++)
   {
      //double val=iCustom(Symbol(), Period(), "TSI",4,7,0,i);
      
      CrossUp[i] = EMPTY_VALUE;
      CrossDown[i] = EMPTY_VALUE;
      double MA21 = iMA(NULL,0,21,0,MODE_EMA,PRICE_CLOSE,i);
      double MA55 = iMA(NULL,0,55,0,MODE_EMA,PRICE_CLOSE,i);
      if (MA21<=MA55) //downtrend
      {
         double SellTestValue = 60;
         double BuyTestValue = -75; //ie needs to be really oversold before buying
      }
      
      if (MA21>=MA55) //downtrend
      {
         SellTestValue = 75; //ie needs to be really overbought before selling
         BuyTestValue = -60; 
      }
      
      //sell
      //if (val >= 75)
      if (iCustom(Symbol(), Period(), "testwindow",4,7,0,i) >= SellTestValue)
      {
         CrossDown[i] = iHigh(NULL,NULL,i) + 0.1500;
      }

      //buy
      //if (val <= -75)
      if (iCustom(Symbol(), Period(), "testwindow",4,7,0,i) <= BuyTestValue)
      {
         CrossUp[i] = iLow(NULL,NULL,i) - 0.1500;
      }
      
   }

   return(0);
  }
//+------------------------------------------------------------------+
 
SanMiguel:

The indicator "testwindow" works on both so why doesn't iCustom pick up the value?


How many extern variables does your Indicator
"testwindow" h
ave ?
 
RaptorUK:
SanMiguel:

The indicator "testwindow" works on both so why doesn't iCustom pick up the value?


How many extern variables does your Indicator
"testwindow" h
ave ?

2.

I put those in as 4,7 in the above.

 
SanMiguel:

2.

I put those in as 4,7 in the above.

OK, just checking . . . can't help much more without seeing the code for the Indicator . .
 

Attached


  //+------------------------------------------------------------------+
//|                                                   testwindow.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Black
//---- input parameters
extern int       First_R=4;
extern int       Second_S=7;
//---- buffers
double TSI_Buffer[];
double MTM_Buffer[];
double EMA_MTM_Buffer[];
double EMA2_MTM_Buffer[];
double ABSMTM_Buffer[];
double EMA_ABSMTM_Buffer[];
double EMA2_ABSMTM_Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorBuffers(7);
   SetIndexBuffer(1, MTM_Buffer);
   SetIndexBuffer(2, EMA_MTM_Buffer);
   SetIndexBuffer(3, EMA2_MTM_Buffer);
   SetIndexBuffer(4, ABSMTM_Buffer);
   SetIndexBuffer(5, EMA_ABSMTM_Buffer);
   SetIndexBuffer(6, EMA2_ABSMTM_Buffer);

   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,TSI_Buffer);
   SetIndexLabel(0,"TSI");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- TODO: add your code here
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   int limit,i;
   limit=Bars-counted_bars-1;
   for (i=Bars-1;i>=0;i--)
      {
      MTM_Buffer[i]=Close[i]-Close[i+1];//iMomentum(NULL,0,1,PRICE_CLOSE,i);
      ABSMTM_Buffer[i]=MathAbs(MTM_Buffer[i]);
      //TSI_Buffer[i]=ABSMTM_Buffer[i];
      }
      
   for (i=Bars-1;i>=0;i--)
      {
      EMA_MTM_Buffer[i]=iMAOnArray(MTM_Buffer,0,First_R,0,MODE_EMA,i);
      EMA_ABSMTM_Buffer[i]=iMAOnArray(ABSMTM_Buffer,0,First_R,0,MODE_EMA,i);
      //TSI_Buffer[i]=EMA_ABSMTM_Buffer[i];
      }

   for (i=Bars-1;i>=0;i--)
      {
      EMA2_MTM_Buffer[i]=iMAOnArray(EMA_MTM_Buffer,0,Second_S,0,MODE_EMA,i);
      EMA2_ABSMTM_Buffer[i]=iMAOnArray(EMA_ABSMTM_Buffer,0,Second_S,0,MODE_EMA,i);
      //TSI_Buffer[i]=EMA2_ABSMTM_Buffer[i];
      }

   for (i=Bars-1;i>=0;i--)
      {
      TSI_Buffer[i]=100.0*EMA2_MTM_Buffer[i]/EMA2_ABSMTM_Buffer[i];
      }
      
//---- TODO: add your code here
   
   //Comment (DoubleToStr(TSI_Buffer[0],5));
   if (
         (TSI_Buffer[0]>=75 || TSI_Buffer[0]<=-75) &&
         GlobalVariableGet(Symbol()+"TSIAlerts"+Symbol()) < iTime(NULL,PERIOD_H1,0)
      )
   {
      GlobalVariableSet(Symbol()+"TSIAlerts"+Symbol(), iTime(NULL,PERIOD_H1,0));
      Alert("TSIAlert");
   }
   
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
 

This is your problem . . . .

   CrossDown[i] = iHigh(NULL,NULL,i) +    0.1500;  //  <--   this hard coded value
      }

      //buy
      //if (val <= -75)
      if (iCustom(Symbol(), Period(), "testwindow",4,7,0,i) <= BuyTestValue)
      {
         CrossUp[i] = iLow(NULL,NULL,i) -    0.1500;   //  <--   this hard coded value

your arrows are there, you just can't see them . . .

 
SanMiguel:

I can't think why this code would work on JPY pairs but not on the 5 decimal place pairs.

CrossDown[i] = iHigh(NULL,NULL,i) + 0.1500;
On JPY that value is 15 pips, on EURUSD it is 1500 pips. Don't hard code numbers. Adjust for 4/5 digit brokers
//++++ These are adjusted for 5 digit brokers.
int     pips2points;    // slippage  3 pips    3=points    30=points
double  pips2dbl;       // Stoploss 15 pips    0.015      0.0150
int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
int     init(){
     if (Digits % 2 == 1){      // DE30=1/JPY=3/EURUSD=5 forum.mql4.com/43064#515262
                pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
    } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
//---- These are adjusted for 5 digit brokers.
}
:
crossUp[i] = iLow(NULL,NULL,i) - 15*pips2dbl;
Why use a function call when the predefined array is identical iLow(NULL,NULL, i) == Low[i]
 
Thanks all.
 

How can I get an indicator from the arrows to show how far price moves pat the arrow until the next arrow appears?

For example, if there is a buy arrow, I need to see how many pips on average price moves past that arrow until the next sell arrow signal is given.

Then I can work out some standard deviations and such.

 

You could . . .

Store the value for the current arrow, when the next appears calculate and plot the difference between the last arrow and the current, then store the value for the current arrow, repeat . .

Reason: