Help: How to write simple EA to buy and sell at a specific time? - page 5

 
Bongo:
omellette,

This is forward test.

You can not back test multiple pairs, for this moment.

Maybe MT4 will allow you to do in the future.

Print screen is from former Refco (FXCM) trading platform.

Bongo

Oh, ok. It must be a pretty old forward test, as all the dates say 2004...

As for Metaquotes implementing multiple-pair backtests (ever!) - not a chance! I'll make it to the moon under my own steam before that happens... :D

 
omelette:
Oh, ok. It must be a pretty old forward test, as all the dates say 2004... As for Metaquotes implementing multiple-pair backtests (ever!) - not a chance! I'll make it to the moon under my own steam before that happens... :D

omelette,

we are many, many years in this business...

b.

 
Try this EA!

Thanks Bongo! Any pointers since you be doing this for a while?

 
Bongo:
Try this EA!

Haven't studied code to find out how it ticks yet, just ran a quick back test on only 1 month with 90% quality and no mismatched chart errors. Lot size set to 0.1, everything else set to default. Yikes!

Any good settings for this?

Files:
 

Wolfe,

Can you modify the code of grid EA if I post it here? I doesn't place buy limits.

Thanks,

Lcfx

 
lcfxtrader:
Wolfe,

Can you modify the code of grid EA if I post it here? I doesn't place buy limits.

Thanks,

Lcfx

If you're talking about GridMaster_03 I downloaded it from post#20. I haven't really looked at the code yet, been coding another project.

 

I found this one on FF.

extern string GridName = "Grid"; // identifies the grid. allows for several co-existing grids

extern double Lots = 0.1; // Lot sizing

extern double GridSize = 10; // pips between orders - grid or mesh size

extern double GridSteps = 10; // total number of orders to place

extern double TakeProfit = 0; // number of ticks to take profit. normally is = grid size but u can override

extern double StopLoss = 0; // if u want to add a stop loss. normal grids dont use stop losses

extern double UpdateInterval = 15; // update orders every x minutes

extern bool wantLongs = true; // do we want long positions

extern bool wantShorts = true; // do we want short positions

extern bool wantBreakout = true; // do we want longs above price, shorts below price

extern bool wantCounter = false; // do we want longs below price, shorts above price

extern double LastUpdate = 0; // counter used to note time of last update

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

//| expert initialization function |

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

int init()

{

//----

#property show_inputs // shows the parameters

if ( TakeProfit <= 0 ) //

{ TakeProfit = GridSize; }

//----

return(0);

}

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

//| tests if there is an open position or order in the region of atRate |

//| will check for longs if checkLongs is true, else will check |

//| for shorts |

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

bool IsPosition(double atRate, double inRange, bool checkLongs )

{

int totalorders = OrdersTotal();

for(int j=0;j<totalorders;j++) // scan all orders and positions...

{

OrderSelect(j, SELECT_BY_POS);

if ( OrderSymbol()==Symbol() && OrderComment() == GridName ) // only look if mygrid and symbol...

{ int type = OrderType();

if (MathAbs( OrderOpenPrice() - atRate) < inRange) // dont look for exact price but price proximity (less than gridsize)

{ if ( ( checkLongs && ( type == OP_BUY || type == OP_BUYLIMIT || type == OP_BUYSTOP ) ) || (!checkLongs && ( type == OP_SELL || type == OP_SELLLIMIT || type == OP_SELLSTOP ) ) )

{ return(true); }

}

}

}

return(false);

}

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

//| script program start function |

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

int start()

{

//----

int i, j,k, ticket, entermode, totalorders;

bool doit;

double point, startrate, traderate;

//----

if (MathAbs(CurTime()-LastUpdate)> UpdateInterval*60) // we update the first time it is called and every UpdateInterval minutes

{

LastUpdate = CurTime();

Print("Updating");

point = MarketInfo(Symbol(),MODE_POINT);

startrate = ( Ask + point*GridSize/2 ) / point / GridSize; // round to a number of ticks divisible by GridSize

k = startrate ;

k = k * GridSize ;

startrate = k * point - GridSize*GridSteps/2*point ; // calculate the lowest entry point

double EMA34=iMA(NULL,0,34,0,MODE_EMA,PRICE_CLOSE,0);

for( i=0;i<GridSteps;i++)

{

traderate = startrate + i*point*GridSize;

{

if (!IsPosition(traderate,point*GridSize,true) ) // test if i have no open orders close to my price: if so, put one on

{

double myStopLoss = 0;

if ( StopLoss > 0 )

{ myStopLoss = traderate-point*StopLoss ; }

if ( traderate > Ask )

{ entermode = OP_BUYSTOP; }

else

{ entermode = OP_BUYLIMIT ; }

if ( (traderate > Ask ) && (wantBreakout) || ((traderate < Ask ) && (wantCounter)) )

{ ticket=OrderSend(Symbol(),entermode,Lots,traderate,0,myStopLoss,traderate+point*TakeProfit,GridName,16384,0,Green); }

}

}

{

if (!IsPosition(traderate,point*GridSize,false) ) // test if i have no open orders close to my price: if so, put one on

{

myStopLoss = 0;

if ( StopLoss > 0 )

{ myStopLoss = traderate+point*StopLoss ; }

if ( traderate > Bid )

{ entermode = OP_SELLLIMIT; }

else

{ entermode = OP_SELLSTOP ; }

if ( (traderate Bid ) && (wantCounter)) )

{ ticket=OrderSend(Symbol(),entermode,Lots,traderate,0,myStopLoss,traderate-point*TakeProfit,GridName,16384,0,Red); }

}

}

}

}

return(0);

}

 

Timebased EA

There seems to be a problem with this EA where the magic number setting does not work. I have it trading over mutipal pairs with different magic numbers but only one trade is taken on one pair. Can someone help..?

 
wolfe:
Haven't studied code to find out how it ticks yet, just ran a quick back test on only 1 month with 90% quality and no mismatched chart errors. Lot size set to 0.1, everything else set to default. Yikes! Any good settings for this?

Neither have I bothered looking at the code, but if this EA does use correllation, then (reliable) backtesting should not even be possible...

 
omelette:
Neither have I bothered looking at the code, but if this EA does use correllation, then (reliable) backtesting should not even be possible...

The GridMaster EA is from the AutoFx forum and does not use any correlation whatsoever - I do not know why Bongo posted it.

The GridMaster EA is basically a Grid EA, as the name suggests....I would seriously advise anybody who is considering using this EA live to test in with demo accounts first.

Reason: