indicator doesn't show arrows - page 2

 
The old arrows were erroneous and inconsistent now they are true. You need to reconsider your algorithm for the decisions. Remember an indicator can only show you what has past. The old arrows were probably predicting the future and you know a computer cannot do that.
 

Ok, that was what I suspected...so I'll try to combine it with another indicator!


Thank you very much for your help!


leMai

 

I have a new code I was working at, unfortunatelly I am not allowed to open another new topic, so I have to post it here.

I just try to make an average trough the value of the rsi(look in my code), the buffer appears in the window, but it is always only a straight line:


int start()
  {
   double RSI1,RSI2;

   int  limit, i, counted_bars = IndicatorCounted();
//----
   if(counted_bars < 0) 
       return(-1);
//----
   if(counted_bars > 0) 
       counted_bars--;
   int Limit=Bars-counted_bars-1;
   for(i=Limit; i>=0; i--) 
   {
     RSI1 = iRSI(NULL, 0, RSIPeriod1, PRICE_CLOSE, i);
     RSI2 = iRSI(NULL, 0, RSIPeriod2, PRICE_CLOSE, i);

     MABuffer1[i] = (RSI1-RSI2);
   }
   
   
      
   for(i=Limit; i>=0; i--)
   {
     ind_buffer1[i] = iMAOnArray(MABuffer1,0,14,0,MODE_SMA,i);
     Cross[i] = iMAOnArray(ind_buffer1,0,Cross1,0,MODE_SMA,i);
   }
   
   for(i=Limit; i>=0; i--)
      {
        MABuffer1[i]=0;
      }
   
   
   return(0);
}

I don't understand why the first average(ind_buffer[]) workes for some time, but if I make a correction in my code, or if I change a value in the indicator again, it disappears. The second average(cross[]) I was talking about never works, so what can I do?



leMai

 
Put the buffers in separate i loops because you need something in ind_buffer1 before you can do iMAOnArray to it.
 
leMai:

Hello


I am writing my first indicator and I want to show buy and sell signals with arrows. But somehow it doesn't work, is there anybody who can help me?


In this part of code I make a average of the Buffer0. When the direction of the Indicator changes, I want it to give a signal, but it doesn't work:



There aren't any error messages...but there are no arrows or alert!


leMai


Arrow codes are:

SYMBOL_THUMBSUP67Thumb up symbol (C).
SYMBOL_THUMBSDOWN68Thumb down symbol (D).
SYMBOL_ARROWUP241Arrow up symbol (ñ).
SYMBOL_ARROWDOWN242Arrow down symbol (ò).
SYMBOL_STOPSIGN251Stop sign symbol (û).
SYMBOL_CHECKSIGN252Check sign symbol (ü).


The codes you use (233 and 234) wouldn't show up.



 
leMai:

So, now, in live, I have a new problem...offline the indicator shows the signlas in the right time, but when it's running online, there is even every finished minute a sell and a buy signal! this is my current code:


Maybe it would help to if it would only go into the direction loop(the now&last-loops) if the bar(in this case one minute) is finished and a new begins! but I don't know how to code it but maybe that isn't the fault!

Is there a possibility that the start-function only starts, if a new bar has began?

Can you help me?

Thanks for your help!



leMai



Maybe the problem is in this paragraph?

double iMAOnArray( double array[], int total, int period, int ma_shift, int ma_method, int shift)
Calculation of the Moving Average on data stored in a numeric array. Unlike iMA(...), the iMAOnArray function does not take data by symbol name, timeframe, the applied price. The price data must be previously prepared. The indicator is calculated from left to right. To access to the array elements as to a series array (i.e., from right to left), one has to use the ArraySetAsSeries function.



 

Thank you, now it works, I just had to change the i for the beginning of the loop. But why am I not allowed to open a nwe topic and what can I do?


leMai

 

Now I have a new problem, there are sometimes to many signals if it is running online...I have been triing to fix it for a long time, but I can't find a mistake...


extern int RSIPeriod1=14;
extern int RSIPeriod2=28;
extern int Cross1=10;
extern double difference=2.0;

double   ind_buffer1[];
double   MABuffer1[];
double   Cross[];
double   UpArrow[];
double   DnArrow[];

double now=1,last=0;
int direction=0;

...

indicator deklaration

...

int start()
  {
   double RSI1,RSI2;

   int  limit, i, counted_bars = IndicatorCounted();
//----
   if(counted_bars < 0) 
       return(-1);
//----
   if(counted_bars > 0) 
       counted_bars--;
   int Limit=Bars-counted_bars-1;
   for(i=Limit; i>=0; i--) 
   {
     RSI1 = iRSI(NULL, 0, RSIPeriod1, PRICE_CLOSE, i);
     RSI2 = iRSI(NULL, 0, RSIPeriod2, PRICE_CLOSE, i);

     MABuffer1[i] = (RSI1-RSI2);
     
   }
   
   
      
   for(i=Limit; i>=0; i--)
   {
     ind_buffer1[i] = iMAOnArray(MABuffer1,0,14,0,MODE_SMA,i);   
   }
   
   
   int top=ArraySize(ind_buffer1);
   for(i=top; i>=0; i--) 
    {
      Cross[i]=iMAOnArray(ind_buffer1,Bars,Cross1,0,MODE_SMA,i);
      now=Cross[i];
     
    
      if(now>(last+(difference/1000)))
      {
        if(direction<1)
        {
         UpArrow[i]=Cross[i];
         direction=1;
        } 
      }
        else  
          if(now<(last-(difference/1000)))
          {
            if(direction>-1)
            {
             DnArrow[i]=Cross[i];
             direction=-1;
            }        
          } 
         
      last=Cross[i]; 
    }  
   
   for(i=Limit; i>=0; i--)
      {
        MABuffer1[i]=0;
      }
   
   
   return(0);

Is there anybody who can help me?

Thanks



leMai

 

Now I am trying to write a EA for the first indicator I modified:


//--------------------------------------------------------------------
//                                             Copyright © 2010, LeMai 
//--------------------------------------------------------------------
#property copyright "Copyright © 2010,LeMai"
#property indicator_separate_window

#property indicator_buffers 4
#property indicator_color1 Orange
#property indicator_color2 Blue
#property indicator_color3 LimeGreen
#property indicator_color4 Red

extern int barsToCount=34;   
extern int CountBars=10000;   
extern int CrossLine=4;
extern double difference=2.0;

int j;
double now=1,last=0;
int direction=0;
double     buffer0[];
double     buffer1[];
double     UpArrow[];
double     DnArrow[];
//--------------------------------------------------------------------
int init()
{
   IndicatorShortName(StringConcatenate("TrendLR (",barsToCount,")"));
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
   SetIndexBuffer(0,buffer0);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);
   SetIndexBuffer(1,buffer1);
   SetIndexStyle(2,DRAW_ARROW);
   SetIndexArrow(2,233);
   SetIndexStyle(3,DRAW_ARROW);
   SetIndexArrow(3,234);
   SetIndexBuffer(2,UpArrow);
   SetIndexBuffer(3,DnArrow);
   return(0);
}

//--------------------------------------------------------------------
int deinit()
{  
   return(0);
}

//--------------------------------------------------------------------
int start()
{ 
  int     counted_bars = IndicatorCounted(); 
  double  a, b, c, sumy, sumx, sumxy, sumx2;
  double  prev; 
  double  current; 
  if(Bars <= CountBars + barsToCount+1) return(0);
  int   limit=Bars-counted_bars-1;
  if (limit>CountBars) limit=CountBars;

  for(int shift = limit; shift >= 0; shift--) 
   {
    sumy=0.0; sumx=0.0; sumxy=0.0; sumx2=0.0;
    for(int i=0; i<barsToCount; i++)
     {
        sumy+=Close[i+shift];
       sumxy+=Close[i+shift]*i;
       sumx+=i;
       sumx2+=i*i;
     }   
    c=sumx2*barsToCount-sumx*sumx;
    if (c==0) c=0.1;
    b=(sumxy*barsToCount-sumx*sumy)/c;
    current=-1000*b; 
    prev=current;
    buffer0[shift]= current;        
   }

  int Limit=ArraySize(buffer0);
  for(j=Limit; j>=0; j--) 
   { 
     
     buffer1[j]=iMAOnArray(buffer0,Bars,CrossLine,0,MODE_SMMA,j);
     now=buffer1[j];
     
    
     if(now>(last+(difference/1000)))
     {
       if(direction<1)
       {
        UpArrow[j]=buffer1[j];
        direction=1;
       } 
     }
       else  
         if(now<(last-(difference/1000)))
         {
           if(direction>-1)
           {
            DnArrow[j]=buffer1[j];
            direction=-1;
           }        
         } 
         
     last=buffer1[j];
   } 
  
  
   
  
  return(0);
}

I tried diffrentthigs, but I have a few problems I didn't find a solution:

1. I included an "iMAOnArry", but as far as I know I can't use arrays in EA's, so how can I do the average?

2. How can I make the EA check the last closed bar and not the current changing?



I hope somebody can help me!

Thanks!



leMai

 
It amazes me how people always want to reinvent the wheel. Just take the sample MACD EA and change the MACD calls to iCustom(...........1); to call your indicator. Setting "1" as the last parameter gives you the last closed bar.
Reason: