Function to write stats on Next 15 bars After arrow object

 

 I have an MQL4 function that plots an arrow object on a chart for backtesting purposes. I am working on another function that writes whether the next 15 bars after the object closed up or down and I am running into problems...  The up/down stats written to the file don't mesh with what I see on the chart and I don't understand why barshift isn't working at expected.

 My code is below.  Help? 

 

//Calc arrow objects function

void CalcArrows(){

   int    obj_total=ObjectsTotal();

   for(int h=0;h<obj_total;h++)

    {

    name= ObjectName(h);

    //find Object and set barshift entry time 15 minutes ahead

    entryTime=ObjectGet(name,OBJPROP_TIME1)+900;

    if(TimeCurrent()>=entryTime){

    int shift = iBarShift(Symbol(),0, entryTime);

   // write if candle closed up or down for 15 bars after arrow object

    string candle2=CandleUpDown(shift-14);

    string candle3=CandleUpDown(shift-13);

    string candle4=CandleUpDown(shift-12);

    string candle5=CandleUpDown(shift-11);

    string candle6=CandleUpDown(shift-10);

    string candle7=CandleUpDown(shift-9);

    string candle8=CandleUpDown(shift-8);

    string candle9=CandleUpDown(shift-7);

    string candle10=CandleUpDown(shift-6);

    string candle11=CandleUpDown(shift-5);

    string candle12=CandleUpDown(shift-4);

    string candle13=CandleUpDown(shift-3);

    string candle14=CandleUpDown(shift-2);

    string candle15=CandleUpDown(shift-1);

    string candle0=CandleUpDown(shift);

    }

    if(name!=lastname && StringLen(name)>5){

    int handle;

      handle = FileOpen("filename.csv",FILE_CSV|FILE_WRITE|FILE_READ,';');

      FileSeek(handle,0,SEEK_END);

      //Write whether each candle closed up or down

      FileWrite(handle,name,Symbol(), candle2, candle3, candle4, candle5, candle6, candle7, candle8, candle9, candle10, candle11, candle12, candle13, candle14 , candle15,candle0);

      FileClose(handle);

      lastname=name;

     }

    // delete arrow

    //ObjectDelete(name);

    }

}


string CandleUpDown(int barnum){

double openprice =iOpen(Symbol(),PERIOD_M1,barnum);

double closeprice =iClose(Symbol(),PERIOD_M1,barnum);

if(closeprice>openprice)return("up");

if(closeprice<openprice)return("down");

}

 
entryTime=ObjectGet(name,OBJPROP_TIME1+900);
:
int shift = iBarShift(Symbol(),0, entryTime);
entryTime=ObjectGet(name,OBJPROP_NO_SUCH_PROPERTY);
:
int shift = iBarShift(Symbol(),0, entryTime);
entryTime=0;
:
int shift = iBarShift(Symbol(),0, entryTime);
entryTime=0;
:
int shift = Bars - 1;
 
WHRoeder:

Thanks for the reply. 

 

I modified this: 

entryTime=ObjectGet(name,OBJPROP_TIME1+900);

 

To this and no difference:

 entryTime=ObjectGet(name,OBJPROP_TIME1)+900;

      OBJPROP_PRICE1 is a constant and part of object property. 

 

Regarding:  

int shift = Bars - 1

Bars is a count of all bars on the chart. So it wouldn't satisfy the need of getting the Next 15 bars from the plot of the given arrow object.

 
kenleyl: To this and no difference
entryTime=ObjectGet(name,OBJPROP_TIME1)+900;

  1. For large amounts of code, attach it
  2. Of course it made a difference. Now what is object 'name' Is it an object you created, something the tester created. Is is a horizontal line?
    Add some Print statements and find out.
  3. string candle15=CandleUpDown(shift-1);
    :
    string CandleUpDown(int barnum){
        double openprice =iOpen(Symbol(),PERIOD_M1,barnum);
    Shift is on the current chart. Then you use it (barnum) on the M1 chart. Fails is the current chart is NOT M1.
 

This not gonna be easy 

if(TimeCurrent() == entryTime)

datetime is actually an integer represents the amount of seconds elapse since 00:00 Jan 1, 1970. We probably won't have every second in every tick, so try this ...

if(TimeCurrent() >= entryTime)
 
phi.nuts:

This not gonna be easy 

datetime is actually an integer represents the amount of seconds elapse since 00:00 Jan 1, 1970. We probably won't have every second in every tick, so try this ...

 


Good eye. I've been testing with '>', I must have tweaked the code before I pasted it here.

 With:

 if(TimeCurrent() >= entryTime)

The result in the CSV file is:

down 2012.11.28 10:41:14 Strategy11;EURUSD;;;;;;;;;;;;;;; 

the candle states are not being captured correctly.

 

Does iBarShift return correctly ?

int shift = iBarShift(Symbol(),0, entryTime);

Print ("entry time ",TimeToStr (entryTime, TIME_DATE|TIME_SECONDS)," shift ",shift," err ",GetLastError());
 
kenleyl:


Good eye. I've been testing with '>', I must have tweaked the code before I pasted it here.

 With:

 if(TimeCurrent() >= entryTime)

The result in the CSV file is:

down 2012.11.28 10:41:14 Strategy11;EURUSD;;;;;;;;;;;;;;; 

the candle states are not being captured correctly.

 

TimeCurrent() is not >= entryTime  so all your strings = ""
Reason: