Code Problems! - page 2

 
Timbo618:

Hi WHRoeder,

It is still just giving a flat line...Not to sure why.

Is it ? or does it just look like it is ? take a look at the buffer values using the Data Window (Ctrl + D) for a flatline the values will all be the same . . .
 

YYYEEEEEAAAAHHHHH!!!!!!

It is working GREAT.....Now I just need to get the BinSig = Previous value (either 1 or -1, instead of 0 at the end of the code).

Do I just make it BinSig[i+1]?

Have a quick look at the code again for me please.

Thank you again...YIPPEE...Brilliant!!! :)

Code below.

Tim

int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
///---- Close from Today
   for(int i=0; i<limit; i++)
      HOURCLOSE0[i]=iClose(Symbol(),PERIOD_H1,i);
//---- Close from Yesterday
   for(i=0; i<limit; i++)
      HOURCLOSE1[i]=iClose(Symbol(),PERIOD_H1,i);
//---- Close from 2 Days ago
   for(i=0; i<limit; i++)
      HOURCLOSE2[i]=iClose(Symbol(),PERIOD_H1,i);
//---- Binary Trend
   for(i=0; i<limit; i++)
if((HOURCLOSE1[i+1]>HOURCLOSE2[i+2])&&(HOURCLOSE0[i]>HOURCLOSE1[i+1]))
  {
   BinSig[i]=1;
  }
else        if((HOURCLOSE1[i+1]<HOURCLOSE2[i+2])&&(HOURCLOSE0[i]<HOURCLOSE1[i+1]))
  {
   BinSig[i]=-1;
  }
else        BinSig[i]=0;
//---- done
   return(0);
  }
 

Nope...I tried BinSig[i]=BinSig[i+1]; and leaves a dotted line. Not connected.

Bit Confused...lol

Thank you.

Tim.

 
   for(int i=0; i<limit; i++)
      HOURCLOSE0[i]=iClose(Symbol(),PERIOD_H1,i);
Bogus unless your chart is also H1. If you are on the M1 chart every 60 bars should be identical because your source isn't changing.
 
for(int i=0; i<limit; i++)
      HOURCLOSE0[i]=iClose(Symbol(),PERIOD_H1,i);
//---- Close from Yesterday
   for(i=0; i<limit; i++)
      HOURCLOSE1[i]=iClose(Symbol(),PERIOD_H1,i);
//---- Close from 2 Days ago
   for(i=0; i<limit; i++)
      HOURCLOSE2[i]=iClose(Symbol(),PERIOD_H1,i);

You are assigning exactly the same value to each array

 

Hi Guys,

Thank you very much again for everything...Great learning curve...

GumRai: I think I have fixed the assigning of values....Have a look at code below.

I'm still struggling with the code for "instead of 0, then the last value that wasn't a 0(i.e 1 or -1)"

I tried "BinSig[i+1]" but that just gave the previous value of BinSig, even if the previous value was a 0.

Very confused...Need help big time with that code.

And I have no idea how to make the "BinSig" change its look with different time frames, but still keep the PERIOD_H1 signals.

I'm almost there.....I can smell it...I just need a bit of help to cross the finish line....lol... :)

Thanks again guys and gals!

Cheers,

Tim.

//+------------------------------------------------------------------+
//|                                                       TimTry.mq4 |
//|                                                               Me |
//|                                                          Missing |
//+------------------------------------------------------------------+
#property copyright "Me"
#property link      "Missing"

#property indicator_separate_window
#property  indicator_buffers 2
#property  indicator_color2  Silver
#property indicator_minimum -2
#property indicator_maximum 2
#property  indicator_width2  1
//---- indicator buffers
double     HOURCLOSE0[];
double     BinSig[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
   SetIndexStyle(1,DRAW_LINE);
   SetIndexDrawBegin(1,BinSig);
   IndicatorDigits(Digits+1);
//---- indicator buffers mapping
   SetIndexBuffer(0,HOURCLOSE0);
   SetIndexBuffer(1,BinSig);
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("Binary Trend");
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Binary Close Trend                           |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
///---- Close from Today
   for(int i=0; i<limit; i++)
      HOURCLOSE0[i]=iClose(Symbol(),PERIOD_H1,i);
//---- Binary Trend
   for(i=0; i<limit; i++)
   {
if((HOURCLOSE0[i+1]>HOURCLOSE0[i+2])&&(HOURCLOSE0[i]>HOURCLOSE0[i+1]))
  {
   BinSig[i]=1;
  }
else        if((HOURCLOSE0[i+1]<HOURCLOSE0[i+2])&&(HOURCLOSE0[i]<HOURCLOSE0[i+1]))
  {
   BinSig[i]=-1;
  }
else        BinSig[i]=0;
}
//---- done
   return(0);
  }
//+------------------------------------------------------------------+
 
Timbo618:

Hi Guys,

Thank you very much again for everything...Great learning curve...

GumRai: I think I have fixed the assigning of values....Have a look at code below.

I'm still struggling with the code for "instead of 0, then the last value that wasn't a 0(i.e 1 or -1)"

I tried "BinSig[i+1]" but that just gave the previous value of BinSig, even if the previous value was a 0.

Look at this section of code and work through the first few values in the loop manually to see if the code works . . .

   for(int i = 0; i < limit; i++)
      HOURCLOSE0[i] = iClose(Symbol(),PERIOD_H1,i);
   
   //---- Binary Trend
   for(i=0; i<limit; i++)
      {
      if( (HOURCLOSE0[i+1] > HOURCLOSE0[i+2]) && (HOURCLOSE0[i] > HOURCLOSE0[i+1]) )
         {
         BinSig[i] = 1;
         }
      else  if( (HOURCLOSE0[i+1] < HOURCLOSE0[i+2]) && (HOURCLOSE0[i] < HOURCLOSE0[i+1]) )
         {
         BinSig[i] = -1;
         }
      else BinSig[i] = 0;
   }

. . . the first loop value is 0

HOURCLOSE[0] == Bid

HOURCLOSE[1], HOURCLOSE[2] have not been calculated yet . . .

the net loop value is 1

HOURCLOSE[1] == Close for H1 Bar 1

HOURCLOSE[2], HOURCLOSE[3] have not been calculated yet . . . .


etc. do you see the issue ?

Now do the same with this modified for loop . . .

   for(i = limit; i >= 0; i--)
 

Hi Raptor,

Not sure why it is just a flat line now....I think I have gone backwards in coding...lol

Cheers,

Tim.

int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
///---- Close from Today
   for(int i=0; i<limit; i++)
      HOURCLOSE0[i]=Bid;
      HOURCLOSEPAST1[i]=iClose(Symbol(),PERIOD_H1,i+1);
      HOURCLOSEPAST2[i]=iClose(Symbol(),PERIOD_H1,i+2);
//---- Binary Trend
   for(i=limit; i>=0; i--)
   {
if((HOURCLOSEPAST1[i]>HOURCLOSEPAST2[i])&&(HOURCLOSE0[i]>HOURCLOSEPAST1[i]))
  {
   BinSig[i]=1;
  }
else        if((HOURCLOSEPAST1[i]<HOURCLOSEPAST2[i])&&(HOURCLOSE0[i]<HOURCLOSEPAST1[i]))
  {
   BinSig[i]=-1;
  }
else        BinSig[i]=0;
}
//---- done
   return(0);
  }
//+------------------------------------------------------------------+
 
Timbo618:

Hi Raptor,

Not sure why it is just a flat line now....I think I have gone backwards in coding...lol

Do you understand why you need to make the change you have made ? please answer this Q.


If you do understand . . . why didnt you also change this loop ?

   for(int i=0; i<limit; i++)
      HOURCLOSE0[i]=Bid;

      HOURCLOSEPAST1[i]=iClose(Symbol(),PERIOD_H1,i+1);  //  this line is not within the loop
      HOURCLOSEPAST2[i]=iClose(Symbol(),PERIOD_H1,i+2);  //  this line is not within the loop


Why have you changed from using HOURCLOSE0 to using HOURCLOSE0, HOURCLOSE1 & HOURCLOSE2 ?

Reason: