5 sec charts in mt4

 

Hi,

I heard that it is possible to make 5 sec bars in mt4 from tick online data.

Has anybody made this indicator that can make that?

Thx

 
nobody can helpt? pls
 

I did not respond previously because if you're looking to create a chart that you can watch, I cannot help. However, if you want to create pseudo 5 sec bars in your EA that should not be to difficult to accomplish.


What is it that you want? Chart? or, manufactured 5S data bars for the EA to react to?


Amended Post: If you want to run moving averages on the 5S data that can be done in the EA, but if you want to run other indicators on the 5S bars that is too complicated for me.

 
i would like to know how you can use "5sec bars" in an ea for calculation.
would be awesome, i am only looking pure price action ( high / lows) and so on. no indictators.

best regards
 
hi, not testet this, but generally it should work:
is inits a array with 200bars, 5sec each bar.
note: after init the array is not filled and not ready for use, you have to wait (200)*5 seconds before you can use the array. adjust 'count';
also you could look if the backwatch-period of your EA is smaller than (count-current).


int interval=5;
int count=200;
double high[count];
double low[count];
double open[count];
double close[count];
int seconds[count];
int current=count-1;

void update_values(){
  high[current]=MathMax(high[current],Ask);
  low[current]=MathMin(low[current],Ask);
  close[current]=Ask;
}

void init_values(){
  high[current]=Ask;
  low[current]=Ask;
  open[current]=Ask;
  close[current]=Ask;
  seconds[current]=TimeSeconds(TimeCurrent());
}




void start(){
/*
  i have not checked if the TimeSeconds(Timecurrent()) function does what it should ;)
*/
if( (TimeSeconds(Timecurrent())) > (seconds[count]+interval) )
{
  if(current==0){
     /*
      if array is already filled, we have to shift the array. stack would be cool
     */
     for(int tmp=count-1;tmp>0);tmp--){
        high[tmp]=high[tmp-1];
        low[tmp]=low[tmp-1];
        open[tmp]=open[tmp-1];
        close[tmp]=close[tmp-1];
        time[tmp]=time[tmp-1];
     }
  }else{
    current--;
  }

  init_values();
}else{
  update_values();
}

Array is filled as soon as current==0
and in my opinion ready to use for EA
 
thank you very much, however can you add some short explanations. i dont exactly get what you are doing :D

/edit: ah i see some now :D
 
wich part is not clear?
i dont if this works, was just my first idea.
 
yea its pretty hard. i dont get this line

for(int tmp=count-1;tmp>0);tmp--)
sorry i am more than a rookie to mt4 :D

i cant believe there is no real 5 sec tf... would be so easy to program my ea :/
 
hello,

     /*
      if array is already filled, we have to shift the array. stack would be cool
     */
     for(int tmp=count-1;tmp>0);tmp--){
        high[tmp]=high[tmp-1];
        low[tmp]=low[tmp-1];
        open[tmp]=open[tmp-1];
        close[tmp]=close[tmp-1];
        time[tmp]=time[tmp-1];
     }


/*
we have initialized  an array with 'count' members. (double high[count])
we can access to high's from high[0] (current bar) to high[count-1] (high[199]) wich is the farest we can watch back.
in the case above all members are filled allready. so no new bars can formed. 
we have to shift the array, so we can create the new bar in front. 
(high[0] is the new current high value). of course we are loosing the last value in the array. 
for this shift we go trough the whole array starting from tmp=(count-1)=199, to tmp>0;
*/
for(int tmp=count-1;tmp>0);tmp--)
//we shift the values   
high[tmp]=high[tmp-1];
 
thank you very much
 
now, this is how far i am now, however i dont really get the logic i think :D

would be cool if someone could look into it and point me in some way. thank you
//+------------------------------------------------------------------+
//| sem.mq4 |
//| Copyright © 2010, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"


extern int MaxOrders=1;
extern int Magic=2010;
extern bool Comments=true;
extern string Name_Expert = "ppa";
extern int Slippage = 30;
extern int msl=50;
extern double mtp=250;
extern double mlot=0.1;

color clOpenBuy = Khaki;
color clCloseBuy = Gold;
color clOpenSell = Gold;
color clCloseSell = Khaki;
color clModiBuy = Khaki;
color clModiSell = Gold;

int init()
{
return(0);
}

int deinit()
{
return(0);
}
//==========================================================================

int interval=5;
int count=200;
double high[count];
double low[count];
double open[count];
double close[count];
int seconds[count];
int current=count-1;


int start(){

if(Comments)
{
Comment("\nppa v.1 ",
"\n",
"\nLot: " + DoubleToStr(mlot,2),
"\nBalance: " + DoubleToStr(AccountBalance(),2);
}

if(AccountFreeMargin()<(1000*mlot)){
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}

// need to check for values right?


if (!ExistPositions()){

if ((CONDITION) && (CountOrders(OP_BUYSTOP,Magic)+CountOrders(OP_SELLSTOP,Magic))<MaxOrders){
OpenBuy();
return(0);
}

if ((CONDITION) && (CountOrders(OP_BUYSTOP,Magic)+CountOrders(OP_SELLSTOP,Magic))<MaxOrders){
OpenSell();
return(0);
}
}

return (0);
}

//==========================================================================

// Check if Positions Exist
bool ExistPositions() {
for (int i=10; i<OrdersTotal(); i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol()==Symbol()) {
return(True);
}
}
}
return(false);
}


// Count orders
int CountOrders(int Type,int Magic)
{
int _CountOrd;
_CountOrd=0;
for(int i=0;i<OrdersTotal();i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol())
{
if((OrderType()==Type&&(OrderMagicNumber()==Magic)||Magic==0))_CountOrd++;
}
}
return(_CountOrd);
}


// Opening Buy
void OpenBuy() {
double ldLot, ldStop, ldTake;
string lsComm;
int ticket;
ldLot = GetSizeLot();
if(msl>0){ldStop=Ask-msl*Point;}else {ldStop=0;}
//ldStop = 0;
ldTake = GetTakeProfitBuy();
lsComm = GetCommentForOrder();
ticket=OrderSend(Symbol
(),OP_BUY,ldLot,Ask,Slippage,ldStop,ldTake,lsComm,Magic,0,clOpenBuy);
if(ticket<0)
{
Print("OrderSend failed with error #",GetLastError());
return(0);
}
}


//opening Sell
void OpenSell() {
double ldLot, ldStop, ldTake;
string lsComm;
int ticket;
ldLot = GetSizeLot();
if(msl>0){ldStop=Bid+msl*Point;}else {ldStop=0;}
//ldStop = 0;
ldTake = GetTakeProfitSell();
lsComm = GetCommentForOrder();
ticket=OrderSend(Symbol
(),OP_SELL,ldLot,Bid,Slippage,ldStop,ldTake,lsComm,Magic,0,clOpenSell);
if(ticket<0)
{
Print("OrderSend failed with error #",GetLastError());
return(0);
}
}

// some functions
string GetCommentForOrder() { return(Name_Expert); }
double GetSizeLot() { return(mlot); }
double GetTakeProfitBuy() { return(Ask+mtp*Point); }
double GetTakeProfitSell() { return(Bid-mtp*Point); }




void update_values(){
high[current]=MathMax(high[current],Ask);
low[current]=MathMin(low[current],Ask);
close[current]=Ask;
}

void init_values(){
high[current]=Ask;
low[current]=Ask;
open[current]=Ask;
close[current]=Ask;
seconds[current]=TimeSeconds(TimeCurrent());
}

void check(){

if( (TimeSeconds(Timecurrent())) > (seconds[count]+interval) )

{
if(current==0){
/*
if array is already filled, we have to shift the array. stack would be cool
*/
for(int tmp=count-1;tmp>0);tmp--{
high[tmp]=high[tmp-1];
low[tmp]=low[tmp-1];
open[tmp]=open[tmp-1];
close[tmp]=close[tmp-1];
time[tmp]=time[tmp-1];

}
}else{
current--;
}
init_values();
}else{
update_values();
}

Files:
sem.mq4  5 kb
Reason: