I finally got around to doing something about those rapidly-closing trades.
Guys, unless you have actually
used this rubbish, you would not believe what utter, unmitigated appalling crap is mql4. Some of the stuff we coders have to do to work around this drivel is astonishing.
We turn an input into something that is the correct size for a particular pair by using the internal command Point, as in NewStop = OrderOpenPrice() - (StopLoss * Point);
Simple enough unless you are coding a multi-pair trader. In this case we need a variable that can represent Point for each pair, so we have something like
double point = MarketInfo(OrderSymbol(), MODE_POINT);
All well and good until you come across this fact: on some charts of some of the more ridiculously asinine, cretinious, twisted, morose, cabage-brained, turd-for-charisma crims, MarketInfo(OrderSymbol(), MODE_POINT); often returns zero. Fat lot of bloody use that is.
So, if MarketInfo(OrderSymbol(), MODE_POINT) is so unreliable, some of the cleverer people here came to the conclusion that Point could be similarly unreliable and came up with a routine to overcome this piece of dung.
All my recent EA's have a globally-declared variable, factor:
double factor;
Early in init() comes factor = PFactor(Symbol); where PFactor(Symbol) is a function that calculates the value of Point correctly. Lifesys was kind enough to add this to mptm a few months ago.
With me so far? This is where the fun of dealing with this heap of syphilitic Dingo's droppings
really begins.
If, say, StopLoss is declared as an integer as in int StopLoss = 20:
double NewStop = NewStop = OrderOpenPrice() - (StopLoss * Point); is allowed and (StopLoss * Point) creates a 0.xxxxxxxx result.
The command using factor is OrderOpenPrice() - (StopLoss / factor);
But, if StopLoss is an integer then the code (StopLoss / factor) returns a zero value.
What magnificent programming. One method of calculation that creates a < 0 result is allowed, whilst another is not. Therefore any pip value that is going to use factor to convert to the correct number of decimal places has to be declared as a double, not an integer.
A group of stupid sods somewhere in LoonyVille actually sat down and
wrote this rubbish; it wasn't thrown together by a bunch of 8 year olds with a computer. A 16 year old computer science student would be severely bollocked for such a ball-brained- pre-infantile mistake.
All the pip values in mptm were declared as integers, so when interacting with factor resulted in 0 being added to whatever the bot was supposed to be doing, and so trades were closing prematurely. All that was needed was to convert them to doubles - something Paul forgot to do and that I did not notice.
So, fix is in post 1; sing out if I am barking at the wrong moon and the fix does not work.
