Removing alert in indicator if there is a position opened

Moderator: admin

Removing alert in indicator if there is a position opened

Postby Demos4x » Tue Feb 25, 2020 12:41 pm

Hello everyone.

My question is:
Who can I add the condition " if a position is open in this pair, turn off alerts", in a indicator?

For example if I had this code

Code: Select all

void manageAlerts()
{
   if (alertsOn)
   {
      int whichBar = 1; if (alertsOnCurrent) whichBar = 0;
      if (trend[whichBar] != trend[whichBar+1])
      {
         if (trend[whichBar]== 1) doAlert(whichBar,"up");
         if (trend[whichBar]==-1) doAlert(whichBar,"down");
      }
   }
}


I was thinking in the lines of :


void manageAlerts()
{
if (alertsOn) && (command that tells that there is not a position open in that symbol ) = true


or


void manageAlerts()
{
if (alertsOn) && (command that tells that there is position open in that symbol ) = false

I don't know code , I know little of programming, but enough to understand the logic of the code.

Thank you for your help in advance.
Demos4x
 
Posts: 6
Joined: Thu Nov 28, 2019 9:32 pm

Re: Removing alert in indicator if there is a position open

Postby Apprentice » Tue Mar 03, 2020 6:07 am

if (alertsOn && IsPositionExists)

...


bool IsPositionExist()
{
for (int i = OrdersTotal() - 1; i >= 0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderSymbol() == _Symbol)
{
return true;
}
}
}
return false;
}
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 24434
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Removing alert in indicator if there is a position open

Postby Demos4x » Sun Mar 22, 2020 8:13 pm

Dear Apprentice

I tried various ways to apply this code but it is always giving the error:

'IsPositionExists' - undeclared identifier

I tried in various indicators put the code in various places even the ones that I know were wrong, tried to find some tutorials, I unnecessary/wrong declared the bool ispositionExists variable, but simply couldn't make it work.

Can you please add that code to this indicators.

Thank you in advance.

RSI_X2_alarm.mq4
(4.06 KiB) Downloaded 1 time
Demos4x
 
Posts: 6
Joined: Thu Nov 28, 2019 9:32 pm

Re: Removing alert in indicator if there is a position open

Postby Apprentice » Tue Mar 24, 2020 9:11 am

Your request is added to the development list.
Development reference 936.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 24434
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia


Re: Removing alert in indicator if there is a position open

Postby Demos4x » Thu Mar 26, 2020 5:00 pm

Thank you so much for this modification. It works perfectly.
Now I know what I was doing wrong and applied in 2 other indicator just for test and it works perfectly.

Again, Thank you for your work.
Demos4x
 
Posts: 6
Joined: Thu Nov 28, 2019 9:32 pm


Return to Indicator Development

Who is online

Users browsing this forum: No registered users and 3 guests