Forex



Go Back   Forex Trading > Trading systems > Martingale/Average Cost and Hedging
Forex Forum Register More recent Blogs Calendar Advertising Others Help






Register
Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.

From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.

Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
  • Elite Section
    Get access to private discussions, specialized support, indicators and trading systems reported every week.
  • Advanced Elite Section
    For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
See more

Reply
Thread Tools Display Modes
  #41 (permalink)  
Old 06-26-2007, 06:33 AM
don_forex's Avatar
Member
 
Join Date: Oct 2005
Posts: 67
don_forex is on a distinguished road
Version 4

Well, I have tried to clean up and update the code, to include updates from NEO, as well as add the LWMA. Here it is explained.

Trend is the internal value that is checked against the bid/ask. It uses the MAPeriod.

MAPeriod - A friend of mine determined that he liked using 15M TF 80 LWMA to place the orders, I converted it to a 1M TF 1200 LWMA (15*80) Buys above this and sells below.

Everything else is pretty much the same.

The close routines are still screwing up a bit. Sometimes the positive buys above the midpoint will close out a losing sell, sometimes not. same for the sells below the midpoint. Errrr. Can still use some help with this aspect.

Don

Last edited by don_forex; 06-26-2007 at 06:37 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #42 (permalink)  
Old 06-26-2007, 08:49 PM
Neo Neo is offline
Member
 
Join Date: Jun 2006
Posts: 46
Neo is on a distinguished road
Ok, Don...here's how to sort the trend filtering:

extern int MAPeriod = 1200;
double Trend = iMA(NULL, 0, MAPeriod, 0, MODE_LWMA, MODE_CLOSE, 0);

should be...

double Trend = iMA(NULL, PERIOD_M1, MAPeriod, 0, MODE_LWMA, MODE_CLOSE, 0);

as your existing code uses 1200 periods of the current chart timeframe



And for the Buy and Sell routines, you're missing some brackets so the logic is currently wrong so these:

if (Ask < LowestBuy-(Spacing*Point) || Ask > HighestBuy + (TrendSpacing * Point) && Ask > Trend)

if (Bid > HighestSell + (Spacing * Point) || Bid < LowestSell - (TrendSpacing * Point) && Bid < Trend)

should be replaced with:

if ((Ask < LowestBuy-(Spacing*Point) || Ask > HighestBuy + (TrendSpacing * Point)) && Ask > Trend)

if ((Bid > HighestSell + (Spacing * Point) || Bid < LowestSell - (TrendSpacing * Point)) && Bid < Trend)

Good luck, Neo
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #43 (permalink)  
Old 06-26-2007, 09:16 PM
don_forex's Avatar
Member
 
Join Date: Oct 2005
Posts: 67
don_forex is on a distinguished road
Quote:
Originally Posted by Neo View Post
Ok, Don...here's how to sort the trend filtering:

extern int MAPeriod = 1200;
double Trend = iMA(NULL, 0, MAPeriod, 0, MODE_LWMA, MODE_CLOSE, 0);

should be...

double Trend = iMA(NULL, PERIOD_M1, MAPeriod, 0, MODE_LWMA, MODE_CLOSE, 0);

as your existing code uses 1200 periods of the current chart timeframe



And for the Buy and Sell routines, you're missing some brackets so the logic is currently wrong so these:

if (Ask < LowestBuy-(Spacing*Point) || Ask > HighestBuy + (TrendSpacing * Point) && Ask > Trend)

if (Bid > HighestSell + (Spacing * Point) || Bid < LowestSell - (TrendSpacing * Point) && Bid < Trend)

should be replaced with:

if ((Ask < LowestBuy-(Spacing*Point) || Ask > HighestBuy + (TrendSpacing * Point)) && Ask > Trend)

if ((Bid > HighestSell + (Spacing * Point) || Bid < LowestSell - (TrendSpacing * Point)) && Bid < Trend)

Good luck, Neo
According to the help file:

timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.

By putting in PERIOD_M1, you are locking in the 1M timeframe no matter what. I was even thinking of having a couple of externs so people could customize the MA, like one for TF and one for type of MA.

Nice catch on the brackets. I didn't think that would matter.

The closes are still not 100% doing what they are supposed to doing. Same situation above buys and below sells not closing out the losing opposite order all the time.

Don
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #44 (permalink)  
Old 06-26-2007, 09:32 PM
don_forex's Avatar
Member
 
Join Date: Oct 2005
Posts: 67
don_forex is on a distinguished road
Ticket numbers

I think I have an idea about the improper closings. I added a HighestBuyTicket and LowestSellTicket to the comment block and noticed when I ran the backtester the tickets weren't reseting like they should. Maybe this might give us some new area of thought. Maybe a whole subroutine to refresh all the variables once profit is taken.

Don
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #45 (permalink)  
Old 06-26-2007, 10:30 PM
Neo Neo is offline
Member
 
Join Date: Jun 2006
Posts: 46
Neo is on a distinguished road
There seem to be two more areas of issue....both in the start() function:

First, simplify the "count-up" code - I'm also pretty sure you had missed some variables that were being used later in the code...

for (Order = OrdersTotal() - 1; Order >= 0; Order--)
{
if (OrderSelect(Order, SELECT_BY_POS, MODE_TRADES))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Reference)
{
Profit = OrderProfit() + OrderSwap() + OrderCommission();

if (OrderType() == OP_BUY)
{
if (OrderOpenPrice() >= HighestBuy)
{
HighestBuy = OrderOpenPrice();
HighestBuyTicket = OrderTicket();
HighestBuyProfit = Profit;
}

if (OrderOpenPrice() <= LowestBuy)
{
LowestBuy = OrderOpenPrice();
LowestBuyTicket = OrderTicket();
LowestBuyProfit = Profit;
}

BuyOrders++;
if (BuyOrders > MaxBuys) MaxBuys = BuyOrders;
BuyLots += OrderLots();

BuyProfit += Profit;
if (Profit > 0) PosBuyProfit += Profit;
}

if (OrderType() == OP_SELL)
{
if (OrderOpenPrice() <= LowestSell)
{
LowestSell = OrderOpenPrice();
LowestSellTicket = OrderTicket();
LowestSellProfit = Profit;
}

if (OrderOpenPrice() >= HighestSell)
{
HighestSell = OrderOpenPrice();
HighestSellTicket = OrderTicket();
HighestSellProfit = Profit;
}

SellOrders++;
if (SellOrders > MaxSells) MaxSells = SellOrders;
SellLots += OrderLots();

SellProfit += Profit;
if (Profit > 0) PosSellProfit += Profit;
}
}
}
}



Next, try connecting the "if"s in the close analysis section with "else"s - I'm convinced that is where the main issue lies (might also be worth calculating MidPoint unconditionally)....


MidPoint = (HighPoint + LowPoint) / 2;

RefreshRates();

if (MidPoint > 0 && Ask - Bid > MidPoint)
{
if (PosBuyProfit + LowestSellProfit >= ProfitTarget && LowestSell < LowestBuy)
{
OrderSelect(LowestSellTicket, SELECT_BY_TICKET);

OrderClose(OrderTicket(), OrderLots(), Ask, 5, Green);

CloseBuysInProfit();

LowestBuy = 1000;
HighestBuy = 0;
LowestSell = 1000;
LowestSellTicket = 0;
}
else if (PosSellProfit + LowestSellProfit >= ProfitTarget && LowestSell < LowestBuy)
{
OrderSelect(LowestSellTicket, SELECT_BY_TICKET);

OrderClose(OrderTicket(), OrderLots(), Ask, 5, Red);

CloseSellsInProfit();

LowestSell = 1000;
HighestSell = 0;
LowestSellTicket = 0;
}
else if (PosBuyProfit + LowestBuyProfit >= ProfitTarget && LowestBuy < LowestSell)
{
OrderSelect(LowestBuyTicket, SELECT_BY_TICKET);

OrderClose(OrderTicket(), OrderLots(), Bid, 5, Green);

CloseBuysInProfit();

LowestBuy = 1000;
HighestBuy = 0;
LowestBuyTicket = 0;
}
else if (PosSellProfit + LowestBuyProfit >= ProfitTarget && LowestBuy < LowestSell)
{
OrderSelect(LowestBuyTicket, SELECT_BY_TICKET);

OrderClose(OrderTicket(), OrderLots(), Bid, 5, Red);

CloseSellsInProfit();

LowestSell = 1000;
HighestSell = 0;
LowestBuy = 1000;
LowestBuyTicket = 0;
}
}
else if (Ask - Bid < MidPoint)
{
if (PosBuyProfit + HighestBuyProfit >= ProfitTarget && HighestBuy > HighestSell)
{
OrderSelect(HighestBuyTicket, SELECT_BY_TICKET);

OrderClose(OrderTicket(), OrderLots(), Bid, 5, Green);

CloseBuysInProfit();

LowestBuy = 1000;
HighestBuy = 0;
HighestBuyTicket = 0;
}
else if (PosSellProfit + HighestBuyProfit >= ProfitTarget && HighestBuy > HighestSell)
{
OrderSelect(HighestBuyTicket, SELECT_BY_TICKET);

OrderClose(OrderTicket(), OrderLots(), Bid, 5, Red);

CloseSellsInProfit();

LowestSell = 1000;
HighestSell = 0;
HighestBuy = 0;
HighestBuyTicket = 0;
}
else if (PosBuyProfit + HighestSellProfit >= ProfitTarget && HighestSell > HighestBuy)
{
OrderSelect(HighestSellTicket, SELECT_BY_TICKET);

OrderClose(OrderTicket(), OrderLots(), Ask, 5, Green);

CloseBuysInProfit();

LowestBuy = 1000;
HighestBuy = 0;
HighestSell = 0;
HighestSellTicket = 0;
}
else if (PosSellProfit + HighestSellProfit >= ProfitTarget && HighestSell > HighestBuy)
{
OrderSelect(HighestSellTicket, SELECT_BY_TICKET);

OrderClose(OrderTicket(), OrderLots(), Ask, 5, Red);

CloseSellsInProfit();

LowestSell = 1000;
HighestSell = 0;
HighestSellTicket = 0;
}
}


Finally, I changed the initialisation code in the function header like this:

double LowestBuy = 999, HighestBuy = 0.0001, LowestSell = 999, HighestSell = 0.0001, HighPoint, MidPoint, LowPoint;

...to run the Buy & Sell criteria routines on the first pass through:

// BUY Trade Criteria
if (HighestBuy > 0 && LowestBuy < 1000)

// SELL Trade Criteria
if (HighestSell > 0 && LowestSell < 1000)



I added in some auditing code the to version I'm playing with and it was throwing out all sorts of errors before I made these changes. Now there are none being generated and opposite orders appear to be closing correctly.

Neo

Last edited by Neo; 06-26-2007 at 10:35 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #46 (permalink)  
Old 06-26-2007, 10:37 PM
BluePearl's Avatar
Senior Member
 
Join Date: Oct 2005
Posts: 206
BluePearl is on a distinguished road
neo, will you please post the ea with changes? there have been several changes proposed by various members and it's getting difficult to keep track now of what all of the changes are.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #47 (permalink)  
Old 06-26-2007, 11:08 PM
don_forex's Avatar
Member
 
Join Date: Oct 2005
Posts: 67
don_forex is on a distinguished road
Good JOB!!!

We're not worthy, We're not worthy... (Wayne's World)

I have always said there are better programmers than I. Thanks.

Don
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #48 (permalink)  
Old 06-26-2007, 11:57 PM
don_forex's Avatar
Member
 
Join Date: Oct 2005
Posts: 67
don_forex is on a distinguished road
Exclamation Neo Ea

NEO,

if you post your latest version I will add it on the first post. Just name it PipMakerv5NEO. Thanks for taking an interest in this system.

Don
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #49 (permalink)  
Old 06-27-2007, 01:07 AM
Neo Neo is offline
Member
 
Join Date: Jun 2006
Posts: 46
Neo is on a distinguished road
Ok... you guys asked for it

The reason I didn't post the entire EA previously is that I generally "rewrite" EAs in my own formatting style which helps me work out what's going on. I also generally rename variables and functions, though that may just be OCD

Anyway, the major deviation from Don's version is that I grafted the magic number routine from Fifth's Blessing code and added error reporting to a text file. There are a few minor revisions too but the most important is that I added the trend filtering into the Start() function.

I've got a sneaking suspicion that the Martingale side of things isn't working correctly but that's no big shakes at the moment.

Opps... almost forgot! I converted all neccesary "extern bool" parameters into "extern int" so that you can use them in optimisation mode in the strategy tester (0 = false, 1 = true) - the boolean code is just commented out throughout so you can switch it back if you want.

If you find any other issues then I guess you'll let me know
Attached Files
File Type: mq4 PipMakerV5Neo.mq4 (23.9 KB, 622 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #50 (permalink)  
Old 06-27-2007, 01:43 AM
fxnewbie's Avatar
Senior Member
 
Join Date: Jun 2006
Posts: 497
fxnewbie is on a distinguished road
Quote:
Originally Posted by don_forex View Post
I use 1M time frame as there isn't any indicators involved.

I am trying to incorporate a LWMA and still will use a 1M tf.


Don
Why Ea is warning "cannot load external expert stdlib" ?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
Reply

Bookmarks

Tags
adaptive RSI, ADAPTIVE RSI.EX4, ADXMA, bless ea, cache:QNp-4lQtnkIJ:www.forex-tsd.com/martingale-average-cost-hedging/8126-pipmaker-v1-price-action-b, don_forex, ea pipmaker, forex, forex pipmaker, Forex price action, forex price action EA, forex tsd, forex tsd pipmaker, forex-tsd, i_Trend.ex4, ordersend error 4051, pallada, pallada ea, pip maker, Pipmaker, pipmaker 15, pipmaker 9-1, pipmaker ea, pipmaker expert, pipmaker expert advisor, pipmaker forex, pipmaker Forex TSD, PipMaker mq4, PipMaker MT4, pipmaker settings, pipmaker v10, pipmaker v14, PIPMAKER V15, pipmaker v15_3, PipMaker v5, pipmaker v9, PipMakerV5aNeo, PipMaker_NeoV5a_Rodmod8.mq4, pipmaker_v15, Pipmaker_V15.mq4, Pipmaker_V15_4.mq4, Price, price action, price action ea, price action expert advisor, price action forex, price action forex trading, price action mq4, price action trading, slope direction line, slope direction line modified.mq4, Terminator, terminator ea, tsd forex, USD CDN Terminator EA, www.forex-tsd.com


Currently Active Users Viewing This Thread: 2 (1 members and 1 guests)
profittaker
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Price action reversal EA help !!!!! compro99 Expert Advisors - Metatrader 4 5 11-18-2009 07:39 PM
Want some action? FX of course Kirsty_FX Suggestions for Trading Systems 2 05-17-2007 03:15 AM
EA Based on Price Movement babarmughal Expert Advisors - Metatrader 4 10 05-29-2006 08:56 PM
Bar Action Shahzadfx Expert Advisors - Metatrader 4 16 04-04-2006 05:38 AM


All times are GMT. The time now is 03:06 PM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.