Page 1 of 1

Removing alert in indicator if there is a position opened

PostPosted: Tue Feb 25, 2020 12:41 pm
by Demos4x
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.

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

PostPosted: Tue Mar 03, 2020 6:07 am
by Apprentice
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;
}

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

PostPosted: Sun Mar 22, 2020 8:13 pm
by Demos4x
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 448 times

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

PostPosted: Tue Mar 24, 2020 9:11 am
by Apprentice
Your request is added to the development list.
Development reference 936.

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

PostPosted: Thu Mar 26, 2020 7:08 am
by Apprentice

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

PostPosted: Thu Mar 26, 2020 5:00 pm
by Demos4x
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.