stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

MPTM's new home
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=64
Page 8 of 57
Author:  cuzgeorge [ Mon May 14, 2012 11:08 am ]
Post subject:  Re: MPTM's new home

Hi Steve,
this MPTM is incredible. As i learn more of how it works, i start to understand many, many, of your EA's much better. The guide here also explains many items you find in other EA's not written by you and obtained by paying or D/L from other sites. There are some modules you dont always use that are also explained. This helps with the actual setup of ANY EA settings you may find, whether using MPTM or not.
Don't you think "Home of MPTM" should be next to the "UTILITIES" tab. Its rather obscure, or hard to find where it is now. It should be essential reading or even linked to your welcome screen. What do you think, am i the only one? :shock:

This is so important for people who dont know about your work or dont even know what MPTM is. i did'nt know what it was, thinking it was another normal EA until a little while ago. I feel i should have started with this before i even went near any EA, it's that important. I finally got a good Sunday nights sleep with out waiting for the markets to open as i usually do, and found MPTM had handled all my EA's as it should have. sure i had wrong settings at one part, but this is part of the learning process.
2c here and thank you for this magnificent piece or work. cant believe you wrote this so long ago. you always say your older work is 'looser' but now i know better, again.!! ;)
regards,
cuzgeorge
Author:  SteveHopwood [ Mon May 14, 2012 5:32 pm ]
Post subject:  Re: MPTM's new home

Glad you are enjoying it George - lovely to hear.

:D
Author:  pgtips [ Mon May 28, 2012 9:25 pm ]
Post subject:  Re: MPTM's new home

Hi Steve,

I read that partial close is used in conjunction with Break Even settings.
1. Can I set this/will it work with a negative number, basically I want to lock in half my trade early at +10 and set SL to -10. Then at 18 move the SL to BE +1

2. I can't figure how to set the BE to +1 in this instance because I have already used BEP to be 10 for the partial close routine.

Like this
extern string BE="Break even settings";
extern bool BreakEven=true;
extern int BreakEvenPips=10;
extern int BreakEvenProfit=-10;
extern bool HideBreakEvenStop=false;
extern int PipsAwayFromVisualBE=100;
//----------------------------------------------
extern string JSL="Jumping stop loss settings";
extern bool JumpingStop=true;
extern int JumpingStopPips=18;
extern bool AddBEP=false; want this to be +1 but already set BEP to 10 to enable partial close of half profit at 10
extern bool JumpAfterBreakevenOnly=false;
extern bool HideJumpingStop=true;
extern int PipsAwayFromVisualJS=100;

Thanks for a great piece of code.
Kevin
Author:  SteveHopwood [ Mon May 28, 2012 9:42 pm ]
Post subject:  Re: MPTM's new home

You cannot use the same instance of an ea to perform mutually exclusive functions. Expecting to be able to do so is ridiculous.

You can probably use multiple instances of mptm to perform otherwise mutually exclusive functions. Don't know for sure, because I have never done so myself. Do what the rest of the world does. Try it and see.

:D
Author:  pgtips [ Mon May 28, 2012 10:35 pm ]
Post subject:  Re: MPTM's new home

Thanks for the reply, yes I've been trying it for a while, without success and just wanted to see if I was approaching it the wrong way or if it was even possible.
Author:  SteveHopwood [ Mon May 28, 2012 10:50 pm ]
Post subject:  Re: MPTM's new home

pgtips wrote:Thanks for the reply, yes I've been trying it for a while, without success and just wanted to see if I was approaching it the wrong way or if it was even possible.
Hehe. I do not joke when I write that I rarely know what this EA is capable of. :lol: Any coder will confirm that he/she spends most of his/her time tracking down the last time they solved this problem, or that problem and using copy/paste/edit to save working out how to code it again.

So, run multiple instances of mptm and edit each instance to achieve whatever it is you want to achieve.

:D
Author:  garyfritz [ Tue May 29, 2012 4:36 am ]
Post subject:  Re: MPTM's new home

Look out! You've awakened the Software Engineer!!
SteveHopwood wrote:Any coder will confirm that he/she spends most of his/her time tracking down the last time they solved this problem, or that problem and using copy/paste/edit to save working out how to code it again.
I must beg to differ, strenuously. No offense intended, but an experienced professional coder would quail at the very thought of having dozens of copy-and-pasted versions of code lying about. They might all be different in some way, causing confusion when you use a copy that works differently than you're used to. Worse, if you find a problem in it, it's nearly impossible to find all the copies you pasted everywhere, and if you can, then you have to fix the same problem 27 times. There are plenty of reasons why copying the code to a zillion different places is a recipe for disaster, or at least serious headaches.

A pro coder will build a shared LIBRARY of reusable code, so the same common code gets used everywhere. That way there is ONE copy of each key routine, in a known place, and all programs use that same shared copy. You write your library routines carefully so they encapsulate their functionality, without a lot of extraneous cruft like "you have to set this global variable before you call it, and pull your result from that global variable when it's done, and oh by the way it also changes this thing and that thing that you have to know about." Simple clean functions do everything internally (as much as possible), without broadcasting details of their internal workings. That way you can change the internal workings if necessary without disrupting the programs that call it.

Most modern professional programming languages are actually built to hide all internal details of your code so that calling routines literally cannot see or affect the code's internal functioning. They changed to this non-obvious approach because decades of research and practical experience have shown that this is the most efficient way we know to develop software.

With most of your code in these black-box functions, your main program becomes much smaller and vastly easier to write, debug, maintain, and understand. This is the way all (literally 99.9% or more) professional software is developed. I'd bet even incompetent hacks like the Empty4 developers use this approach. It's the technique that has been developed over decades by thousands of programmers. It's the only way that's manageable for large software projects, and IMHO it's the best way for small ones too.

Steve, the fact that you've taught yourself to code, and that you are so incredibly prolific, is a great testament to your intelligence and your ability to hold huge amounts of complexity in your head. The fact that you are continuously bedeviled by copy-paste bloops &etc, that bugs fixed in your shell do not propagate to older EAs, that you cannot remember how an EA works a few months after you write it, and other problems, speaks to the inefficiency of the approach you use. Your approach works for you, but IMHO it doesn't work very well. I think you would be amazed how much more productive you could be if you made the effort to switch to a modern software-development model.
Author:  retireme [ Tue May 29, 2012 10:48 am ]
Post subject:  Re: MPTM's new home

I read every thread on this forum, spend hours enjoying the banter back and forth... People may say well you don't say much, don't even contribute much. I am not at the level of even the lowest of posters, so I live by the maxim that if you add nothing to the conversation, keep your trap shut. No-one ever learned anything by talking!

However, after saying that, I finally found a comment that deserves some response and one that I feel qualified to contribute too. Thank you Gary :)

It is not a long drawn out posting but I challenge Gary to look around his home, family, shopping centre, even workplace and show me two people that operate exactly the same. My background is in behavioural science and as such, I basically watch, listen and learn. I have been employed in this field for some years and have watched many people who on the surface seem to be twins. By that I mean think, act, speak and generally conduct themselves in the same manner. Unfortunately, what we see is not always what is there. Gary looks at most things from an engineering perspective, you can see that in almost all posts. There is absolutely nothing wrong with that, but it has to be recognised that there are many other types of people on this planet. Steve probably taught himself programming out of necessity, inefficiency is not necessarily high on his list. We are all driven my different needs, if chaos programming (think about it when I need it) is your thing, then kudos to you. There is far more inventiveness derived from a chaos programmer than the software engineer. Yes the engineer will have a "dotted i and cross t" approach, tested, retested, improved, re-improved, tested again and so on... this is their nature. Kudos to you too!

We need you all and thank you for what you do and how you do it.

Now I will crawl back in my box until next time :)

Kind regards
RM
Author:  garyfritz [ Tue May 29, 2012 2:17 pm ]
Post subject:  Re: MPTM's new home

I absolutely agree that different people are different, and different approaches can work best for different people.

I also believe that you can become "used to" an approach and it feels comfortable to you, whether or not it's a good way to do it. Many many programmers resisted the change to the the methodology I described (and other earlier changes too) because they didn't want to change what worked for them and what they were used to. But over time people realized that these new approaches really were dramatically better. That's why they've been so universally adopted.

Chaos programming (great term!) may work for the kind of OCCD coding that Steve practices. But I think it also costs him much more than he realizes.

Steve, this is a poor analogy, but: I'm certain you've had plenty of students who played "OK" and insisted "I don't have to practise, I'm doing fine." But you know how crucial regular practise is if you want to become a good pianist. Without regular practise you develop bad habits, you don't learn proper technique, you don't improve, etc. Well "good programming technique" is the "regular practise" of the programming world. :D Just as it's possible for one of your students to plunk out acceptable playing based on innate ability, it's possible to knock out code that works, most of the time, maybe. But if you are serious about coding -- like, if you're going to spend hundreds of hours doing it, and if you're going to entrust money to the results -- then it's to your benefit to do it right. Dodgy coding techniques can have much more serious impact (e.g. on your account and on your sanity, and that of everyone who uses your code) than marginal piano technique.

Marginal piano technique is acceptable for the amateur pianist who just wants to play for fun, and marginal coding technique works for the hobby coder. But you're well beyond that, in terms of the time you've invested and the results you've achieved and are reaching for. You're striving for something closer to the "concert pianist" level of coding, or at least a session musician. Practise, practise, practise. :lol:
Author:  pgtips [ Tue May 29, 2012 2:31 pm ]
Post subject:  Re: MPTM's new home

Dare I offer an alternative I have found (still to resolve 3 problems of 5 digit broker, preserve lots and it only works on full lot size, not mini) but it does get around multiple instances of code running and using shared variable.

I wonder Steve if I might have permission to play around and maybe borrow some of your code. I have no idea where to start but I'll give it a go.

Code: Select all

//+--------------------------------------------------------+
//|                  e-Smart_Tralling                      |
//+--------------------------------------------------------+

extern   bool     UseOneAccount = true;
extern   bool     UseCloseOneThird = true;
extern   int      LevelProfit1 = 30;
extern   int      LevelMoving1 = 10;
extern   int      LevelProfit2 = 15;
extern   int      LevelMoving2 = 10;
extern   int      LevelProfit3 = 25;
extern   int      LevelMoving3 = 15;
extern   int      TrailingStop = 30;
extern   int      TrailingStep = 5;
extern   int      Slippage = 2;
extern   bool     ShowComment = true;
extern   bool     UseSound = true;
string   var_132 = "expert.wav";

//+------------------------------------------------------------------+

void deinit()
{
Comment("");
}

//+------------------------------------------------------------------+

void start()
{
double point;
int    digits;
string msg = "";

for (int i = 0; i < OrdersTotal(); i++)
   {
   if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      {
      if (UseOneAccount || (OrderSymbol() == Symbol()))
         {
         ThreeLevelSystemOfOutput();
         digits = MarketInfo(OrderSymbol(),MODE_DIGITS);
         point = MarketInfo(OrderSymbol(),MODE_POINT);
         msg = msg + OrderSymbol() + "  Öåíà: " + DoubleToStr(OrderOpenPrice(),digits) + "  SL = " + DoubleToStr(OrderStopLoss(),digits) + " (" + StopLossInPoint() + ")\n";
         }
      }
   }

if (ShowComment) Comment(msg);
}

//+------------------------------------------------------------------+

void ThreeLevelSystemOfOutput()
{
int profit = ProfitPosition();
int sl = StopLossInPoint();
int spread = MarketInfo(OrderSymbol(),MODE_SPREAD);

if ((profit > LevelProfit1) && (profit <= LevelProfit2) && (sl < LevelMoving1))
   {
   ModifyStopLossInPoint(LevelMoving1);
   if (UseCloseOneThird) CloseOneThird();
   }
if ((profit > LevelProfit2) && (profit <= LevelProfit3) && (sl < LevelMoving2)) ModifyStopLossInPoint(LevelMoving2);
if ((profit > LevelProfit3) && (sl < LevelMoving3)) ModifyStopLossInPoint(LevelMoving3);
if (profit > LevelMoving3 + TrailingStop + TrailingStep) TrailingPositions();
}

//+------------------------------------------------------------------+

void CloseOneThird()
{
bool   result = false;
double lots = MathCeil(OrderLots() / 3.0 * 10.0) / 10.0;

if (lots > 0.0)
   {
   if (OrderType() == OP_BUY)
      {
      result = OrderClose(OrderTicket(),lots,Bid,Slippage,CLR_NONE);
      }
   if (OrderType() == OP_SELL)
      {
      result = OrderClose(OrderTicket(),lots,Ask,Slippage,CLR_NONE);
      }
   if (result && UseSound) PlaySound(var_132);
   }
}

//+------------------------------------------------------------------+

void TrailingPositions()
{
double bid;
double ask;
double point = MarketInfo(OrderSymbol(),MODE_POINT);

if (OrderType() == OP_BUY)
   {
   bid = MarketInfo(OrderSymbol(),MODE_BID);
   if (bid - OrderOpenPrice() > TrailingStop * point)
      {
      if (OrderStopLoss() < bid - (TrailingStop + TrailingStep - 1) * point)
         {
         ModifyStopLoss(bid - TrailingStop * point);
         return;
         }
      }
   }

if (OrderType() == OP_SELL)
   {
   ask = MarketInfo(OrderSymbol(),MODE_ASK);
   if (OrderOpenPrice() - ask > TrailingStop * point)
      {
      if ((OrderStopLoss() > ask + (TrailingStop + TrailingStep - 1) * point) || (OrderStopLoss() == 0))
         {
         ModifyStopLoss(ask + TrailingStop * point);
         }
      }
   }
}

//+------------------------------------------------------------------+

void ModifyStopLoss(double sl)
{
bool result = OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),0,CLR_NONE);
if (result && UseSound) PlaySound(var_132);
}

//+------------------------------------------------------------------+

void ModifyStopLossInPoint(int stoploss)
{
bool   result;
double sl = 0;
double point = MarketInfo(OrderSymbol(),MODE_POINT);

if (OrderType() == OP_BUY) sl = OrderOpenPrice() + stoploss * point;
if (OrderType() == OP_SELL) sl = OrderOpenPrice() - stoploss * point;

result = OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),0,CLR_NONE);
if (result && UseSound) PlaySound(var_132);
}

//+------------------------------------------------------------------+

int ProfitPosition()
{
double bid;
double ask;
double point = MarketInfo(OrderSymbol(),MODE_POINT);
double profit = 0;

if (OrderType() == OP_BUY)
   {
   bid = MarketInfo(OrderSymbol(),MODE_BID);
   profit = (bid - OrderOpenPrice()) / point;
   }
if (OrderType() == OP_SELL)
   {
   ask = MarketInfo(OrderSymbol(),MODE_ASK);
   profit = (OrderOpenPrice() - ask) / point;
   }
return(MathRound(profit));
}

//+------------------------------------------------------------------+

int StopLossInPoint()
{
double point = MarketInfo(OrderSymbol(),MODE_POINT);
double sl = 0;

if (OrderType() == OP_BUY) sl = (OrderStopLoss() - OrderOpenPrice()) / point;
if (OrderType() == OP_SELL) sl = (OrderOpenPrice() - OrderStopLoss()) / point;
if (OrderStopLoss() == 0.0) sl = -OrderOpenPrice() / point;
return(MathRound(sl));
}
Kevin
All times are UTC Page 8 of 57