// XSCZones *mLastHindZones; XSCZones *mLastLongZones; XSCZones *mLastMediumZones; // bool DoEQMProtectOfSupports() { // bool result = false; // // The Senario is When all Signals are Support and Account in Drawdown // here we have to Do some Support Actions ... // XPosition positions[]; int positionsCount = mTrader.GetPositions(positions); result = IsValidSize(positionsCount); if (!result) { return result; } // // Noe We Have to Separate Support Positions ... XPosition supports[]; int supportsCount = ExtractSupportPositions( positions, supports // ); result = IsValidSize(supportsCount); if (!result) { return result; } // // Now We Are sure we have Support Positions ... // then we must Check the Supports are Long enough to make the Support ... XPosition youngest; int youngestAge = GetYoungest( youngest, supports // ); result = youngestAge > 2; if (!result) { return result; } // // Try to Find Youngest Support's Setup ... int setupIDX = FindSetupIndex( youngest.symbol // ); result = IsValidIndex(setupIDX); if (!result) { return result; } // // Now we can Implememnt Support of Supports based on // Several Senarios ... // 1. Recieve Market Conditions; // 2. Recieve Summary of Long Verifications and Short Verifications; // 3. Collect VolumeOSC and also Bullish and Bearish Scores; // 4. Collect XSCZones of Last HIND Market; // // Hind Zone ... if (mLastHindZones == NULL) { // mLastHindZones = mSetups[setupIDX].GetZones( X_MARKET_CYCLE_HIND // ); result = mLastHindZones != NULL; if (!result) { return result; } // result = mLastHindZones.DrawZones(0, "HIN"); if (result) { Print("Zone Drawn ..."); } } // // Long Zone ... if (mLastLongZones == NULL) { // mLastLongZones = mSetups[setupIDX].GetZones( X_MARKET_CYCLE_LONG // ); result = mLastLongZones != NULL; if (!result) { return result; } // result = mLastLongZones.DrawZones(0, "LON"); if (result) { Print("Zone Drawn ..."); } } // // Medium Zone ... if (mLastMediumZones == NULL) { // mLastMediumZones = mSetups[setupIDX].GetZones( X_MARKET_CYCLE_MEDIUM // ); result = mLastMediumZones != NULL; if (!result) { return result; } // result = mLastMediumZones.DrawZones(0, "MED"); if (result) { Print("Zone Drawn ..."); } } // return result; } //////////////////////////////////////////////////////////////////////////////// // // XPosition Pack ... // // Extract specific Positions Pack ... // in this senario there is no need to Position exists itself ... bool GetPositionPack( ulong ticket, // Specified Positions Ticket string symbol, // Specified Position Symbol ENUM_TIMEFRAMES period, // Specified Position Period XPositionPack &pack // Hold Result ) { // bool result = false; // pack.Clean(); // XPosition position; bool hasPosition = GetPosition( ticket, position // ); if (hasPosition) { pack.position = position; } // XOrder supportOrders[]; XPosition supportPositions[]; // XOrder orders[]; GetOrders( orders, symbol, // Specified Symbol NULL, // All Providers period, // Specified Period NULL, // All Types ORDER_STATE_PLACED, // Just UnTriggered Orders true // Filter by Magic ); int ordersCount = ArraySize(orders); // // Select Orders ... if (ordersCount > 0) { // for (int i = 0; i < ordersCount; i++) { // XOrder iOrder = orders[i]; // // Retrieve Order Supported Ticket ... ulong parentTicket = ExtractSupportedTicket(iOrder.comment); if (NotEmpty(parentTicket) && parentTicket == ticket) { // AddRef( iOrder, supportOrders // ); } } } // int supportOrdersCount = ArraySize(supportOrders); if (supportOrdersCount > 0) { // pack.supportOrdersCount = supportOrdersCount; // Copy( supportOrders, pack.supportOrders); } // XPosition positions[]; GetPositions( positions, symbol, // Specified Symbol ... NULL, // All Providers ... period // Specified Period ... ); int positionsCount = ArraySize(positions); // // Select Positions ... if (positionsCount > 0) { // for (int i = 0; i < positionsCount; i++) { // XPosition iPosition = positions[i]; // ulong parentTicket = ExtractSupportedTicket(iPosition.comment); if (NotEmpty(parentTicket) && parentTicket == ticket) { // AddRef( iPosition, supportPositions // ); } } } // int supportPositionsCount = ArraySize(supportPositions); if (supportPositionsCount > 0) { // pack.supportPositionsCount = supportPositionsCount; // Copy( supportPositions, pack.supportPositions); } // result = pack.IsValid(); // return result; } // // Close Position Pack ... bool ClosePositionPack( XPositionPack &pack, // Specified Position Pack string comment, // Specified Close Comment bool inProfit = false, // if it's true only close Pack if in profit double minProfitPerTrade = 0, // Min Profit based On Volume Factor ... double minProfitPerVolumeFactor = 0 // Min Volume Factor ... ) { // bool result = false; // ulong ticket = pack.ticket; // XPosition positions[]; // XPosition pPosition; result = GetPosition( ticket, pPosition // ); if (result) { // AddRef( pPosition, positions // ); } // if (pack.supportPositionsCount > 0) { // for (int i = 0; i < pack.supportPositionsCount; i++) { // XPosition iPosition = pack.supportPositions[i]; // AddRef( iPosition, positions // ); } } // // Force Close ... if (!inProfit) { // int closed = Close( positions, comment // ); // int cancelled = 0; if (pack.supportOrdersCount > 0) { cancelled = CancelOrders(pack.supportOrders); } // result = (closed + cancelled) == (pack.supportPositionsCount + pack.supportOrdersCount + 1); } else { // bool canHedge = SpecifiedIsPositionsReadyForHedge( positions, minProfitPerTrade, minProfitPerVolumeFactor // ); if (canHedge) { // int closed = Close( positions, comment // ); // int cancelled = 0; if (pack.supportOrdersCount > 0) { cancelled = CancelOrders(pack.supportOrders); } // result = (closed + cancelled) == (pack.supportPositionsCount + pack.supportOrdersCount + 1); } else { result = false; } } // return result; } bool ClosePositionPack( ulong ticket, // Specified Position Pack string symbol, // Specified Position Symbol ENUM_TIMEFRAMES period, // Specified Position Period string comment, // Specified Close Comment bool inProfit = false, // if it's true only close Pack if in profit double minProfitPerTrade = 0, // Min Profit based On Volume Factor ... double minProfitPerVolumeFactor = 0 // Min Volume Factor ... ) { // bool result = false; // XPositionPack pack; result = GetPositionPack( ticket, symbol, period, pack // ); if (!result) { return result; } // result = ClosePositionPack( pack, comment, inProfit, minProfitPerTrade, minProfitPerVolumeFactor // ); // return result; } // // Close Positions Pack ... int ClosePositionsPack( XPosition &positions[], // Positions ... string comment, // Specified Close Comment bool inProfit = false, // if it's true only close Pack if in profit double minProfitPerTrade = 0, // Min Profit based On Volume Factor ... double minProfitPerVolumeFactor = 0 // Min Volume Factor ... ) { // int result = 0; // int positionsCount = ArraySize(positions); if (positionsCount <= 0) { return result; } // for (int i = 0; i < positionsCount; i++) { // XPosition iPosition = positions[i]; // bool isClosed = ClosePositionPack( iPosition.ticket, iPosition.symbol, iPosition.period, comment, inProfit, minProfitPerTrade, minProfitPerVolumeFactor // ); if (isClosed) { result++; } } // return result; }