Price Alert Robot for cAlgo
Price Alert Robot for cAlgo
The PriceAlertWithHotkeys robot allows users to interact with alerts through a user interface by enabling hotkey functionality and mouse interaction. Users can press the 'A' key to activate the alert point setting mode, indicated by a mode message on the chart. Once the mode is activated, users can click on the chart to set a new alert point based on the mouse click price. The robot updates the alert point by removing previous alert lines and labels and drawing a new horizontal line and text label at the clicked price position. This interaction is handled by the Chart_KeyDown and Chart_MouseDown event methods .
The PriceAlertWithHotkeys robot's primary functionality is to alert the user when the current price of a financial instrument crosses a specified alert point. It achieves this by comparing the current price, represented by Symbol.Bid, with the alert point adjusted for a price offset. When the current price is within the specified range, the robot triggers an alert by playing a sound from a specified file path and displaying a message "its now cross MR VIPER !" on a chart grid. This alert mechanism is activated or deactivated automatically in the OnTick method, which checks the price on each tick .
Including both price offset and alert point parameters in the PriceAlertWithHotkeys robot is significant for user flexibility and robustness in alert precision. The alert point acts as a primary threshold for triggering alerts, while the price offset allows for a range of sensitivity around this threshold. This dual-parameter setup provides users with control over how narrowly or broadly they want the alert conditions to be defined, accommodating various trading strategies and market conditions. It enhances the robot's adaptability and usability in different trading scenarios .
Upon stopping, the PriceAlertWithHotkeys robot manages resources by cleaning up UI elements and event subscriptions. The alert message in _alertTextBlock is cleared, and the alert timer is stopped inside the OnStop method. Additionally, the robot removes the grid and graphic elements like "alertLine" and "alertLabel" from the chart and unsubscribes from the Chart.MouseDown event. These steps ensure proper resource management and prevent potential memory leaks by removing unused references and subscriptions .
The hotkey feature contributes to user flexibility by allowing users to quickly enter alert point setting mode without navigating through multiple menu layers. Pressing the 'A' key provides immediate feedback by displaying a mode message, guiding users to click on the chart to set a new alert point. This direct interaction with the chart makes the system intuitive and user-friendly. The hotkey significantly enhances the efficiency of the robot, especially in fast-paced trading scenarios where timely response to price movements is crucial .
The robot uses mouse interactions and hotkeys to dynamically update the alert point through user input. Once the user presses the 'A' key, the chart enters an alert point setting mode, indicated by a message on the mode message TextBlock. Users can then click on the chart, and the Chart_MouseDown event method updates the alert point to the clicked price by removing any existing alert line and label, and drawing a new line and label at the clicked price. This interaction supports dynamic updates without needing to alter hardcoded values or use a traditional UI input form .
The Grid UI component in the PriceAlertWithHotkeys robot serves to display information and status messages to the user. It is structured as a grid with two rows and one column, positioned at the top right of the chart area. The first row contains a TextBlock for displaying alert messages, while the second row holds a TextBlock for mode messages. This grid setup ensures that important alert information is prominently displayed, facilitating user interactions and alert recognition. The grid is initialized and integrated into the chart through the InitializeGrid method .
The robot ensures alert messages do not persist longer than necessary using a timer mechanism. When an alert is triggered, a timer is initialized in the TriggerAlert method to last for two minutes. The timer setup involves associating its Elapsed event with the RemoveAlert method, which clears the alert message and stops the timer once the time elapses. This automated mechanism prevents alert messages from cluttering the interface beyond the necessary duration, promoting a cleaner and less distracting user interface .
The robot handles visual representation of alert conditions by drawing graphical elements on the chart. When an alert is set, a horizontal line is drawn at the alert point using Chart.DrawHorizontalLine, with parameters for color, thickness, and line style. Additionally, a text label showing the alert price is added with Chart.DrawText, positioned at the alert line's Y-coordinate on the chart. This visual setup ensures that users can immediately see where the alert conditions apply in relation to the current market price, enhancing situational awareness and decision-making .
The alert initiation process begins in the OnTick method, which runs on every tick update. It checks if AlertPointEnabled is true and whether the current price is within a specified range relative to the alert point, adjusted by the PriceOffset. If these conditions are met, TriggerAlert is called, which plays a sound file using Notifications.PlaySound and updates a grid TextBlock with the alert message. Additionally, TriggerAlert sets up a timer via System.Timers.Timer to remove the alert message after two minutes. This cleanup process is completed in the RemoveAlert method, which clears the message and stops the timer, maintaining a clean user interface .