I 1311 is the new trade and 1318 is the existing trade.
I want to make sure that the entry of the new trade is not between the entry and stoploss of the existing trade, and I want to make sure the entry of the existing trade is not between the entryand stoploss of the new trade
Assistant
To ensure that the entry of the new trade is not between the entry and stop loss of the existing trade—and vice versa—we need to compare the prices appropriately.
Let's define:
Existing Trade (Trade 1318):
Entry Price: E1
Stop Loss: S1
New Trade (Trade 1311):
Entry Price: E2
Stop Loss: S2
Understanding the Price Ranges
Range of Existing Trade: Between E1 and S1
Range of New Trade: Between E2 and S2
Note: The range can be ascending or descending based on whether the trade is long or short.
Conditions to Ensure No Overlap
1. New Trade's Entry Price Not Between Existing Trade's Entry and Stop Loss
We want to ensure that E2 is not between E1 and S1.
if (E2 <= min(E1, S1) or E2 >= max(E1, S1)) and (E1 <= min(E2, S2) or E1 >= max(E2, S2)) then
// No overlap between entries and stop losses
proceed with the new trade
else
// There is an overlap
handle overlap (e.g., adjust entry prices, skip trade, etc.)
Key Takeaways
Ensure Entry Prices Are Outside Each Other's Range: By checking that the entry price of one trade is not within the range defined by the entry and stop loss of the other trade.
Use Min and Max Functions: This accounts for whether the trades are long or short and whether the price ranges are ascending or descending.
Avoid Overlaps: This method prevents potential conflicts or unintended risks associated with overlapping trades.
Feel free to replace E1, S1, E2, and S2 with the actual values from your trades to verify the conditions.