Download MetaTrader 5

help me fix this indi

To add comments, please log in or register
Register as a seller and start making profit!
james
24
james 2014.04.06 18:20 


I found this indi which looks very promising on backtest, but as soon as i put it in live, well..you can see for yourself. However when I ran through the code it didnt make use of anything that really repaints, merely RSI, ADX ATR and momentum. I'm quote confused as to why the indi messes up in live like this? cheers

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
//---- input parameters
extern string symbolhint = "Symbol (leave blank for current chart):";
extern string symbol = "";
extern string tfhint = "timeframe (in Minutes, 0 for current):";
extern int timeFrame = 0;
extern int cciPeriod = 6;
extern int atrPeriod = 12;
extern int momentumPeriod = 7;
extern int rsiPeriod = 7;
extern int adxPeriod = 7;
extern string indihint1 = "periods for control:";
extern int rsiControlPeriod = 12;
extern int adxControlPeriod = 12;
extern int rsiTrigger = 50;
extern int adxTrigger = 20;
extern string subtracthint = "default: -2, -1";
extern double subtractFromSignalVal = -2.0;
extern double subtractFromIndiVal = -1.0;
extern string hl0 = "-=------------------------------------------------------=-";
extern bool showBuySignals = true;
extern bool showSellSignals = true;
extern string wingdingshint = "default: 233, 234";
extern int wingdingsUpArrow = 233;
extern int wingdingsDownArrow = 234;
extern string hl1 = "-=------------------------------------------------------=-";
extern string alerthint = "optional settings:";
extern bool Alerts = false;
extern bool PlaySounds = false;
extern string alerthint1 = "Want change sounds for signals?";
extern string alerthint2 = "(must be in MT4\sounds\ directory";
extern string alerthint3 = "and have extension .wav)";
extern string LongSignalSoundFile = "alert.wav";
extern string ShortSignalSoundFile = "alert.wav";
extern bool SignalMail = False;
datetime lastbartime;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//----

int    nShift;   
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {

//----    
    SetIndexStyle(0, DRAW_ARROW, 0, 1);
    SetIndexArrow(0, wingdingsUpArrow);
    SetIndexBuffer(0, ExtMapBuffer1);
//----
    SetIndexStyle(1, DRAW_ARROW, 0, 1);
    SetIndexArrow(1, wingdingsDownArrow);
    SetIndexBuffer(1, ExtMapBuffer2);
//---- name for DataWindow and indicator subwindow label
    IndicatorShortName("#MomentumChartSignalsIndicator"); // (" + indiName + ")
    SetIndexLabel(0, "BUY SIGNAL");
    SetIndexLabel(1, "SELL SIGNAL"); 
//----
    switch(Period())
      {
        case     1: nShift = 1;   break;    
        case     5: nShift = 3;   break; 
        case    15: nShift = 5;   break; 
        case    30: nShift = 10;  break; 
        case    60: nShift = 15;  break; 
        case   240: nShift = 20;  break; 
        case  1440: nShift = 80;  break; 
        case 10080: nShift = 100; break; 
        case 43200: nShift = 200; break;               
      }
//----
    return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
    return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
    if (Time[0] != lastbartime) {
  lastbartime = Time[0];
    int limit;
    int counted_bars = IndicatorCounted();
//---- check for possible errors
    if(counted_bars < 0) 
        return(-1);
//---- last counted bar will be recounted
    if(counted_bars > 0) 
        counted_bars--;
    limit = Bars - counted_bars;
//----
string signalSentAlready = "NONE";
if (symbol == "0" || symbol == "") symbol = Symbol();
    for(int i = 0; i < limit; i++)
      { // start loop
     
        // current data:
        double momVal = iMomentum(symbol,timeFrame,momentumPeriod,PRICE_TYPICAL,i);
        double atrVal = iATR(symbol,timeFrame,atrPeriod,i);
        double cciVal = iCCI(symbol,timeFrame,cciPeriod,PRICE_TYPICAL,i);
        double rsiVal = iRSI(symbol,timeFrame,rsiPeriod,PRICE_TYPICAL,i);
        double adxVal = iADX(symbol,timeFrame,adxPeriod,PRICE_TYPICAL,MODE_MAIN,i);
        double adxPLUSVal = iADX(symbol,timeFrame,adxPeriod,PRICE_TYPICAL,MODE_PLUSDI,i);
        double adxMINUSVal = iADX(symbol,timeFrame,adxPeriod,PRICE_TYPICAL,MODE_MINUSDI,i);

        double signalVal = (momVal / (atrVal + adxVal)) - subtractFromSignalVal; // -2
        double indiVal = ((atrVal + cciVal + rsiVal) / adxVal) - subtractFromIndiVal; // -1
        
         // triggerData:
         double adx1Val = iADX(symbol,timeFrame,adxControlPeriod,PRICE_CLOSE,MODE_MAIN,i);
         double adx1PLUSVal = iADX(symbol,timeFrame,adxControlPeriod,PRICE_CLOSE,MODE_PLUSDI,i);
         double adx1MINUSVal = iADX(symbol,timeFrame,adxControlPeriod,PRICE_CLOSE,MODE_MINUSDI,i);
         double rsi1Val = iRSI(symbol,timeFrame,rsiControlPeriod,PRICE_CLOSE,i);

        //---- SELL SIGNAL:
        if(signalVal < indiVal && adx1MINUSVal < adx1PLUSVal && rsi1Val > rsiTrigger && adx1Val > adxTrigger)
         {
           if (signalSentAlready != "short")
            {
             if (showSellSignals) ExtMapBuffer2[i] = High[i] + nShift*Point;
              if (Alerts) { Alert("SELL SIGNAL at ", symbol,": ",Close[0]," (TF ",Period(),")"); }
              if (PlaySounds) { PlaySound(ShortSignalSoundFile); }
              if (SignalMail) { SendMail(""+symbol+" SELL SIGNAL","SELL SIGNAL on "+symbol+": "+Close[0]+" (Timeframe: "+Period()+")"); }
             signalSentAlready = "short";
            }
         }
         
        //---- BUY SIGNAL:
        if(signalVal > indiVal && adx1PLUSVal < adx1MINUSVal && rsi1Val < rsiTrigger && adx1Val > adxTrigger)
         {
           if (signalSentAlready != "long")
            {
             if (showBuySignals) ExtMapBuffer1[i] = Low[i] - nShift*Point;
              if (Alerts) { Alert("BUY SIGNAL at ", symbol,": ",Close[0]," (TF ",Period(),")"); }
              if (PlaySounds) { PlaySound(LongSignalSoundFile); }
              if (SignalMail) { SendMail(""+symbol+" BUY SIGNAL","BUY SIGNAL on "+symbol+": "+Close[0]+" (Timeframe: "+Period()+")"); }
             signalSentAlready = "long";
            }
         }
         
      } // end loop
//----
    return(0);
  }
  )
Keith Watford
Moderator
9624
Keith Watford 2014.04.06 21:37  
string signalSentAlready="NONE";  //This should not be in start, it should be in init, it is reset every tick.

//
//

         
      } // end loop
//----
    return(0);
  }
  )   //???????  Change to }
signalSentAlready should be declared Globally
ahmednasr
5
ahmednasr 2014.04.28 19:45  
GumRai:
signalSentAlready should be declared Globally

I tried your modifications but it is still repaint heavily :(, any other suggestion !
Bambang Sugianto
10224
Bambang Sugianto 2014.04.29 07:59  
 for(int i = 0; i < limit; i++)

ADX repaint if you using i==0;

Ian Venner
2584
Ian Venner 2014.04.29 15:52  

All of those indicators repaint, ATR, CCI, RSI, ADX.

Alain Verleyen
Moderator
30743
Alain Verleyen 2014.04.29 15:54  
WDholic:

ADX repaint if you using i==0;



SDC:
All those indicators repaint.

Updating value on bar 0 is not repainting.

Repainting is when past data are changed, not current candle.

Ian Venner
2584
Ian Venner 2014.04.29 16:13  

That is open to interpretation. I think most people consider an indicator that changes its value on the zero bar is repainting, and an indicator that gives a fixed value on the zero bar is NRP.

SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.04.29 16:15  
Aren't zero bar tends to change its value over time ? Of course the calculations no longer the same over time as well, isn't it ?
Alain Verleyen
Moderator
30743
Alain Verleyen 2014.04.29 16:21  
SDC:

That is open to interpretation. I think most people consider an indicator that changes its value on the zero bar is repainting, and an indicator that gives a fixed value on the zero bar is NRP.

It's wrong interpretation in my opinion. If bar zero has a fixed value, it means the indicator doesn't take into account the data if the current bar (which is weird for an indicator not ?), or it changes the value of this bar when the bar is shifted to 1, so it changes the value of this bar, and you have a repainting indicator following your interpretation


Edit: can you point me to some indicator which are NRP in your opinion ?

Ian Venner
2584
Ian Venner 2014.04.29 16:23  
Yes, how ever you want to call it, repainting, repositioning, updating, the changing values on the zero bar cause trade signals to be given during the formation of a bar that are not apparent when examining the indicator's pre drawn history on the chart.
Ian Venner
2584
Ian Venner 2014.04.29 16:30  
angevoyageur:
It's wrong interpretation in my opinion. If bar zero has a fixed value, it means the indicator doesn't take into account the data if the current bar (which is weird for an indicator not ?), or it changes the value of this bar when the bar is shifted to 1, so it changes the value of this bar, and you have a repainting indicator following your interpretation


Edit: can you point me to some indicator which are NRP in your opinion ?

Well I could be wrong because really I am just using the terminology as I have seen it used by others in trading forum discussions but the consensus seems to be, NRP indicators are those which either calculate on the open price of the zero bar or project a value for the zero bar based on calculations performed on previous bars, so when you apply them to a chart, signals that are apparent on the indicator's pre drawn history are identical to those created on live trading.
12
To add comments, please log in or register