Risk per currency function

Avatar
  • updated
  • Fixed

I tested the function "risk per currency" to understand how it works.

Installed default set for 5 currency pairs on a demo account.

expertId:

eurusd - 1011

gbpusd - 1012

audusd - 1013

usdchf - 1014

usdjpy - 1015

Risk per currency properties (the same for each pair):

Type - by position number

Max risk value - 1.0

Opposite position calc mode - Netto Mode

Additional magic number list - 1011,1012,1013,1014,1015

Use semaphor - true

I expected the following:

with an open buy position on eurusd, positions will not be opened (until the eurusd position is opened):

buy - gbpusd, audusd

sell - usdchf, usdjpy

Further, I noticed that after the time elapsed, part of ea spontaneously turned off

From the EA logs, I noticed that at that moment an error occurred -  "invalid pointer access in 'RiskPerCurrency.mqh'". Also at this moment, a new signal appeared for another currency pair.

Has anyone encountered this? 
Is this a bug or incorrect settings EA?

And I understand the logic of the function correctly?

Pinned replies
Avatar
1
Andrey Khatimlianskyi
  • Answer

New parameter -- Consider only one position per EA (symbol/magic/type) -- is available in 2.54.11

Avatar
3
Andrey Khatimlianskyi
  • Under review

Thank you for your bug report!

It is a bug in Risk per currency library, of course.

Can you share your set file and expert logs? I'll investigate it and try to fix.

And yes, you understand function correctly. With buy EURUSD opened, no more buys for EURxxx or xxxUSD or sells for xxxEUR or USDxxx are allowed.

Avatar
0
jay hu

I observed that while EUUSD trend up, USDCHF trend down in the recent market. The logic suppose while CP EA open buy position for EU pair based on active signal, no more buy for UCHF but sell is only allowed? Even those two pairs use same strategy or same signal say MA crossing.

Avatar
1
Kirill El
Quote from Andrey Khatimlianskyi

Thank you for your bug report!

It is a bug in Risk per currency library, of course.

Can you share your set file and expert logs? I'll investigate it and try to fix.

And yes, you understand function correctly. With buy EURUSD opened, no more buys for EURxxx or xxxUSD or sells for xxxEUR or USDxxx are allowed.

Andrey, 


set file:

1011_eurusd.set

1012_gbpusd.set
1013_audusd.set
1014_usdchf.set
1015_usdjpy.set
expert log:
20230717.log
Avatar
0
Kirill El

in the previous message, the terminal log. Additionally, I attach the expert log

20230717.log

Avatar
1
Quote from Kirill El

in the previous message, the terminal log. Additionally, I attach the expert log

20230717.log

Thanks, I'll check and write you back.

Avatar
0
Andrey Khatimlianskyi
  • Fixed

Thanks again for your bug-report!

It is fixed in 2.54.4 -- https://t.me/CommunityPowerNews/117

Avatar
0
Kirill El

Andrey, thank you very much

I continued testing and see that the error "invalid pointer access in 'RiskPerCurrency.mqh'" no longer appears (at least for now).

But there was a question on the logic of work of function. In my test, I see that a series of usdchf has opened, and then positions are opened for eurusd, gbpusd, audusd.

Image 4494

Do I understand correctly that with my settings (Netto Mode: 2 buy + 1 sell = +1 , Type - by position number, Max risk value - 1.0) due to 6 open sell positions at usdchf, it is possible to open 7 positions at xxxusd (any type - 1st trade, martin)?

Is it possible to add a parameter that would set which positions should be included in the calculation (only 1st trade or all trade (1st trade + martin trade)?

Sorry for bad english. I hope the idea is clear

Avatar
0
Quote from Kirill El

Andrey, thank you very much

I continued testing and see that the error "invalid pointer access in 'RiskPerCurrency.mqh'" no longer appears (at least for now).

But there was a question on the logic of work of function. In my test, I see that a series of usdchf has opened, and then positions are opened for eurusd, gbpusd, audusd.

Image 4494

Do I understand correctly that with my settings (Netto Mode: 2 buy + 1 sell = +1 , Type - by position number, Max risk value - 1.0) due to 6 open sell positions at usdchf, it is possible to open 7 positions at xxxusd (any type - 1st trade, martin)?

Is it possible to add a parameter that would set which positions should be included in the calculation (only 1st trade or all trade (1st trade + martin trade)?

Sorry for bad english. I hope the idea is clear

Your English is perfect :)

And you can always write me privately in Russian with such a bug-reports.

You understand correctly, if you have 6 sells USDxxx, EA can open up to 7 buys USDxxx or 7 sells xxxUSD with settings your set.

Do you want to calculate only first trades for RiskPerCurrency?
How to detect them? Just take 1 trade per side (buy/sell) / magic / symbol?

Avatar
0
Kirill El
Quote from Andrey Khatimlianskyi

Your English is perfect :)

And you can always write me privately in Russian with such a bug-reports.

You understand correctly, if you have 6 sells USDxxx, EA can open up to 7 buys USDxxx or 7 sells xxxUSD with settings your set.

Do you want to calculate only first trades for RiskPerCurrency?
How to detect them? Just take 1 trade per side (buy/sell) / magic / symbol?

Andrey, yes, I want to calculate only first trades for RiskPerCurrency.

I want to avoid a situation where two (or more) series of trades can be opened in "one direction" (as in my example, 1st trades for eurusd, gbpusd, audusd were opened, which could potentially be transformed in a series with martin)

you asked "How to detect them?"

I think we need bundle "side + type of symbol - xxx(any) or (any)xxx"

That is at each moment of time only 2 first trade can be opened "in the opposite direction" at the same time:

buy (any)XXX (1st trade) + sell (any)XXX (1st trade)

Example: buy eurUSD (1st trade) + sell gbpUSD (1st trade). Or buy eurUSD (1st trade) + sell eurUSD (1st trade)

or

buy (any)XXX (1st trade) + buy XXX(any) (1st trade)

Example: buy eurUSD (1st trade) + buy USDchf (1st trade)

or

buy XXX(any) (1st trade) + sell XXX(any) (1st trade)

Example: buy USDchf (1st trade) + sell USDjpy (1st trade). Or buy USDchf (1st trade) + sell USDchf (1st trade)

or

sell XXX(any) (1st trade) + sell (any)XXX (1st trade)

Example: sell USDchf (1st trade) + sell eurUSD (1st trade)

and this would apply to all magics in the "Additional magic number list"

Avatar
1
Quote from Kirill El

Andrey, yes, I want to calculate only first trades for RiskPerCurrency.

I want to avoid a situation where two (or more) series of trades can be opened in "one direction" (as in my example, 1st trades for eurusd, gbpusd, audusd were opened, which could potentially be transformed in a series with martin)

you asked "How to detect them?"

I think we need bundle "side + type of symbol - xxx(any) or (any)xxx"

That is at each moment of time only 2 first trade can be opened "in the opposite direction" at the same time:

buy (any)XXX (1st trade) + sell (any)XXX (1st trade)

Example: buy eurUSD (1st trade) + sell gbpUSD (1st trade). Or buy eurUSD (1st trade) + sell eurUSD (1st trade)

or

buy (any)XXX (1st trade) + buy XXX(any) (1st trade)

Example: buy eurUSD (1st trade) + buy USDchf (1st trade)

or

buy XXX(any) (1st trade) + sell XXX(any) (1st trade)

Example: buy USDchf (1st trade) + sell USDjpy (1st trade). Or buy USDchf (1st trade) + sell USDchf (1st trade)

or

sell XXX(any) (1st trade) + sell (any)XXX (1st trade)

Example: sell USDchf (1st trade) + sell eurUSD (1st trade)

and this would apply to all magics in the "Additional magic number list"

I meant that all trades made by 1 EA have the same magic.

So, we can only get the 1 trade per magic. But it will work for Max risk value - 1.0 only. So, I'll add this as an option.