Use the iClose() in EA, Why the result is OpenPrice?

Back to topics list To post a new topic, please log in or register
avatar
6
xin2014 2015.01.14 04:52
 


I want to print out the Close price and MA price (1 mintue) though the back testing.

Here is the code of the EA:

//##################################################################
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict


static datetime now;
double BufMAA=0;

int start()
{
if(now != Time[0])
   {
    now = Time[0];
    BufMAA=iMA(NULL,PERIOD_M1,4,0,MODE_SMA,PRICE_CLOSE,0);
    Print(Time[0],",",iClose(NULL,PERIOD_M1,0),",",BufMAA);
    }
return(0);
   
}
//##################################################################

The setting of Back Testing:

Symbol:USDJPY

Model: Every tick

UseDate: From 2013.01.01 To:20.13.01.31

Period:M1

Spread:10


I don't know why I used the iClose() in the EA, but the result in the log file is Open Price.

Hope can get your help.

Thanks a  lot. I have attached my EA for anyone to have a try.






Attached files:
  forasking_1.mq4  (0.54 KB)
avatar
2017
gooly 2015.01.14 10:02 #
 

1) if you post code please use the SRC button beside the camera!

2) you enter this loop:

if(now != Time[0])
   {
    now = Time[0];
...

only at the open of the new bar - so you get only the opens.


avatar
6
xin2014 2015.01.15 01:55 #
 
gooly:

1) if you post code please use the SRC button beside the camera!

2) you enter this loop:

only at the open of the new bar - so you get only the opens.


Thanks a lot for your answering.

Can you help me, if I want to get the close price, how to change the code?

Please・・・・

avatar
Moderator
3418
GumRai 2015.01.15 05:18 #
 
BufMAA=iMA(NULL,PERIOD_M1,4,0,MODE_SMA,PRICE_CLOSE,1);
    Print(Time[1],",",iClose(NULL,PERIOD_M1,1),",",BufMAA);
To print the previous bars close, change the index from 0 to 1
avatar
6
xin2014 2015.01.19 08:44 #
 
GumRai:
To print the previous bars close, change the index from 0 to 1

Thanks a lot! Really!!

Back to topics list  

To add comments, please log in or register