How to get USD value of a trade closed at stop loss for use in a variable
-
I have multiple trades open, one trade closed at loss, in the trade history it show a loss for eg: -11.50$
How can I get that value? Ie I want to add these up and display the totalAll the blocks that do checks for profit or loss are all comparing it <>= etc to some figure, but how do I get that actual amount?
I want this amount

-
I offered a solution for that in this thread:
-
Ok thanks for the info seems easy enough although in the meantime I got it to work using a "custom MQL code" ontick with the following:
static int previous_open_positions = 0;
int current_open_positions = PositionsTotal();
if(current_open_positions < previous_open_positions) // a position just got closed:
{
previous_open_positions = current_open_positions;
HistorySelect(TimeCurrent()-300, TimeCurrent()); // 5 minutes ago
int All_Deals = HistoryDealsTotal();
if(All_Deals < 1) Print("Some nasty shit error has occurred :s");
// last deal (should be an DEAL_ENTRY_OUT type):
ulong temp_Ticket = HistoryDealGetTicket(All_Deals-1);
// here check some validity factors of the position-closing deal
// (symbol, position ID, even MagicNumber if you care...)
LAST_TRADE_PROFIT = HistoryDealGetDouble(temp_Ticket , DEAL_PROFIT);
Print("Last Trade Profit : ", DoubleToString(LAST_TRADE_PROFIT));
}
else if(current_open_positions > previous_open_positions) // a position just got opened:
previous_open_positions = current_open_positions;Then I just made the "LAST_TRADE_PROFIT" the variable I can use

-
Impressive! Congratulations

-
What about this:

To load the last trade only, set that "Not more than..." parameter to 1. The direction is already set to "newest to oldest", so it will start with the newest one. And then get the value in the other block. -
@fxdreema Thanks but a comment wont help as I need to add them in variables so I could do this, Does that look right? Im only working with sell orders to keep it simple so the filter setting are all for sells only

-
My next question I want to get a trailing stop loss based on a "breakeven" price point using the losses calculation and have come with the following:
For each position will use the last opened order as a reference point and then I want to check if the current open trades profit is more than the losses and record the current price then I want to add 15 pips for a profit above breakeven

Im not sure if that is the right way or if using a formula for the current market price less open price of the last order in loop
Lets say the last opened order as a reference point (ie 0 pips) and my breakeven condition is at 20 pips below that order and I want 15 pips profit from there
so the trailing stop will need to start from an offset from the open price 35 pips
Am I on the right track or is there another way to do it?
-
@clintk said in How to get USD value of a trade closed at stop loss for use in a variable:
@fxdreema Thanks but a comment wont help as I need to add them in variables so I could do this, Does that look right? Im only working with sell orders to keep it simple so the filter setting are all for sells only

That structure is correct, but be sure TotalLoss_Sells is properly reinitiated when required.
-
For your second question, how many open trades are supposed to be active at the same time?