help to find an EA

To add comments, please log in or register
kitchenfrenzy
20
kitchenfrenzy  

I hope its ok opening a post for this.


Can anyone point me in the direction of and EA that simply opens a buy position at the end of a bar if the bar finished high and a low position if the bar closed down?


The closest I got was the attached file - but it doesn't work?


Cheers
Files:
William Roeder
18337
William Roeder  
double C=iClose(NULL,NULL,0);
double O=iOpen(NULL,NULL,0);
At the start of a bar those to are equal, you want C=Close[1]; etc. Second you want to test value ONLY at the start of the next bar
int start() {
   static newBar.Time;
   if (Time[0] <= newBar.Time) return(0);
   newBar.Time = Time[0];   // Reset the static

   //...
ticket=OrderSend(Symbol(),OP_BUY,Lot,Ask,0,0,0,NULL,0,iTime( Symbol(), PERIOD_H4, 0 ) + 86400);
Expiration times are irreverent to non-pending orders (buy/sell)
kitchenfrenzy
20
kitchenfrenzy  

Hello and thanks you very much for the post. It must make you cringe seeing these scripts cobbled up from several EAs. I have made the changes ( which I think I understand.... ). When I compile it complains about

'newBar.Time' - unexpected token C:\Program Files\MetaTrader - Alpari UK\experts\2-pip-wonder.mq4 (42, 11)
'newBar.Time' - variable not defined C:\Program Files\MetaTrader - Alpari UK\experts\2-pip-wonder.mq4 (43, 19)


do I need to set 'newBAR.Time' as variable?


and does

double O=iOpen(NULL,NULL,1); mean the same as double C=iOpen[1] ??
 


Thanks again for your help.



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

//| expert start function |
//+------------------------------------------------------------------+

int start() {
static newBar.Time;
if (Time[0] <= newBar.Time) return(0);
newBar.Time = Time[0]; // Reset the static

{
int ticket;
int err;
int q=0;

double C=iClose(NULL,NULL,0);
double O=iOpen(NULL,NULL,1);

double SL=100;
double TP=20;

double Spread=MarketInfo(Symbol(),MODE_SPREAD)*Point;
double FreeDepo=NormalizeDouble(AccountBalance()-AccountMargin(),Digits2Round);
double Risk=NormalizeDouble((FreeDepo*PercentOfFreeDepo/100),Digits2Round);
double Lot=NormalizeDouble(Risk/(SL/0.0001)*0.1,Digits2Round);

//===================== Lets determine lot size and risk ===================================

if ( Lot < MinLot )
{
Lot=MinLot;
}
Comment( "\n","Acceptable risk is ",PercentOfFreeDepo, "% = ",Risk," of the free money ",FreeDepo," in lots = ",Lot);

//====================== checking for the orders opening

for( q=0;q<OrdersTotal();q++)
{


if (OrderSelect(q, SELECT_BY_POS, MODE_TRADES) && OrderSymbol()==Symbol())
{
// checking positions, if there are some opended orders, lets check them with the indicator
if (OrderType()==OP_BUYSTOP)
{
return(0);
}
if (OrderType()==OP_SELLSTOP)
{
return(0);
}
}
}

//======================= condition for ORDER BUY ===============================

if ( O > C )
{
// buy or sell, lot size, price,slippage,SL,TP,comment,magicno,expiration
ticket=OrderSend(Symbol(),OP_BUY,Lot,Ask,0,0,0,NULL,0,iTime( Symbol(), PERIOD_H4, 0 ) + 86400);
if (ticket==-1)
{
err=GetLastError();
Print("error(",err,")");
}
}

//================================ condition for ORDER SELL ====================

if ( O < C )
{
ticket=OrderSend(Symbol(),OP_SELL,Lot,Bid,0,0,0,NULL,0,iTime( Symbol(), PERIOD_H4, 0 ) + 86400);
if (ticket==-1)
{
err=GetLastError();
Print("error(",err,")");
}
}


}
//+------------------------------------------------------------------+
Joseph Bervell
376
Joseph Bervell  
//+------------------------------------------------------------------+

A few additions and changes here and there to get it to work and be profitable. Run on EURUSD 15 minute.

Files:
kitchenfrenzy
20
kitchenfrenzy  
Kengen:

A few additions and changes here and there to get it to work and be profitable. Run on EURUSD 15 minute.

kitchenfrenzy
20
kitchenfrenzy  

I can't believe you manged to get it to work and added a MACD.... As you might be able to tell my scripting involves butchering other EAs.. I just managed to get it to run - and found out how to change the spread in MT4 for backtesting - and it was still a straight line down to £0.


I have a question - is there a way of closing any open orders at the end of the candle ( before opening the new orders) ?


Thanks for taking an interest.


Cheers

To add comments, please log in or register