| stevehopwoodforex.com https://www.stevehopwoodforex.com/phpBB3/ Print view |
|
| Water EA https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=5857 |
Page 2 of 2 |
| Author: | SteveHopwood [ Thu Jun 11, 2020 1:47 pm ] |
| Post subject: | Water EA |
A little more clarification. You are depending on the host chart receiving a quote from your broker if you run an EA with your code in the OnTick() event. Masses of stuff can be happening to the other pairs and your bot will not pick them up. The solution is the OnTimer() function. You have to add this yourself: Code: Select all Code: Select all Code: Select all Code: Select all In the rational world, the result of dividing 1 by 2 is 0.5, even if the result is held in a double so, double someNumber = 1 /2; results in someNumber being zero, not 0.5 The second concerns comparing doubles. Suppose you declare two doubles i.e. Code: Select all Code: Select all Variable declared as 'double' have 8 decimal points, so the equation should be comparing two values of 25.00000000 each. The compiler sometimes adds an extra 1 to the final decimal point, so one of the numbers might contain 25.00000001. They are unequal so the equation fails. Sane programming languages have the fix for this installed. CrapQl4 doesn't, or at least did not, so we have a function provided by garyfritz a long time ago: Code: Select all Code: Select all |
|
| Author: | SteveHopwood [ Fri Jun 12, 2020 12:53 pm ] |
| Post subject: | Water EA |
Some more of the stuff not usually mentioned in coding lessons or Mql4 documentation. Two thingies that will stop your code executing are: division by zero; the Array out of range error. These stop your EA in its tracks without telling you, so you think it is still running. This is why all mine have the time display on the chart; the EA has stopped if the time is not updating. Thomas flashes, "Active" to show that TDesk is running. Use a conditional if there is any chance of the divisor being 0 i.e. Code: Select all This is the standard use of Point in a single pair trader and always works: double take = NormalizeDouble(Ask + (takeProfit * Point), Digits); We need to find the value of Point differently in a multi pair trader such as SPB. Here, the code would be: Code: Select all Code: Select all Code: Select all You will see the errors in the Experts tab, along with the line number in the code that generated it. |
|
| Author: | wallywonka [ Sat Jun 13, 2020 2:56 am ] |
| Post subject: | Water EA |
Appreciate all of these posts Steve, very informative stuff! |
|
| Author: | SteveHopwood [ Sat Jun 13, 2020 1:20 pm ] |
| Post subject: | Water EA |
Here is a nasty little trick that our beloved platform has up its sleeve and which it is essential to know about. A trade shows up in our trades window as soon as it is opened but this is a mirage. It is not safely tucked away in the memory location that an EA interrogates for open trades until the platform receives a return receipt from the broker's server. This can take some time to arrive. So here is what happens:
We discovered this in the early years of SHF. It has not been a problem since because none of us would bother to have nightmares about not including code to combat it. This has not been an issue lately because we have been writing so many multi-pair EA's that mostly send off stop orders. It is a huge problem when you are writing single pair bots. PostTradeAttemptWaitSeconds that defaults to 10 minutes. This tells the bot to wait for ten minutes after attempting to send a trade regardless of whether or not the order send was successful. Further down is this: Code: Select all Code: Select all All my shells and hence single pair EA's have this input, defaulting to 1 minute. This is a defence for novice coders, against faulty coding. The most likely scenario is coding the trade trigger incorrectly, sending a buy when the EA should be sending a sell. The EA spots this at the next tick and instantly closes the trade, costing the spread. This will continue until you notice. My code includes a check on the most recently closed trade and declares it a 'rogue' trade if it opened and closed inside one minute. It then displays a warning on the chart feedback display and sounds an alert. All this happens automatically if you are using my shells to write an EA, at viewtopic.php?p=803#p803 Or you can hack the attached - just search for the inputs/variables to see how I code their use. |
|
| All times are UTC | Page 2 of 2 |
|
Powered by phpBB® Forum Software © phpBB Limited |
|