0

How would I enable my EA to send a notification only once to my iPhone when the else if (ClosePosition == false) condition returns true (in other words, when my EA fails to close an EA-opened position). At the moment, it pings on every tick.

The ClosePositionboolean for the OrderClose() function returns true when the EA successfully closes the position when the conditions specified are met. It returns ClosePosition == false when the EA fails to close the position.

Here is my code so far

                   else if(ClosePosition == false)
                   {
                   int failedClosePosition = OrdersTotal()-1;
                   bool fail = OrderSelect(failedClosePosition,SELECT_BY_POS,MODE_TRADES);       
                   if(fail == true)
                      {
                      SendNotification("Order Number #"+IntegerToString(OrderTicket(),10)+" has failed to close. Please refer to error code "+IntegerToString(GetLastError()));
                      }
                   }

1 Answers1

0

Without any context to the real solution ( ref. your other post's broader view ),
the repetitively detected reasons to send a notification ought be locked-out by a first occasion such a notification was sent ( imagine an array of notifications positively sent to:

int ArrayOfNotificationsAlreadySENT[][3];  //[ <OrderTicketNUMBER>,
                                           //  <Notification_E.164_TargetNUMBER>,
                                           //  <TimeStampSECONDS>
                                           //  ],

storing an OrderTicket() number as a UUID of such "trouble-maker" )

For problems, where a repetitive detection takes place, may want to extend the definition and add a fourth column, where you update an amount of trouble detections for each respective UUID, and (as common) probably using some fallback policy to reduce the flow of messages according to some reasonable re-notification "distances" from on-first-detected to on-2nd-detect() to on-5th-detect() to on-10th-detect() to on-100th-detect() depending on your feasible trouble-context and business-acceptable density of re-notifications

Community
  • 1
  • 1
user3666197
  • 1
  • 6
  • 50
  • 92