Forum:	MetaTrader 4 platform
Téma:	I code your strategy into an EA
---------------------------------------

newschool:
Simply post the entry and exit triggers, I will then make an EA with the source in MQ4 available.
I do this because you will be able to automate your method, and at the same time it shares the knowledge of traders, turning small ideas in great strategies.

Here is an example blueprint you need to follow===
conditions for BUY:
Bid &gt; Rsi20
AND Bid&gt;MA50 
close:
Bid = MA50
OR3 red candles in a row

PINKPANTHER5:
Can you make a Triggerline EA??
When the red and the green have crossed over we go log or short??

newschool:
Give me the link to the Triggerline indicator.

learning_fx:
NewSchool, 
Could you change the sema-version10dragon-eu.mq4 to use the daily Sema's? I would like to test with daily Sema's and larger stops. 
Thanks

farizu:
OK here is one, which has been really good on the 1hr time frame on most major pairs. Let me know if you can turn it into an ea?
The setup:
First:
4 EMA lines set to periods 10,20,30 and 40 
Second:
MACD set to the following settings:
Fast EMA: 5
Slow EMA: 31
MACD SMA: 1
Trading Strategy:
When all 4 EMA lines intertwine and MACD line rises from below 0 into the positive side, a BUY signal is triggered. 
When all 4 EMA lines intertwine and MACD line drops from above 0 into the negative side, a SELL signal is triggered.
Exit is a 30pip trailing sl.

newschool:
learning_fx,
I do not support anymore the Sema EA, but it very easy to change it to daily, just go in the source and change the PERIOD_H1 to PERIOD_D1. You can also change the Open price of the candles to something like M30 instead of M15.
farizu,
did something for your strategy, obviously the definiton of &quot;intertwine&quot; is a problem here so what I did is to substract each MAs and take the trade if the difference is below a maximum number of Pips. This version is not positive, but check the trades it takes and give me feedback.

farizu:
newschool wrote:learning_fx,
I do not support anymore the Sema EA, but it very easy to change it to daily, just go in the source and change the PERIOD_H1 to PERIOD_D1. You can also change the Open price of the candles to something like M30 instead of M15.
farizu,
did something for your strategy, obviously the definiton of &quot;intertwine&quot; is a problem here so what I did is to substract each MAs and take the trade if the difference is below a maximum number of Pips. This version is not positive, but check the trades it takes and give me feedback.

Many many thanks newschool, will forward test this baby and get back to you soon. 
There is another strategy that i am manual trading with very good success, I will try to set out the entry and exit criteria as succinctly as possible and post it here as soon as i can...

newschool:
Hey, I suggest you backward test first because like I said, I am not even sure the entries are exactly like you asked.

PINKPANTHER5:
newschool wrote:Simply post the entry and exit triggers, I will then make an EA with the source in MQ4 available.
I do this because you will be able to automate your method, and at the same time it shares the knowledge of traders, turning small ideas in great strategies.

Here is an example blueprint you need to follow===
conditions for BUY:
Bid &gt; Rsi20
AND Bid&gt;MA50 
close:
Bid = MA50
OR3 red candles in a row


Newchool

Here is the code for the triggerline. Can you set the trigger, when the crossover buy and sell occurs? And hopefully have the stop-loss and take profit to be a changeable option....

//+------------------------------------------------------------------+
//| Trigger Line |
//| Copyright ? 2005 dwt5 and adoleh2000 |
//|http://www.metaquotes.net |
//+------------------------------------------------------------------+
#propertycopyright &quot;Copyright ? 2005 dwt5 and adoleh2000 &quot;
#propertylink&quot;http://www.metaquotes.net/&quot;
//---- indicator settings
#propertyindicator_chart_window
#propertyindicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 Yellow
#property indicator_color3 HotPink
#property indicator_color4 Aqua
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
int width;
extern int Rperiod = 50;
extern int LSMA_Period = 50;
int Draw4HowLong;
int shift;
int i;
int j;
int loopbegin;
int length;
int lsma_length;
double lengthvar;
double tmp ;
double tmp2 ;
double wt[];
double sum[];
double lsma_sum[];
double lsma_ma[];
double middle[];
int c;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- 7 additional buffers are used for counting.
 IndicatorBuffers(7); 
 
//---- drawing settings
 
 SetIndexBuffer(0,ExtMapBuffer1);
 SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
 
 SetIndexBuffer(1,ExtMapBuffer2);
 SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);
 
 SetIndexBuffer(2,ExtMapBuffer3);
 SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,1);
 
 SetIndexBuffer(3,ExtMapBuffer4);
 SetIndexStyle(3,DRAW_LINE,STYLE_SOLID,1);
 
 
 
 SetIndexBuffer(4,sum);
 SetIndexBuffer(5,wt); 
 SetIndexBuffer(6,lsma_ma);
 
//---- initialization done
 return(0);
}
int start()
{ Draw4HowLong = Bars-Rperiod - 5;//Rperiod = 20
length = Rperiod; //length now = 20
lsma_length = LSMA_Period;
loopbegin = Draw4HowLong - length - 1; 

for(shift = loopbegin; shift &gt;= 0; shift--)//MAIN For Loop
{ 
 sum[1] = 0;
 for(i = length; i &gt;= 1; i--) //LSMA loop
 {
 lengthvar = length + 1; //lengthvar = 21
 lengthvar /= 3; //lengthvar = 7
 tmp = 0;
 tmp = ( i - lengthvar)*Close[length-i+shift]; //tmp = 20 - 7 * close[20-i+shift]
 sum[1]+=tmp;
 }
 wt[shift] = sum[1]*6/(length*(length+1));
 j = shift;
 lsma_ma[shift] = wt[j+1] + (wt[j]-wt[j+1])* 2/(lsma_length+1);

//========== COLOR CODING =========================================== 

ExtMapBuffer1[shift] = wt[shift]; 
ExtMapBuffer2[shift] = lsma_ma[shift]; 
ExtMapBuffer3[shift] = wt[shift]; 
ExtMapBuffer4[shift] = lsma_ma[shift]; 

if (wt[shift]&lt; lsma_ma[shift])
{
ExtMapBuffer4[shift] = EMPTY_VALUE;
ExtMapBuffer3[shift] = EMPTY_VALUE;
 }
}
}
//+------------------------------------------------------------------+

farizu:
Hi Newschool,
have been playing around with the ea and i think i have isolated why the ea is yet not as profitable as the manual system. If you look at the attached chart you will see that the ea is getting into the trades a little too late. 
Can this be rectified?
Also can you please change the ea so that it allows fractional lots to be traded?
Many thanks for a brilliant first attempt at automating this strategy.

brettnchris:
Hello I have a set up I use that uses two indicators.
1. 50 SMA Colored
2. CCI Alert

Buy Entry: Buy when 50 SMA is green and the CCI is over sold.
Sell Entry: Sell when 50 SMA is red and CCI is over bought.
Attached are the indicators that I am using the CCI is set up to alert when the criteria matches.
I think using a scale out method for exit is the best. This I am still working on.My thoughts are take half at an adjustable amount of pips and let half run to another pip target.
Stop would be percentage amount of account or an adjustable hard stop amount.
Please let me know if this can be done.Thank you....

trendme82:
its not as simple as enter exit strategy.
1. we need to set a signal condition, if signal condition is met, then it goes to step two. step two is another condition. If met then trade enters.
condition one: confirm market behavior
How? use several Moving averages, 5-50 (use about 6-7 different MA)
IF ALL MA averages are with a small Range, condition is met.
The purpose of this condition is to find a Consolidation.
Once consolidation is confirmed, then we can go to step two.
Condition Two:( we use fractual to draw trendline Object) Once Price breaks Trendline, then condition two is Met.
Enter Condition: Once (MA Group_ ma 5-50) all Decline/incline then Order is Entered. 
Exit strategy: We dont need one. We can use another EA to close our orders!!

trendme82:
I can be reached at 4xquestion@gmail.com for more explanation.
or Google talk at wschaarrand@gmail.com

trendme82:
IF we build this EA:
We need External parameters:
----------------------------------------------------------------
MA1- (we enter the value) Type (sma, ema) Open/close
MA2
MA3-
MA4-
 etc,so we can choose our own MA combination.
----------------------------------------------------------


Moving Average Decline/incline calculation:
[0] bar Current value &gt;or&lt; [1] bar close // this will tell us if its incline or decline
* this will need to be run on Each Moving average that is assigned in the Moving Average Group.

marblaa:
!!!!!.

newschool:
farizu,
you told me your strategy was H1, so I coded it that way hehe. What you posted is H1 entries on a M15 chart. To make it versatile, just go into the code and replace all the &quot;PERIOD_H1&quot; by &quot;0&quot;.
PINKPANTHER5,
I don't how you named your indicator so go into the EA code and change all the 4 &quot;Triggerline&quot; words to suit yours. Also, since this is a custom indicator, backtesting will be slow. So you need to go into the code of your indicator and replace the pink colored &quot;Bars&quot; to the number of past candles it will be using. For example &quot;300&quot;. That way it will only lookback to that number, instead of checking all your history.
As you can see trading with this indicator only will give you few false signals. Also to avoid repainting, I delayed the trigger by 1 candle.
brettnchris,
I did your EA but realized it will trigger whenever the SMA is green (in a long trade). Is that what you want , or your trigger is when it changes from another color to green? Also there is some repainting so you will probably need to delay by 1 candle.
trendme, 
the 2 conditions entry is still very easy to do. Basically I just use a logical AND. No problem for the different MAs too. The thing I don't understand is the &quot;fractual that draws the trendline Object&quot;. Is it an indicator?

trendme82:
(TRENDME) yeah the TWO trendlines are drawn by an Indicator;
Demark Trendlines..
The Demark TL finds the last two Fractals (Bill WIlliams Fractal) and connects the fractals with a line. 
Cost for Code? 
I can always add other features to the code later..

trendme82:
All the Moving averges must be a external parameter so Each trader can adjust accordingly. I use 244 MA and most traders use 200ma

farizu:
newschool wrote:farizu,
you told me your strategy was H1, so I coded it that way hehe. What you posted is H1 entries on a M15 chart. To make it versatile, just go into the code and replace all the &quot;PERIOD_H1&quot; by &quot;0&quot;.

Many thanks newschool, you are absolutely correct, my bad :oops: 
I am finding some encouraging results with this ea on gu, and i would be grateful if you would let me know how i should modify the code to allow for fractional trades. i.e. .01 lots for example. Right now I am unable to do so with the ea as it is currently configured.
Thanks again for your remarkable work...

newschool:
farizu,
in the first few lines of code, you see &quot;extern int Lots = 2;&quot;. That defines the Lots as a default integer of 2. To allow a fractional number, you change &quot;int&quot; for &quot;double&quot;.
trendme,
I searched for that indicator but I think there are many versions, you have to put it in a file attachment here.

farizu:
Hi newschool,
I have been visually backtesting the ea that you kindly coded for me, and it has thrown up this rather major problem having to do with multiple order entries when the price whipsaws around the intertwined emas. Have a look at the attached picture.
One way to prevent this would be to code a condition that if a contrary signal is issued whilst one trade is still live, the live trade should be closed before the new signal is taken. That way at any given time only one trade would be active.
So for example if a short trade has triggered and then the price reverses shortly thereafter with the criteria being met for a long trade to be taken, then before the long trade is taken, the ea must first close out the short trade.
Is it possible for you to make this change to the ea?

newschool:
Done with few modifications. Check first page. It is starting to look good indeed.

farizu:
Many thanks newschool for the modified ea...will play around with it and report back...
In the meantime, can you please tell me how can i turn off the hedging function when running the ea?

farizu:

Hi newschool, even with the new ea, i am still getting multiple orders...wondering why?
Have a look at the attached pic for more details

newschool:
Well hedging function will permit multiple orders... dont you check the inputs before running the EA ? Its all here..

farizu:
newschool wrote:Well hedging function will permit multiple orders... dont you check the inputs before running the EA ? Its all here..
The reason I asked is because the hedging input is a numerical value, and not a true or false input. So if I enter 0 next to hedging input, will it turn hedging off?
Also I am running into this error in back testing:

&quot;farizu_EA: stopped due test limit &quot;profit maximum=10000&quot; reached with inputs: Lots=1...&quot;
why has a profit maximum of $10000 been placed on the ea?
Many thanks for your ongoing help!

newschool:
-ohh small mistake, but you should be able to change it yourself in the code ;)
hint: double vs bool....
-turn the take profit to false...

farizu:
newschool wrote:-ohh small mistake, but you should be able to change it yourself in the code ;)
hint: double vs bool....
-turn the take profit to false...
Thanks for that, will make the change.
Sorry to be thick, but about turning the hedge off, will entering 0 in the inputs turn the hedge off?

newschool:
hmm first you need to make the small change I talked about
then yes, boolean inputs accept both true/false and 1/0
PS: you shouldnt do forex on a saturdays night ;)

farizu:
newschool wrote:hmm first you need to make the small change I talked about
then yes, boolean inputs accept both true/false and 1/0
PS: you shouldnt do forex on a saturdays night ;)

 :D well the only time i have to optimize this baby is on saturday nights!
Thanks again for your answers...this ea is looking pretty good on some of the back tests...
have you tried to optimise the settings at all?

farizu:
hey newschool, if you are still around and if you have a moment, would you please try to code this strategy into an ea:
5M Chart
any currency
this are the rules
Long Entry
1) RED CANDLE CLOSES
2) GREEN CANDLE CLOSES
3) PRICE TOUCHES HIGH OF PREVIOUS GREEN CANDLE - ENTER LONG
Short Entry
1) Green Candle closes
2) Red Candle Closes
3) Red Candle Touches lowest of previous red canlde - Enter SHORT
Exit will again be trailing sl, to be optimized by the pair or reverse signal, which ever comes first.
if possible, a filter can be added, which is to take long trades only when the cci is above 0 and only shorts when it is below, with the cci set to 333.

newschool:
Hmm is this the Rat?

txraddoc:
Hey newschool,
I am looking for an EA which trails open orders, places the first stop loss at X number of pips out of profit then moves stop loss closer to the current price in away such when the price moves Y number of pips, then the EA would move the stop loss X number of pips closer to the price. eg when a rpice drops 5 pips, lower the stop loss by 6 pips.Or any other combination.
As an example, I place a manual trade then the EA automatically sets my stop loss X number of pipis away from my transaction price.
As the price moves, I'd like the EA to move to stop loss closer by X number of pips toward the price.
So basically, the farther I am in profit, the tighter my stop loss.
Then the ea would lock in a final stop lose when it gets close to the price.Probably about twenty pips.But it would be nice to have a variable for that final stop loss number.
The only other variable I can think of is to set the lot sizes to bought or sold.

forexbob:
txraddoc wrote:Hey newschool,
I am looking for an EA which trails open orders, places the first stop loss at X number of pips out of profit then moves stop loss closer to the current price in away such when the price moves Y number of pips, then the EA would move the stop loss X number of pips closer to the price. eg when a rpice drops 5 pips, lower the stop loss by 6 pips.Or any other combination.
As an example, I place a manual trade then the EA automatically sets my stop loss X number of pipis away from my transaction price.
As the price moves, I'd like the EA to move to stop loss closer by X number of pips toward the price.
So basically, the farther I am in profit, the tighter my stop loss.
Then the ea would lock in a final stop lose when it gets close to the price.Probably about twenty pips.But it would be nice to have a variable for that final stop loss number.
The only other variable I can think of is to set the lot sizes to bought or sold.
have also a look at Multi-purpose trade management ea 
from steve hopwood .
http://www.forexfactory.com/showthread.php?t=89371
probably does not all you want , but goes far.
code is structured and easily adapted

txraddoc:
Fabulous.Thanks.I'll take a look.
Allen

utopianhorizon:
I have not had any luck converting a thinkscript code to mql4 and was hoping you may be able to help.The EA I would like to create looks like this in thinkscript.Perhaps you can decipher it and create an EA for it.
declare LONG_Entry
input length = 20;
input num_devs_dn=2;
input bollinger_price=close
input lower_band_price=close
def value = Average(bollinger_price, length) - num_devs_dn * stdev(bollinger_price), length);
def crosses_over = lower_band_price&gt;value and lower_band_price[1] &lt;= value[1];
def condition = crosses_over;
addOrder(condition, Max(open,value));

declare Short_Entry;
input length = 20
input num_devs_up=2
input bollinger_price=close
input upper_band_price=close
def value = Average(bollinger_prie, length) + num_devs_up * stdev(bollinger_price, length);
def crosses_under = upper_band_price &lt; value &amp;&amp; upper_band_price[1] &gt;= value[1];
def condition = crosses_under &amp;&amp; low &lt;=value;
addOrder (condition,Min(open,value));

newschool:
hehehe bollinger price b/o strategy... already done, tested, and put in the archives for no further use ;)

utopianhorizon:
Any chance of getting the code for what I posted earlier?I would be interested in testing it as well.Thanks for any help!

farizu:
Hey newschool,
Any chance of you kindly using this attached indicator to filter the trades triggerred by the multi ema ea that you coded for me some time back.
This additional indicator i think would filter out many of the unprofitable trades under my older criteria.
use of the attached indicator is selfexplanatory, down arrow for short and up arrow for long.
Many thanks!

jaxsterjoe:
newschool, I don't need an EA created, but an indicator.Could you create an indicator that shows a popup alert when the Awesome Oscillator crosses over the zero line and closes positive (green) and also when it crosses over the zero line and closes negative (red)? The sound of the alert I would like the indicator to use the sound I use for an alert in my Metatrader platform.Thank you.

MAX76:
newschool, can you write an ea for ProStation?
Thanks; Max.

pacinvest:
Hi Newschool
I am working on creating an EA based on nolagdot with some trade filters. Is it possible for you to code a simple EA if I supply the trade logic. I am having some problems with the trade coding. I am experienced as a trader but not so good with the programing stuff. 
I work with QQE a lot in manual trading and want to test combination with nonlagdot. Will of course be happy to share test results and versions with you or other member who could do some coding for this project. 
First version just needs to have 'length' as an adjustable variable and flexible symbol and timeframe and open and close orders on change of color of dot. 
I have attached the nolagdot indicator I want to use it is a simple version.
Thanks in Advance
Vince
