Calc Loss on specific Pair

 

Hi all,

trading on 4 pairs

EUR/USD

GBP/USD

USD/JPY

USDCHF


EURUSDMaxLoss = -500

GBPUSDMaxLoss = -350

...


How can i calculate the MaxLoss on E/U and close all E/U trades if E/U MaxLoss >= -500 greater or equal if reached


Example code can be combined for all 4 majors or seperated for each pair


thx in advanced for any help!

 
fxhedger wrote >>

Hi all,

trading on 4 pairs

EUR/USD

GBP/USD

USD/JPY

USDCHF

EURUSDMaxLoss = -500

GBPUSDMaxLoss = -350

...

How can i calculate the MaxLoss on E/U and close all E/U trades if E/U MaxLoss >= -500 greater or equal if reached

Example code can be combined for all 4 majors or seperated for each pair

thx in advanced for any help!

Not going to be easy, for openers you will need to use OrderSelect() to get each order so you can use OrderProfit() to get the current balance.

You will need to run a loop to check all of the orders and select them by magic number, so you will need to make sure that when you open a E/U trade it has that unique number.

If you have pending orders it gets more complicated you will likely have to sort them out as well.(Might be interesting to see what OrderProfit() would return for a pending order?)

Once you have selected an order; the calcs are straightforward: Double Runningtotal = Runningtotal + OrderProfit();

After exiting loop then test: if(Runningtotal<=-500) {....close all E/U trades...}

if these curencies are trading in the same Ea you will need to loop it for each one or perhaps use "case".

Multi currency ea's are very difficult to keep organised and can't be back tested on the tester so if you haven't got too far with this

I'd suggest that you concentrate on one at a time in one Ea, might help to keep the tylenol expenses down.

HTH

Keith

 
fxhedger wrote >>

Hi all,

trading on 4 pairs

EUR/USD

GBP/USD

USD/JPY

USDCHF

EURUSDMaxLoss = -500

GBPUSDMaxLoss = -350

...

How can i calculate the MaxLoss on E/U and close all E/U trades if E/U MaxLoss >= -500 greater or equal if reached

Example code can be combined for all 4 majors or seperated for each pair

thx in advanced for any help!

hey fx.......here ya go.....h

double TotalProfit(string sym)
{
int total=OrdersTotal();
double profit = 0.0;
for (int cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS);

if(OrderSymbol() != sym) continue;
{
profit += OrderProfit();
}
}
return (profit);
}