8,400 pips in 12 months - need help coding EA

 

I have tested this strategy using historical data in Excel but need to create an EA as it works best on the 5 min chart (EURUSD). It averages 30 pips a day. It opens an order when the new bar opens (based on median price of previous bar) and closes when the current bar closes. In other words the order is open for only 5 minutes on the 5 minute chart and then a new order is executed. (Amounts to 288 orders a day).

Could someone please provide the code for the below pseudocode. Thanks heaps.

//Open order routine
//Find median price of bar immediatley before current bar
If current bar open price < previous bar median price
Open Buy Order (no target or stop loss)
Flag Order as Open
Else
Open Sell Order (no target or stop loss)
Flag Order as Open
End.

//Close order routine
If order is open and current bar is closed
Close order
Execute Open Order routine.
End.

 
Nah, it does not work. If you want a tool for Once-per-Bar why don't you just say so. :) Orders every 5-Minutes heck lol.
 

Alsey

Did a value for the spread make it into your spreadsheet?

-BB-

 
Alsey:

I have tested this strategy using historical data in Excel but need to create an EA as it works best on the 5 min chart (EURUSD). It averages 30 pips a day. It opens an order when the new bar opens (based on median price of previous bar) and closes when the current bar closes. In other words the order is open for only 5 minutes on the 5 minute chart and then a new order is executed. (Amounts to 288 orders a day).

Could someone please provide the code for the below pseudocode. Thanks heaps.

//Open order routine
//Find median price of bar immediatley before current bar
If current bar open price < previous bar median price
Open Buy Order (no target or stop loss)
Flag Order as Open
Else
Open Sell Order (no target or stop loss)
Flag Order as Open
End.

//Close order routine
If order is open and current bar is closed
Close order
Execute Open Order routine.
End.

I can help U. See private message
 
BarrowBoy:

Alsey

Did a value for the spread make it into your spreadsheet?

-BB-


Hi BarrowBoY

I didn't include the spread because it is deducted when the position is executed. The spreadsheet simply calculates the price movement - that is the difference between the Open and Close price.

 
ubzen:
Nah, it does not work. If you want a tool for Once-per-Bar why don't you just say so. :) Orders every 5-Minutes heck lol.


Hi Ubzen

Thanks for the reply, but this is a scalping strategy that actually works. I have tested it over 49 weeks and it produces an average of 31 pips per day, so it may not be so funny.

If you know of a once-per-bar EA could you please let me know and I will happily modify it for my purposes.

A

 
Alsey:


Hi Ubzen

Thanks for the reply, but this is a scalping strategy that actually works. I have tested it over 49 weeks and it produces an average of 31 pips per day, so it may not be so funny.

If you know of a once-per-bar EA could you please let me know and I will happily modify it for my purposes.

A


Sounds like a fairly simple EA. Have you tried using Heiken-ashi candles for this type of strategy?
 
Genma:

Sounds like a fairly simple EA. Have you tried using Heiken-ashi candles for this type of strategy?

No I'm unfamiliar with that one. I'll have a look at it.
 
Alsey, friend. I actually wrote your EA and back-tested it. And it dove like a sparrow. I was gonna post it for you but I felt that you were holding back and that was Not the real reason why you wanted such a tool. If it's really that important to you, I'll re-write it for you as now I've already deleted it.
 
ubzen:
Alsey, friend. I actually wrote your EA and back-tested it. And it dove like a sparrow. I was gonna post it for you but I felt that you were holding back and that was Not the real reason why you wanted such a tool. If it's really that important to you, I'll re-write it for you as now I've already deleted it.


Thanks Ubzen, I can't understand why it would fail as I've run it many times on a spreadsheet, checked and rechecked my code and I keep getting the same profit, around 31 pips per day. Does your code open an order in the opposite direction to the trend from the median of the previous 5 minute bar?. It relies on the price retracing over a few minutes - that's all. Yes I wouldn't mind having a look at the code, if it's at all possible, so that I can maybe play around with it. I can program, but it has been many years since I have programmed in C and a little assistance to get me going with the EAs would be greatly appreciated.

A.

 

Here, I've re-wrote it. I'm a newbie programmer/trader. So if someone else could validate the codes below, I'm sure you'll appreciate it. Now if you used to code in C, something that scares the %!#@ out of me then you must really be laughing your pants off by putting this poor newbie programmer/trader's hopes up. Here's what your one year spread-sheet system did to 50,000$ just last month alone.

 

 

And here's the code I wrote.

 

//+------------------------------------------------+
//|Alsey_M5.mq4
//|
//|
//+------------------------------------------------+
//+------------------------------------------------+
//----------Included & Import Files
//+------------------------------------------------+
//+------------------------------------------------+
//----------Global Variables
double Lots=0.1;
//+------------------------------------------------+
//+------------------------------------------------+
int start(){
//+------------------------------------------------+
//+------------------------------------------------+
//*Money Management
//+------------------------------------------------+
//+------------------------------------------------+
//----------Price Series
//----------Normalize Double Because 4-digit Broker
double Price_Buy=NormalizeDouble(Ask,Digits);
double Price_Sell=NormalizeDouble(Bid,Digits);
//+------------------------------------------------+
//+------------------------------------------------+
//----------Local Variables
static datetime Alsey_TimeStamp;
double Previous_Bar_High,Previous_Bar_Low,
Median_Price;
//+------------------------------------------------+
//+------------------------------------------------+
//+----------Median Price Calculaion
Previous_Bar_High=iHigh(NULL,0,1);
Previous_Bar_Low=iLow(NULL,0,1);
Median_Price=(Previous_Bar_High+Previous_Bar_Low)/2;
//+------------------------------------------------+
//+------------------------------------------------+
//----------Direction Algorithm
int Alsey_Direction;
//----------Buy Condition
if(Open[0]<Median_Price)
{Alsey_Direction=1;}
//----------Sell Condition
if(Open[0]>Median_Price)
{Alsey_Direction=-1;}
//+------------------------------------------------+
//+------------------------------------------------+
//----------OrderClose New_Bar
for(int i=(OrdersTotal()-1); i>=0; i--)
{
if(Alsey_TimeStamp!=Time[0])
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
{
      //+Close Buy
      if(OrderType()==OP_BUY)
      {
         OrderClose(OrderTicket(),OrderLots(),
         NormalizeDouble(Bid,Digits),4,Blue);
      }
   
      //+Close Sell
      if(OrderType()==OP_SELL)
      {
         OrderClose(OrderTicket(),OrderLots(),
         NormalizeDouble(Ask,Digits),4,Blue);
      }
}
}
//+------------------------------------------------+
//+------------------------------------------------+
//----------Placing Orders
if(OrdersTotal()<1)
if(Alsey_TimeStamp!=Time[0])
{
   //----------Buy Order
   if(Alsey_Direction==1)
   {
      OrderSend(Symbol(),OP_BUY,Lots,
      Price_Buy,4,
      0,
      0,
      "Alsey Long",1,0,Green);
      Alsey_TimeStamp=Time[0];
   }
   //----------Sell Order
   if(Alsey_Direction==-1)
   {
      OrderSend(Symbol(),OP_SELL,Lots,
      Price_Sell,4,
      0,
      0,
      "Alsey Short",1,0,Red);
      Alsey_TimeStamp=Time[0];
   }
}
//+------------------------------------------------+
//+------------------------------------------------+
return(0);}