Evaluate Last Order

MQL5 Experts

Specification

I need a function writing to evaluate the last order placed after it has reached it's take profit or stop loss, writing the profit/loss to a global variable and also return a Boolean value of 0/1 depending on a profit or loss being generated. My orders always run to stop limits or take profits.

This sounds easy enough, although I have hit a stumbling block with HistorySelect and cannot go any further, the problem is as follows - I have a structure on tick that looks a little like this:

 

void OnTick()
  {
   if(PositionsTotal() >= 1)
      {

      }
   else
      {
         RefreshCharts();
         CalculateProfitAndLoss();
         OpenOrder();
      }
  }

 

Now the problem is, that my OpenOrder() function may fail and the OnTick() function will loop again when the market refreshes and as a result, the CaculateProfitLoss() function), sees the previous unsuccessful trade and reports a zero profit/loss, which isn't correct.

The solution is probably glaringly obvious, but I cannot work it out and want to get on with the technical analysis side of things. 

Let me know what you think. I would have written a full specification, but with no inputs and only two outputs, it didn't seem worth it. 

Only stipulation is that code is heavily documented. 

  

Additional note (added 06/Sep/13): I just want to ensure that people have read the above thoroughly and understand that simple code such as that listed below does not achieve the desired results as I have a lot of failed trades opening, a situation I am attempting to resolve with a new function. Example of what doesn't work: 

 last_deal=HistoryDealGetTicket((int)deals-1);

Responded

1
Developer 1
Rating
(1235)
Projects
2820
80%
Arbitration
156
22% / 43%
Overdue
488
17%
Free
2
Developer 2
Rating
(82)
Projects
150
29%
Arbitration
9
44% / 11%
Overdue
46
31%
Free
3
Developer 3
Rating
(62)
Projects
140
46%
Arbitration
19
42% / 16%
Overdue
32
23%
Free
4
Developer 4
Rating
Projects
2
50%
Arbitration
0
Overdue
0
Free
5
Developer 5
Rating
(18)
Projects
37
43%
Arbitration
6
17% / 50%
Overdue
17
46%
Free
6
Developer 6
Rating
(63)
Projects
80
28%
Arbitration
17
12% / 76%
Overdue
48
60%
Free
7
Developer 7
Rating
(466)
Projects
697
56%
Arbitration
43
30% / 33%
Overdue
113
16%
Working
8
Developer 8
Rating
(71)
Projects
254
53%
Arbitration
16
50% / 38%
Overdue
83
33%
Free
9
Developer 9
Rating
(215)
Projects
302
79%
Arbitration
4
25% / 0%
Overdue
62
21%
Free
Similar orders
I need A Ea For Parabolic SAR With Default Settings And That Ea Including Take Profit And Stoploss Levels. Take profit : 50 points Stop loss : 50 points I have been seen that ea in Mql5 Market I tested it but that ea stop loss and take profits not activated that's why I came here I need a demo for testing process if you gave demo 1st and I will set you as a person to create a ea
Modifying an expert advisor written in mql5 and adding new indicators to it. The result must work both on strategy testing and on live, with no compilation errors and no warnings
see trade open on every tick seconde ok forex pair us us30 if is current running at 40170.00 so open 2 trade buy stop and sell stop both in every tick pending order of buy stop will 40171.00 and sell stop pending order will be 40169.00 buy stop will open at 40171.00 and tp will be 40173.00 and SL will be 40169.50 ok if buy stop hit sell stop order automatically will be close now if sell stop order open at 40169.00 so
Hi, I have an indicator from my friend, I want to copy it to MT5 can you do that for me. Here is the link
I'm seeking assistance in developing a sophisticated trading robot with the following features: Core strategy: Harmonic pattern recognition Supply and demand analysis Fibonacci zigzag for trade optimization Additional components: News filter Dashboard for easy monitoring Customizable settings: Lot size Trailing stop Trading session parameters Maximum number of orders Option to use market or limit orders Resources
1. Add Feature For (SPREAD) Normal trading Hours Spread or User set trading Hours Spread True or false Set to true or False When set to true EA will only create or develop a trade if spread is in this window allowing it to and EA will follow a window in which it can trade based on spread so if spread is to high and outside of this window it will not create a trade It
Hi, I have an indicator from my friend, I want to copy it to MT5 can you do that for me. Here is the link
Hi, I have a working MQ4 EA (With a few warnings but works fine), I need the warnings cleared and converted to MQ5. But I would also like a few improvements first. Firstly: Fix warnings in MT4 code (return value of 'OrderSelect'/'OrderModify' should be checked). Add following features: Magic number modifiable variable (It's currently hard coded) Is it possible to have a stop loss dollar amount instead of lots if
i create a robot which help with order blocks and detection of spikes ....simply it analyses the market for you and if you are using it you wont need much skill to start operating it well you just need to know and understand how it works
I need an experienced programmer to create an automated EA that will open trades based on different candle stick formation strategies and indicators. The EA will first scan the market, find a current market trend and define area of support and resistance. On ranging market the EA doesn’t place trades . (1) EA should use a straddle strategy from either the S/R level, (2) indecision Doji candle from the S/R area, (3)

Project information

Budget
10 - 100 USD
For the developer
9 - 90 USD
Deadline
from 1 to 14 day(s)