ICustom Question - page 2

 
Yellowbeard:
So how do I get the value of, like say, ZigzagBuffer[], which is set at index 0, when it's value is determined within a series of loops within the code and based on a variety of conditions. Then is reset to 0. I can assign it's value to a variable ( ZigzagBuff = ZigzagBuffer; ) to bring the value out of the loop. Insert an Alert outside the series of loops ( Alert("OUT ZigzagBuffer = ",DoubleToStr(ZigzagBuff,Digits)); ) and presto I have my value. But, try and call the value of ZigzagBuffer with ( double Zigzag = iCustom(NULL,0,"ZigZag",0,0); //---- ZigzagBuffer[] ) and I get 0.000000. The only other option that I could try is to write the value to a file, when it occurs, within the indicator and the read it into my EA. Not sure if this would be the most practical way to solve this.

Why don't you simply assign values to buffer elements at the end of the loop in start"

And then retrieve whichever element you want using iCustom()

 

Do you mean, like this?

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

{

switch(whatlookfor)

{

case 0: // look for peak or lawn

if(lastlow==0.0 && lasthigh==0.0)

{

if(HighBuffer!=0.0)

{

lasthigh=High;

lasthighpos=i;

whatlookfor=-1; whatlookforBuffer[0] = whatlookfor;

ZigzagBuffer=lasthigh;; ZigzagBuff = ZigzagBuffer; // Here is where the value of ZigzagBuffer is, based on condition.

}

if(LowBuffer!=0.0)

{

lastlow=Low;

lastlowpos=i;

whatlookfor=1; whatlookforBuffer[0] = whatlookfor;

ZigzagBuffer=lastlow;; ZigzagBuff = ZigzagBuffer; // Here is where the value of ZigzagBuffer is, based on condition.

.

}

}

break;

case 1: // look for peak

if(LowBuffer!=0.0 && LowBuffer<lastlow && HighBuffer==0.0)

{

ZigzagBuffer[lastlowpos]=0.0;

lastlowpos=i;

lastlow=LowBuffer; // LowBuffer = lastlow;

ZigzagBuffer=lastlow;; ZigzagBuff = ZigzagBuffer; // Here is where the value of ZigzagBuffer is, based on condition.

.

}

if(HighBuffer!=0.0 && LowBuffer==0.0)

{

lasthigh=HighBuffer;// HighBuffer = lasthigh;

lasthighpos=i;

ZigzagBuffer=lasthigh;; ZigzagBuff = ZigzagBuffer; // Here is where the value of ZigzagBuffer is, based on condition.

.

whatlookfor=-1; whatlookforBuffer[0] = whatlookfor;

}

break;

case -1: // look for lawn

if(HighBuffer!=0.0 && HighBuffer>lasthigh && LowBuffer==0.0)

{

ZigzagBuffer[lasthighpos]=0.0;

lasthighpos=i;

lasthigh=HighBuffer;// HighBuffer = lasthigh;

ZigzagBuffer=lasthigh; ZigzagBuff = ZigzagBuffer; // Here is where the value of ZigzagBuffer is, based on condition.

.

}

if(LowBuffer!=0.0 && HighBuffer==0.0)

{

lastlow=LowBuffer;// LowBuffer = lastlow;

lastlowpos=i;

ZigzagBuffer=lastlow; ; ZigzagBuff = ZigzagBuffer; // Here is where the value of ZigzagBuffer is, based on condition.

.

whatlookfor=1; whatlookforBuffer[0] = whatlookfor;

}

break;

}

Outside this point, values will be 0.00000.

Thanks! For you help.

 

All zig zag based indicators use lowest low and highest high values of bars

I do not know which indicator, you are trying to use with icustom propertie, but you should not use icustom formula with zero as shift assignment

and all zig zag indicators calculate zig zag levels 2 or more bars later again and it sometimes change their dots

if someone which called no-repaint zig zag indicator it count 3-4 bars later zigzag levels

so it is not logic to use zig zag indicators in your trade

 

Your right, Zig Zag is not an ideal indicator. It plots highest high till lowest low, and vise versa. By the time it draws a line between the two points, to show trend, the trend has past. I'm interested in it's feature of continuously looking for higher high and lower low as well as direction. ( -1 for high, 1 for low ) Would like to bring it's values into my EA to test their usefulness.

Thanks!

 

O.k. Tried to bring the value of ZigzagBuffer in my EA by writing the value to a file, in the indicator and then reading it from the file, into my EA. Was able to write to file, but when trying to read, I get error code 5004. Below is the code I used.

// ----------------------------------------------------------------------------- FileWrite ZigzagBuff ----------------

{

ZigzagBuffI=FileOpen("ZigzagBuff", FILE_CSV|FILE_WRITE, ';');

if(ZigzagBuffI>0)

{FileWrite(ZigzagBuffI, ZigzagBuff);

FileClose(ZigzagBuffI);}

}

// -------------------------------------------------------------------------------------------------------------

// ----------------------------------------------------------------------------- File ZigzagBuff Read ----------------

double ZigzagO;

double ZigzagV;

ZigzagO=FileOpen("ZigzagBuff"+" .txt",FILE_CSV|FILE_READ,';');

if(ZigzagO>0)

{ZigzagV = FileReadNumber(ZigzagO);

FileClose(ZigzagO);

Zigzag = ZigzagV;}

if(ZigzagO<1)

{Alert("ZigzagBuff error is: ",GetLastError());}

 
Yellowbeard:
O.k. Tried to bring the value of ZigzagBuffer in my EA by writing the value to a file, in the indicator and then reading it from the file, into my EA. Was able to write to file, but when trying to read, I get error code 5004. Below is the code I used.

// ----------------------------------------------------------------------------- FileWrite ZigzagBuff ----------------

{

ZigzagBuffI=FileOpen("ZigzagBuff", FILE_CSV|FILE_WRITE, ';');

if(ZigzagBuffI>0)

{FileWrite(ZigzagBuffI, ZigzagBuff);

FileClose(ZigzagBuffI);}

}

// -------------------------------------------------------------------------------------------------------------

// ----------------------------------------------------------------------------- File ZigzagBuff Read ----------------

double ZigzagO;

double ZigzagV;

ZigzagO=FileOpen("ZigzagBuff"+" .txt",FILE_CSV|FILE_READ,';');

if(ZigzagO>0)

{ZigzagV = FileReadNumber(ZigzagO);

FileClose(ZigzagO);

Zigzag = ZigzagV;}

if(ZigzagO<1)

{Alert("ZigzagBuff error is: ",GetLastError());}

Error 5004 means that it can not open the file. If the file exists, try using share modes to work with file (FILE_SHARE_READ and FILE_SHARE_WRITE)

 

Still have error. Tried int file_handle=FileOpen(InpDirectoryName+"//"+InpFileName,FILE_READ|FILE_WRITE|FILE_CSV); Now, no error and no value.

 
Yellowbeard:
Still have error. Tried int file_handle=FileOpen(InpDirectoryName+"//"+InpFileName,FILE_READ|FILE_WRITE|FILE_CSV); Now, no error and no value.

Try to simplyfy

Remove folder name (use only file name without sub-folder). Write any value and check if it is written (with some external editor). If nothing is there your error us in the writing part. If the value is there , then check the reading part

 
assassin:
All zig zag based indicators use lowest low and highest high values of bars

I do not know which indicator, you are trying to use with icustom propertie, but you should not use icustom formula with zero as shift assignment

and all zig zag indicators calculate zig zag levels 2 or more bars later again and it sometimes change their dots

if someone which called no-repaint zig zag indicator it count 3-4 bars later zigzag levels

so it is not logic to use zig zag indicators in your trade
Yellowbeard:
Your right, Zig Zag is not an ideal indicator. It plots highest high till lowest low, and vise versa. By the time it draws a line between the two points, to show trend, the trend has past. I'm interested in it's feature of continuously looking for higher high and lower low as well as direction. ( -1 for high, 1 for low ) Would like to bring it's values into my EA to test their usefulness. Thanks!

Yellowbeard,

I tried to explain how can you call (bring) it's value into your EA to test or whatever you want to do with their useful or usefulness

(*) it is in the highlighted part of my quote, I never tried before but it should be so because of zigzag indicator's logic, try it please like this

iCustom(NULL,0,"ZigZag",0,1);

use 1 instead of zero as shift value at yhe end of the icustom function

 

File was there originally with value ( C:\Program Files (x86)\MetaTrader 4\MQL4\Files ). Now there is two files, now. One is a .txt file that is empty, the other is in another format, ( not sure which, Windows properties doesn't show what type of file with this ) though I can open it with notepad. It contains two values: 0.91802 and 000000001. 0.91802 is the value I'm looking for. Not sure what the other value is. Thanks!

Reason: