Forex
Google
New signals service!

Go Back   Forex Trading > Trading systems > Martingale/Average Cost and Hedging


Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

Reply
 
LinkBack (20) Thread Tools Display Modes
  14 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 01-10-2008, 11:48 PM
wolfe's Avatar
Senior Member
 
Join Date: Jan 2006
Posts: 704
wolfe is on a distinguished road
Martingale EA

A few days ago I received a PM to code an EA with the following parameters:

-User decides initial trade direction (let's say long) and starting lot size (say .1 lot)
-New position would be added every time the market moves x pips (say 10 pips) up or down away from the most recent position taken. If market moves up from the original position 10 pips a new long is added. If the market moves down 10 pips from the last position a short is added (basically following the market looking to catch a trend in either direction).
-Each new position size increased by x (ex: .1 lot)
-Take profit based on account %
-Stop loss based on account %
-Max number of standard lots before EA can't taken any new positions (at this point the T/P or S/L will need to be hit when max is reached)
-Re-enter mode would start a new progression again once the prior progression has ended do to T/P or S/L being hit
-Magic number to run on multiple pairs

I did my best to code such an EA.

PLEASE read ALL the comments in the code to understand the external variables. Default settings are just a guess, testing and optimization needs to be performed.

I'm not sure if this strategy is viable, these type of experts can get you into trouble quick! So use for testing only!

Edit:If you are new to this thread, the latest version is posted below. This is the eighth version I have made as a result to this thread. Please read thread thoroughly to fully understand this EA.

Enjoy.

Explanation of external variables:
PHP Code:
extern double  Start_Lot_Size=0.1;//starting lot size for cycle
extern double  Lot_Size_Increment=0.1;//Additional orders will increase by this amount
extern bool    Long_Short_Balance=false;//will balance long and short order lots + add Balance_Weight if trend changes
extern double  Balance_Weight=0.1;//amount over balanced long and short lot sizes you want to increase by with the trend
extern bool    Double_Lotsize=false;//set to true if you want to just double every lotsize, Lot_Size_Increment ignored if true, will not work with weighted balance set to true
extern bool    Choose_Own_Progression=false;//select true if you want te enter your own progression lot sizes below
extern double  Trade_1=0;//Enter in your own trade progression lot sizes
extern double  Trade_2=0;
extern double  Trade_3=0;
extern double  Trade_4=0;
extern double  Trade_5=0;
extern double  Trade_6=0;
extern double  Trade_7=0;
extern double  Trade_8=0;
extern double  Trade_9=0;
extern double  Trade_10=0;
extern double  Trade_11=0;
extern double  Trade_12=0;
extern double  Trade_13=0;
extern double  Trade_14=0;
extern double  Trade_15=0;
extern double  Trade_16=0;
extern double  Trade_17=0;
extern double  Trade_18=0;
extern double  Trade_19=0;
extern double  Trade_20=0;
extern int     Max_Trades=20;//maximum number of trades allowed
extern bool    Close_All_Max=false;//select true if you want ALL orders to close if Max_Trades is hit 
extern bool    Pyramid=true;//if true trades with trend, if false trades against trend
extern bool    Auto_Restart=true;//set to true if you want EA to re-start after each cycle
extern bool    Use_MA_Entry=false;//select true if you want moving average to decide starting direction
extern int     Next_Trade=20;//next trade pip increment if Use_MA_Entry =true  (will trade this many pips above OR below last order)
extern int     MA_Period=7;//moving average period for calculation
extern int     MA_Timeframe=60;//timeframe used for MA calculation, 1m=1, 5m=5, 15m=15, 30m=30, 1hr=60, 4hr=240, 1d=1440
extern bool    Use_Kayvan_Method=true;//select to use kayvan's method
extern int     Bar_Timeframe=60;//Bar Timeframe used to look back on, 1m=1, 5m=5, 15m=15, 30m=30, 1hr=60, 4hr=240, 1d=1440
extern int     Bars_Look_Back=1;//number of bars looked back at from current bar for high and low
extern int     EntryLag_Long=0;//number of pips above high to enter trade(ADD YOUR OWN SPREAD)
extern int     EntryLag_Short=0;//number of pips below low to enter trade(ADD YOUR OWN SPREAD)
extern bool    Last_Entry_Filter=false;//if true next high must be greater than last high, next low less than last low
extern bool    Use_Trailing_Stop=true;//select true to use a trailing stop based on total $amount
extern double  Trail_Start=10;//TS will start after this $Profit amount is reached
extern double  TSLoss_Percent=50;//%Percentage of your HIGHEST profit you can lose before close all is performed   
extern bool    Close_By_Percent=false;//If true it will close by percent, if false it will close by Profit or Loss in $$
extern double  TP_Percent=5;//will take profit if profit is greater than percent of account balance (close all orders)
extern double  SL_Percent=10;//will stop loss if profit is less than percent of account balance (close all orders)
extern double  Close_By_Profit=5;//close if >= to this $ amount
extern double  Close_By_StopLoss=99999;//Amount of money to close all if lost
extern int     Slippage=5;//slippage for ordersend command
extern int     Number_Of_Tries=5;//Number of tries to send an OrderSend()command if not going through
extern bool    Sound=true;//if true a sound will be played when an order goes through, and when a close all is performed 
THIS IS STILL A WORK IN PROGRESS, STILL WORKING OUT ALL THE BUGS!

Latest version (v1_8) is posted below.

*This is a re-post of v1_8* Re-install from previous version. Newest posted 3/2/08
Attached Files
File Type: mq4 TFX v1_8.mq4 (62.3 KB, 970 views)

Last edited by wolfe; 03-02-2008 at 07:49 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-11-2008, 12:03 AM
Senior Member
 
Join Date: Sep 2005
Posts: 255
aelimian is on a distinguished road
Working of EA

Please explain a little more. if one uses the e.g above.

long at 227.00 1 lot
price goes up to 227.10, enter 2 lots
then price up to 227.20 enter 3 lots
if price were to retrace from 227.20 to 227.10 would you enter
4 lots shorts or 1 lot short?

thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-11-2008, 12:10 AM
wolfe's Avatar
Senior Member
 
Join Date: Jan 2006
Posts: 704
wolfe is on a distinguished road
Quote:
Originally Posted by aelimian View Post
Please explain a little more. if one uses the e.g above.

long at 227.00 1 lot
price goes up to 227.10, enter 2 lots
then price up to 227.20 enter 3 lots
if price were to retrace from 227.20 to 227.10 would you enter
4 lots shorts or 1 lot short?

thanks
You would enter 4 lots short. You should probably start with 0.1 lots or 0.01 lots. This could increase in a hurry.

I just tried to code this EA the way it was requested.

Do you have a better idea?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-11-2008, 01:03 AM
niaga's Avatar
Junior Member
 
Join Date: Jan 2007
Location: World of Forex
Posts: 21
niaga is on a distinguished road
Quote:
Originally Posted by wolfe View Post
You would enter 4 lots short. You should probably start with 0.1 lots or 0.01 lots. This could increase in a hurry.

I just tried to code this EA the way it was requested.

Do you have a better idea?
Hello Wolfe,

Nice to see u

I'm like an EAs that base on martingale concept...

Before this i'm using 10points3. it ok but must carefully use it.

I wanna to use something new from 10points3 and wanna to modify it.
I'm trying to get somebody that can help me.

Can u help me to????


Please see this link http://www.forex-tsd.com/177073-post3231.html

Your help wanna to say a lot of thank.

TQ
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 01-11-2008, 01:16 AM
ElectricSavant's Avatar
Senior Member
 
Join Date: Jun 2007
Posts: 2,827
ElectricSavant is on a distinguished road
Hello Wolf...this is very similar to the BlackBird EA...I noticed you have not added the reenter mode yet...but I understand this is a work in progress..The open architecture that you use makes this very versatile...

ES


Quote:
Originally Posted by wolfe View Post
A few days ago I received a PM to code an EA with the following parameters:

-User decides initial trade direction (let's say long) and starting lot size (say .1 lot)
-New position would be added every time the market moves x pips (say 10 pips) up or down away from the most recent position taken. If market moves up from the original position 10 pips a new long is added. If the market moves down 10 pips from the last position a short is added (basically following the market looking to catch a trend in either direction).
-Each new position size increased by x (ex: .1 lot)
-Take profit based on account %
-Stop loss based on account %
-Max number of standard lots before EA can't taken any new positions (at this point the T/P or S/L will need to be hit when max is reached)
-Re-enter mode would start a new progression again once the prior progression has ended do to T/P or S/L being hit
-Magic number to run on multiple pairs

I did my best to code such an EA.

The expert I made uses a .mqh file that must be saved in your include folder.
The expert WILL NOT function without it.

All are welcome to critique or improve the code I wrote. PLEASE read ALL the comments in the code to understand the external variables. Default settings are just a guess, testing and optimization needs to be performed.

I'm not sure if this strategy is viable, these type of experts can get you into trouble quick! So use for testing only!

The EA starts by using a EMA for initial long or short starting direction. Just an idea. Maybe someone has a better idea?

Enjoy.
__________________
Live Portfolio (This takes a while to download as it is a big excel spreadsheet)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 01-11-2008, 01:39 AM
Senior Member
 
Join Date: Feb 2007
Posts: 163
lcfxtrader is on a distinguished road
Wolfe,

Is the initial entry based on the close of a candle above or below the SMA or does it just need to touch it from above or below? Thanks again for the EA. I hope testing is a success.

Thanks,
lcfxtrader
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 01-11-2008, 01:51 AM
wolfe's Avatar
Senior Member
 
Join Date: Jan 2006
Posts: 704
wolfe is on a distinguished road
Quote:
Originally Posted by ElectricSavant View Post
Hello Wolf...this is very similar to the BlackBird EA...I noticed you have not added the reenter mode yet...but I understand this is a work in progress..The open architecture that you use makes this very versatile...

ES
The EA will re-enter automatically when either a S/L or T/P is executed based on percentage of account balance.

Yes, this is still a work in progress. Any ideas are welcome.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 01-11-2008, 01:59 AM
wolfe's Avatar
Senior Member
 
Join Date: Jan 2006
Posts: 704
wolfe is on a distinguished road
Quote:
Originally Posted by lcfxtrader View Post
Wolfe,

Is the initial entry based on the close of a candle above or below the SMA or does it just need to touch it from above or below? Thanks again for the EA. I hope testing is a success.

Thanks,
lcfxtrader
Right now the EA is coded to follow the close of an EMA.

All it does is this: It takes current bar EMA and compares it to close of 1 bar previous. If current bar is > than previous bar it will start long. If current bar is < previous bar it will start short.

If there are any other ideas we could try them.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 01-11-2008, 02:00 AM
sunwest's Avatar
Member
 
Join Date: Jan 2006
Location: London
Posts: 93
sunwest is on a distinguished road
Hello Wolfe,

Thanks for this EA, this is nicely programmed with Useful info displayed in Journal.
I think you should not really increase your lot as you follow the trend especially starting with 0.1 and 0.2 and 0.3 as you will be really quicly in Loss if the market turn only a few pips.

I think you should start pyramiding with 0.1 Lot only at the begining at least. 0.1 0.1 0.1 etc.. then maybe increase.

Here is 1 of my preset file that you can try in the strategy tester and load for GBP/USD 5M 50000$ for this month only.

Thanks,
Attached Files
File Type: set wolfe-sun-v1-gbp-usd-5m.set (1.0 KB, 414 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 01-11-2008, 02:16 AM
wolfe's Avatar
Senior Member
 
Join Date: Jan 2006
Posts: 704
wolfe is on a distinguished road
Quote:
Originally Posted by sunwest View Post
Hello Wolfe,

Thanks for this EA, this is nicely programmed with Useful info displayed in Journal.
I think you should not really increase your lot as you follow the trend especially starting with 0.1 and 0.2 and 0.3 as you will be really quicly in Loss if the market turn only a few pips.

I think you should start pyramiding with 0.1 Lot only at the begining at least. 0.1 0.1 0.1 etc.. then maybe increase.

Here is 1 of my preset file that you can try in the strategy tester and load for GBP/USD 5M 50000$ for this month only.

Thanks,
Thank you for the compliments sunwest.

You could set the Lot_Size_Increment in the external variables to 0 to not have the lot size increase.

As for maybe increasing, when do you think that should happen?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Tags
martingale, martingale EA

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

LinkBacks (?)
LinkBack to this Thread: http://www.forex-tsd.com/martingale-average-cost-hedging/11734-martingale-ea.html
Posted By For Type Date
ea - learn to trade forex swicki - powered by eurekster This thread Refback 06-05-2008 05:34 PM
[intraday]martingale strategy dan variasinya - Page 6 - Forexindo Forum This thread Refback 04-04-2008 02:15 AM
TFX v1.5 Expert Adviser - The Money Guru Forum - Money Making Discussions This thread Refback 03-31-2008 04:36 PM
Download 10points3 Ea - Type Your Search Here This thread Refback 03-12-2008 12:38 AM
Expert Advisor | Forex MetaTrader Expert Advisors | Over 40 of the Best EA's for MT4 on Squidoo This thread Refback 03-08-2008 07:36 PM
Expert Advisor | Forex MetaTrader Expert Advisors | Over 40 of the Best EA's for MT4 on Squidoo This thread Refback 03-07-2008 06:27 AM
Expert Advisor | Forex MetaTrader Expert Advisors | Over 40 of the Best EA's for MT4 on Squidoo This thread Refback 03-07-2008 02:27 AM
Expert Advisor | Forex MetaTrader Expert Advisors | Over 40 of the Best EA's for MT4 on Squidoo This thread Refback 03-05-2008 12:56 AM
Bright Idea's :: View topic - TFX Public EA Thread (work in progress) This thread Refback 02-29-2008 12:05 PM
Martingale Baggio Method - Page 11 This thread Refback 02-27-2008 08:59 PM
Martingale Baggio Method - Page 11 This thread Refback 02-27-2008 04:07 PM
Martingale Baggio Method - Page 11 This thread Refback 02-27-2008 04:04 PM
Martingale Baggio Method - Page 10 This thread Refback 02-25-2008 05:50 PM
Martingale Baggio Method - Page 10 This thread Refback 02-25-2008 05:07 PM
Martingale Baggio Method - Page 10 This thread Refback 02-25-2008 05:05 PM
Bright Idea's :: View topic - TFX Public EA Thread (work in progress) This thread Refback 02-23-2008 06:38 PM
Bright Idea's :: View topic - TFX Public EA Thread (work in progress) This thread Refback 02-04-2008 05:15 AM
Bright Idea's :: View topic - TFX Public EA Thread (work in progress) This thread Refback 02-03-2008 04:01 AM