How to code? - page 223

 

...

I think (since I can not see your EA that writes the values to csv file) that you are missing one FileFlush(). In cases when you want to make changes in the file accessible by "others" immediately without closing the file (which implicitly uses flush ) you should always flush the changes to disk

regards

mladen

sunshineh:
Hi,

I am writing an EA which is working with CSV-Files.

For testing I put my CSV Files in the following folder:

/tester/files

Here is only a small part from my EA:

int handle = 0;

int Long = 0;

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

if (handle > 0)

{

Long= FileReadNumber(handle);

FileClose(handle);

}

Print("LongMarket = ", Long);

Print("Long handle = ", handle);

In my EA I read the CSV-Files and then I write some integers down.

Now when I do my test and read in the journal the "Print"-messages, I often get old integers which aren't writen in the CSV-Files anymore!!

For example:

First there is written 3 and my EA ist working and writes the 0 into the file,

I can only see the 3 in that CSV-File!!

When I clear that CSV-File and put a new CSV-File with 3 in that " /tester/files"-Folder, I can only read the 0 from the test before!!!! But I can't find, where the EA reads the 0!!!

I am going crazy!!!!!

I hope you can understand my question and give me a tipp!!
 

Someone can help me to add a warning features?

I would like to add an alarm function of this indicator, color alarm. I have tried for a long time, use the "if alarm", but never without success. Someone can help me? Thank you very much! ~ My English is not good so sorry.

#property indicator_chart_window

#property indicator_buffers 4

#property indicator_color1 ForestGreen

#property indicator_color2 Red

#property indicator_color3 Black

#property indicator_color4 Black

//---- input parameters

extern int FastClosePeriod=13;

extern int FastCloseShift=0;

extern int FastOpenPeriod=34;

extern int FastOpenShift=0;

extern int SlowClosePeriod=34;

extern int SlowCloseShift=0;

extern int SlowOpenPeriod=62;

extern int SlowOpenShift=0;

//---- indicator buffers

double ExtBlueBuffer[];

double ExtRedBuffer[];

double ExtDarkVioletBuffer[];

double ExtBlackBuffer[];

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

//---- line shifts when drawing

SetIndexShift(0,FastCloseShift);

SetIndexShift(1,FastOpenShift);

SetIndexShift(2,SlowCloseShift);

SetIndexShift(3,SlowOpenShift);

//---- first positions skipped when drawing

SetIndexDrawBegin(0,FastCloseShift+FastClosePeriod);

SetIndexDrawBegin(1,FastOpenShift+FastOpenPeriod);

SetIndexDrawBegin(2,SlowCloseShift+SlowClosePeriod);

SetIndexDrawBegin(3,SlowOpenShift+SlowOpenPeriod);

//---- 3 indicator buffers mapping

SetIndexBuffer(0,ExtBlueBuffer);

SetIndexBuffer(1,ExtRedBuffer);

SetIndexBuffer(2,ExtDarkVioletBuffer);

SetIndexBuffer(3,ExtBlackBuffer);

//---- drawing settings

SetIndexStyle(0,DRAW_HISTOGRAM,0,2);

SetIndexStyle(1,DRAW_HISTOGRAM,0,2);

SetIndexStyle(2,DRAW_NONE,0,2);

SetIndexStyle(3,DRAW_NONE,0,2);

//---- index labels

SetIndexLabel(0,"FastClose");

SetIndexLabel(1,"FastOpen");

SetIndexLabel(2,"SlowClose");

SetIndexLabel(3,"SlowOpen");

//---- initialization done

return(0);

}

//+------------------------------------------------------------------+

//| 9Squared Trader |

//+------------------------------------------------------------------+

int start()

{

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;

//---- main loop

for(int i=0; i<limit; i++)

{

//---- ma_shift set to 0 because SetIndexShift called abowe

ExtBlueBuffer=iMA(NULL,0,FastClosePeriod,0,MODE_EMA,PRICE_CLOSE,i);

ExtRedBuffer=iMA(NULL,0,FastOpenPeriod,0,MODE_EMA,PRICE_OPEN,i);

ExtDarkVioletBuffer=iMA(NULL,0,SlowClosePeriod,0,MODE_EMA,PRICE_OPEN,i);

ExtBlackBuffer=iMA(NULL,0,SlowOpenPeriod,0,MODE_EMA,PRICE_MEDIAN,i);

}

//---- done

return(0);

 
 
Files:
example.gif  12 kb
example.mq4  3 kb
 
wolfe:
Here You go. I made this real quick, and yes, it can be done.

Have a look at the attached example.mq4 for coding example.

Also included is a screen shot with comments, so you can see that the RSI values are being saved tick by tick in the array.

Hi wolfe,

Thank you veyr much for your timer and efforts. I will try this

regards,

MSV

 
 

Bollinger Band

Hi,

Can somebody help me on the Bollinger Band fomula (20period dev 2 on close) into Excel spreadsheet. Thank you in advance.

 

Hi guys !!

I need to open only "one buy and sell "order "per day" in my EA, please, how is the code to do this?

 
Apolofx:
Hi guys !! I need to open only "one buy and sell "order "per day" in my EA, please, how is the code to do this?

I believe you need to loop through all the closed orders and check each for its symbol and close time...take the one that matches Symbol() and has the latest close time. then add 24 hours and use that in a variable to test current time and open trade when it reaches last order + 24 hours

 

Or a simpler way to do it would be to just use the TimeDayOfYear function and check the last closed order with matching symbol and magic number. Just make sure it's not the same day of year as today.

Take a look in the help file for definition and use of TimeDayOfYear

Regards

Lux