Need help creating a VERY simple EA

 
i have never created an EA before but i have a trade i do that happens every 30 minutes. i trade it on the gbpusd. when the current 30min candle breaches the previous candle by one pip, i enter to go for 5 pips. it can be a buy or a sell, dosnt matter. i have a few other very simple rules for this trade, so i need an EA that will make this trade for me. can anyone help me please!???
 
crazfoto:
i have never created an EA before but i have a trade i do that happens every 30 minutes. i trade it on the gbpusd. when the current 30min candle breaches the previous candle by one pip, i enter to go for 5 pips. it can be a buy or a sell, dosnt matter. i have a few other very simple rules for this trade, so i need an EA that will make this trade for me. can anyone help me please!???

i might be able to help on this if its not so complicated.

pls provide me more info

 
doshur:

i might be able to help on this if its not so complicated.

pls provide me more info

great. the only rules are:


enter when current candle breaches the high or low of the previous 30m candle by 1 pip (high to buy, low to sell)

only trade a candle that is 20 pips or larger. 

the stop is the low (or high) of the previous 30min candle once an order is activated

if there is no candle breach or order placed, then wait for the next 30min candle to form that is 20 pips or larger


i go for 5 pip profit. i am going to try a trailing stop on this trade this week see if i can pick up some more pips. but 5 pips every half hour aint bad.


Let me know. thanks again

 

enter when current candle breaches the high or low of the previous 30m candle by 1 pip (high to buy, low to sell)

Understood this point


only trade a candle that is 20 pips or larger.

You mean the previous candle's high - low give 20 or more pips?


the stop is the low (or high) of the previous 30min candle once an order is activated

Please explain more


if there is no candle breach or order placed, then wait for the next 30min candle to form that is 20 pips or larger

Please clarify point 2


:)


Regards

Doshur

 
doshur:

enter when current candle breaches the high or low of the previous 30m candle by 1 pip (high to buy, low to sell)

Understood this point


only trade a candle that is 20 pips or larger.

You mean the previous candle's high - low give 20 or more pips?


the stop is the low (or high) of the previous 30min candle once an order is activated

Please explain more


if there is no candle breach or order placed, then wait for the next 30min candle to form that is 20 pips or larger

Please clarify point 2


:)


Regards

Doshur

yes. the previous candle has to be 20 pips or larger to trade. that way we have decent size chanel.


the stop

example:

previous high is 1.7500 

previous low is 1.7480

buy order would be 1.7001 tp 1.7506 st is 1.7480

or the sell would be 1.7479 tp 1.7474 st is 1.7500



now, if we have our range and an order is never placed, ie the market never breaches high or low to activate an order. then the previous 30min range is deregarded and the new 30min candle (which would now become our previous range) will become the new numbers to trade.


example:


previous high is 1.7550

previous low is 1.7500

the new 30m candle stays in between our range and an order is never activated. 


we get a new 30m candle and the previous range is:

high 1.7540

low 1.7520


so this becomes our new range to trade in and the 1.7550 1.7500 range is disregarded


does that make sense? i trade this with pending orders when the new 30min candle starts. when one of the orders is actvated i delete the other order. so if the buy is activated i delete the pending sell and vise versa. if figure with a robot you dont have to have a pending order.

 

I'm clear now.

Will start to code these few days. Let me digest.

:)

 
doshur:

I'm clear now.

Will start to code these few days. Let me digest.

:)

awesome. thank you so much. its a fun little profitable trade. not many losses. i wonder if you could add something that will double the lots entered after a failed trade just for the next entery after a trade fails. it helps to keep the losses very low.


I will be trading it this week trying a trailing stop. i never did it before just always went for 5 pips.

 
crazfoto wrote >>

awesome. thank you so much. its a fun little profitable trade. not many losses. i wonder if you could add something that will double the lots entered after a failed trade just for the next entery after a trade fails. it helps to keep the losses very low.

I will be trading it this week trying a trailing stop. i never did it before just always went for 5 pips.

Interesting strategy. I wrote the follow code to implement. Code is heavily commented so you should be able to understand and modify it. Staregy didn't backtest to well though.

//+------------------------------------------------------------------+
//| 30Min Strategy.mq4 |
//| Copyright © 2008, Brendan Kelly |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, Brendan Kelly"
#property link ""
extern string Order_Comment = "30Min Strategy";
extern double Lots = 0.1;
extern int TakeProfit = 5;

static bool ReadyToTradeThisBar = false;
int MagicNumber = 9999;

int start()
{

if (NewBar()) // This is done at the begining of every new bar
{
CloseAllOpenOrders(); //first close any existing trades left over from previous bar
if(High[1] - Low[1]>= 20*Point) //if previous bar is at least 20 long
ReadyToTradeThisBar = true; //then we can trade this bar
else //else
ReadyToTradeThisBar = false; //we can't trade this bar
}

//This is done every tick
if (ReadyToTradeThisBar == true) //if we can trade this bar
{
if (OrdersTotal() < 1) // and if there is no trade currently running
{
if(Ask > High[1] + 1*Point) //and if current ask price is greater than previous bar's high plus 1
{ // then place a buy order
OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Low[1],Ask+ TakeProfit*Point,Order_Comment,MagicNumber,0,Blue);
ReadyToTradeThisBar = false; //prevent further trades until current trade is closed
}
if(Bid < Low[1] - 1*Point) //and if current ask price is less than previous bar's low minus 1
{ // then place a sell order
OrderSend(Symbol(),OP_SELL,Lots,Bid,3,High[1],Bid- TakeProfit*Point,Order_Comment,MagicNumber,0,Red);
ReadyToTradeThisBar = false; //prevent further trades until current trade is closed
}
}
}

return(0);
}//end


//##########################Support Functions ##########################################

// This function returns the value true if the current bar/candle was just formed
bool NewBar()
{
static datetime PreviousBar;
if(PreviousBar<Time[0])
{
PreviousBar = Time[0];
return(true);
}
else
{
return(false);
}
return(false); // in case if - else statement is not executed
}

//Close all open and pending orders
int CloseAllOpenOrders()
{
int OrderCount = OrdersTotal();
int index = 0;
int TicketNumber = 0;
for(index=OrderCount-1;index>-1;index--)
{
OrderSelect(index,SELECT_BY_POS,MODE_TRADES);
if (OrderMagicNumber()==MagicNumber)
{

TicketNumber = OrderTicket();
if(OrderType() == OP_BUY || OrderType() == OP_SELL )
{
OrderClose(TicketNumber,Lots,Bid,3,Red);
}
}
}
return(0);
}

Regards

Brendan

 
nice. would i be able to modify it to work on a 2hr candle also?
 
i see why this is not working. it is cancelling everyorder automatically every half hour in stead of letting the market stop it out or take profit. i see a lot of orders that would have paid out but the robot closed the order. if that can be changed i think the results will be better
 

Thanks brendan for the code.

I have yet to test the code but seems that if you activate the EA, will it execute an order immediately if all rules are met even if the current price is like 10pip above the previous bar already.

Reason: