// 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; } ///////////////////////////////////////////////////////////// // // Long Support ... bool canLongSupport = // volumeOSC > 5 && bullishScore > bearishScore && ArraySize(longProviders) >= 2 && bearishScore reqValidation * 3 // ; if (canLongSupport) { // bool isPrepared = tmpSignal.Prepare( iPosition.symbol, iPosition.provider, iPosition.period, POSITION_TYPE_BUY, X_ORDER_MODE_MARKET, longEntry, mVolume // ); // if (isPrepared) { // tmpSignal.positionId = iPosition.ticket; string comment = GenerateSupportTag(iPosition.ticket); tmpSignal.comment = comment; // AddRef( tmpSignal, signals // ); // tmpSignal.Clean(); } // isPrepared = tmpSignal.Prepare( iPosition.symbol, iPosition.provider, iPosition.period, POSITION_TYPE_SELL, X_ORDER_MODE_MARKET, shortEntry, mVolume // ); // if (isPrepared) { // tmpSignal.positionId = iPosition.ticket; string comment = GenerateSupportTag(iPosition.ticket); tmpSignal.comment = comment; // AddRef( tmpSignal, signals // ); // tmpSignal.Clean(); } } // // Short Support ... bool canShortSupport = // volumeOSC < -5 && bearishScore > bullishScore && ArraySize(shortProviders) >= 2 && bullishScore reqValidation * 3 // ; if (canShortSupport) { // bool isPrepared = tmpSignal.Prepare( iPosition.symbol, iPosition.provider, iPosition.period, POSITION_TYPE_SELL, X_ORDER_MODE_MARKET, shortEntry, mVolume // ); // if (isPrepared) { // tmpSignal.positionId = iPosition.ticket; string comment = GenerateSupportTag(iPosition.ticket); tmpSignal.comment = comment; // AddRef( tmpSignal, signals // ); // tmpSignal.Clean(); } // isPrepared = tmpSignal.Prepare( iPosition.symbol, iPosition.provider, iPosition.period, POSITION_TYPE_BUY, X_ORDER_MODE_MARKET, longEntry, mVolume // ); // if (isPrepared) { // tmpSignal.positionId = iPosition.ticket; string comment = GenerateSupportTag(iPosition.ticket); tmpSignal.comment = comment; // AddRef( tmpSignal, signals // ); // tmpSignal.Clean(); } } // // If no Support Presents ... if (!canLongSupport && !canShortSupport) { // // RemoveDraws("MED"); // RemoveDraws("LON"); // RemoveDraws("HND"); AddHotLevelsToZones(mZones); AddHotLevelsToZones(lZones); AddHotLevelsToZones(hZones); // bool isPrepared = tmpSignal.Prepare( iPosition.symbol, iPosition.provider, iPosition.period, POSITION_TYPE_BUY, X_ORDER_MODE_MARKET, longEntry, iPosition.volume // ); if (isPrepared) { // tmpSignal.positionId = iPosition.ticket; string comment = GenerateSupportTag(iPosition.ticket); tmpSignal.comment = comment; // AddRef( tmpSignal, signals // ); // tmpSignal.Clean(); } // isPrepared = tmpSignal.Prepare( iPosition.symbol, iPosition.provider, iPosition.period, POSITION_TYPE_SELL, X_ORDER_MODE_MARKET, shortEntry, iPosition.volume // ); if (isPrepared) { // tmpSignal.positionId = iPosition.ticket; string comment = GenerateSupportTag(iPosition.ticket); tmpSignal.comment = comment; // AddRef( tmpSignal, signals // ); // tmpSignal.Clean(); } // // bool isDrawn = mZones.DrawZones(0, "MED"); // if (isDrawn) // { // // // isDrawn = false; // RemoveDraws("MED"); // } // // // isDrawn = lZones.DrawZones(0, "LON"); // if (isDrawn) // { // // // isDrawn = false; // RemoveDraws("LON"); // } // // // isDrawn = hZones.DrawZones(0, "HND"); // if (isDrawn) // { // // // isDrawn = false; // RemoveDraws("HND"); // } // // // isDrawn = mZones.DrawZones(0, "MED"); // isDrawn = lZones.DrawZones(0, "LON"); // isDrawn = hZones.DrawZones(0, "HND"); // if (isDrawn) // { // // // isDrawn = false; // // RemoveDraws("MED"); // // RemoveDraws("LON"); // // RemoveDraws("HND"); // } } // // Now Check Position SUpports ... XPosition iSupports[]; int iSupportsCount = mTrader.GetSupports( iPosition.ticket, iSupports // ); bool isFirst = !IsValidSize(iSupportsCount); bool canSupport = isFirst || iSupportsCount < 3; if (!canSupport) { continue; } // // Now Check Signals For not Exists ... int signalsCount = ArraySize(signals); if (IsValidSize(signalsCount)) { // bool isInserted = false; for (int j = 0; j < signalsCount; j++) { // isInserted = signals[j].positionId == iPosition.ticket; if (isInserted) { break; } } // if (isInserted) { continue; } } // // First Try to Get Market State ... // double bullishScore = 0; double bearishScore = 0; double tmpBullishScore = 0; double tmpBearishScore = 0; // // Max Verifications is 11 ... int reqValidation = 6; int longVerifications = 0; int shortVerifications = 0; // // Pushers ... int longPushers = 0; int shortPushers = 0; int tmpLongPushers = 0; int tmpShortPushers = 0; // string tmpProvider; string longProviders[]; string shortProviders[]; // double volumeOSC = 0; // // Current ... X121SetupConditions cConditions; bool cHasConditions = setups[idx].GetConditions( cConditions, X_MARKET_CYCLE_UNKNOWN // ); if (!cHasConditions) { continue; } bool isCValidForLong = signalGenerator.IsConditionsValidForLong( cConditions, reqValidation // ); if (isCValidForLong) { longVerifications += reqValidation; } bool isCValidForShort = signalGenerator.IsConditionsValidForShort( cConditions, reqValidation // ); if (isCValidForShort) { shortVerifications += reqValidation; } bool cHasLongConditions = signalGenerator.HasLongConditions( cConditions, tmpLongPushers, tmpProvider // ); if (cHasLongConditions) { // AddSpecific( tmpProvider, longProviders // ); // longPushers += tmpLongPushers; } bool cHasShortConditions = signalGenerator.HasShortConditions( cConditions, tmpShortPushers, tmpProvider // ); if (cHasShortConditions) { // AddSpecific( tmpProvider, shortProviders // ); // shortPushers += tmpShortPushers; } volumeOSC += cConditions.vlmConditions.volume[1]; cConditions.GenerateScore( tmpBullishScore, tmpBearishScore // ); bullishScore += tmpBullishScore; bearishScore += tmpBearishScore; // // Short ... X121SetupConditions sConditions; bool sHasConditions = setups[idx].GetConditions( sConditions, X_MARKET_CYCLE_SHORT // ); if (!sHasConditions) { continue; } bool isSValidForLong = signalGenerator.IsConditionsValidForLong( sConditions, reqValidation // ); if (isSValidForLong) { longVerifications += reqValidation; } bool isSValidForShort = signalGenerator.IsConditionsValidForShort( sConditions, reqValidation // ); if (isSValidForShort) { shortVerifications += reqValidation; } bool sHasLongConditions = signalGenerator.HasLongConditions( sConditions, tmpLongPushers, tmpProvider // ); if (sHasLongConditions) { // AddSpecific( tmpProvider, longProviders // ); // longPushers += tmpLongPushers; } bool sHasShortConditions = signalGenerator.HasShortConditions( sConditions, tmpShortPushers, tmpProvider // ); if (sHasShortConditions) { // AddSpecific( tmpProvider, shortProviders // ); // shortPushers += tmpShortPushers; } volumeOSC += sConditions.vlmConditions.volume[1]; sConditions.GenerateScore( tmpBullishScore, tmpBearishScore // ); bullishScore += tmpBullishScore; bearishScore += tmpBearishScore; // // Medium ... X121SetupConditions mConditions; bool mHasConditions = setups[idx].GetConditions( mConditions, X_MARKET_CYCLE_MEDIUM // ); if (!mHasConditions) { continue; } XSCZones *mZones = setups[idx].GetZones( X_MARKET_CYCLE_MEDIUM // ); bool isMValidForLong = signalGenerator.IsConditionsValidForLong( mConditions, reqValidation // ); if (isMValidForLong) { longVerifications += reqValidation; } bool isMValidForShort = signalGenerator.IsConditionsValidForShort( mConditions, reqValidation // ); if (isMValidForShort) { shortVerifications += reqValidation; } bool mHasLongConditions = signalGenerator.HasLongConditions( mConditions, tmpLongPushers, tmpProvider // ); if (mHasLongConditions) { // AddSpecific( tmpProvider, longProviders // ); // longPushers += tmpLongPushers; } bool mHasShortConditions = signalGenerator.HasShortConditions( mConditions, tmpShortPushers, tmpProvider // ); if (mHasShortConditions) { // AddSpecific( tmpProvider, shortProviders // ); // shortPushers += tmpShortPushers; } volumeOSC += mConditions.vlmConditions.volume[1]; mConditions.GenerateScore( tmpBullishScore, tmpBearishScore // ); bullishScore += tmpBullishScore; bearishScore += tmpBearishScore; // // Long ... X121SetupConditions lConditions; bool lHasConditions = setups[idx].GetConditions( lConditions, X_MARKET_CYCLE_LONG // ); if (!lHasConditions) { continue; } XSCZones *lZones = setups[idx].GetZones( X_MARKET_CYCLE_LONG // ); bool isLValidForLong = signalGenerator.IsConditionsValidForLong( lConditions, reqValidation // ); if (isLValidForLong) { longVerifications += reqValidation; } bool isLValidForShort = signalGenerator.IsConditionsValidForShort( lConditions, reqValidation // ); if (isLValidForShort) { shortVerifications += reqValidation; } bool lHasLongConditions = signalGenerator.HasLongConditions( lConditions, tmpLongPushers, tmpProvider // ); if (lHasLongConditions) { // AddSpecific( tmpProvider, longProviders // ); // longPushers += tmpLongPushers; } bool lHasShortConditions = signalGenerator.HasShortConditions( lConditions, tmpShortPushers, tmpProvider // ); if (lHasShortConditions) { // AddSpecific( tmpProvider, shortProviders // ); // shortPushers += tmpShortPushers; } volumeOSC += lConditions.vlmConditions.volume[1]; lConditions.GenerateScore( tmpBullishScore, tmpBearishScore // ); bullishScore += tmpBullishScore; bearishScore += tmpBearishScore; // // Hind ... X121SetupConditions hConditions; bool hHasConditions = setups[idx].GetConditions( hConditions, X_MARKET_CYCLE_HIND // ); if (!hHasConditions) { continue; } XSCZones *hZones = setups[idx].GetZones( X_MARKET_CYCLE_HIND // ); bool isHValidForLong = signalGenerator.IsConditionsValidForLong( hConditions, reqValidation // ); if (isHValidForLong) { longVerifications += reqValidation; } bool isHValidForShort = signalGenerator.IsConditionsValidForShort( hConditions, reqValidation // ); if (isHValidForShort) { shortVerifications += reqValidation; } bool hHasLongConditions = signalGenerator.HasLongConditions( hConditions, tmpLongPushers, tmpProvider // ); if (hHasLongConditions) { // AddSpecific( tmpProvider, longProviders // ); // longPushers += tmpLongPushers; } bool hHasShortConditions = signalGenerator.HasShortConditions( hConditions, tmpShortPushers, tmpProvider // ); if (hHasShortConditions) { // AddSpecific( tmpProvider, shortProviders // ); // shortPushers += tmpShortPushers; } volumeOSC += hConditions.vlmConditions.volume[1]; hConditions.GenerateScore( tmpBullishScore, tmpBearishScore // ); bullishScore += tmpBullishScore; bearishScore += tmpBearishScore; //////////////////////////////////////////////////////// // // Place EQM Orders ... void PlaceEQMOrders() { // int count = CountSetups(); if (!IsValidSize(count)) { return; } // XSignal supports[]; // for (int i = 0; i < count; i++) { // string iSymbol = mSetups[i].GetSymbol(); ENUM_TIMEFRAMES iPeriod = NULL; // All Periods ... string iProvider = NULL; // All Providers ... // XPosition iPositions[]; int iPositionsCount = mTrader.GetPositions( iPositions, iSymbol, iProvider, iPeriod, X_POSITION_TYPE_ALL // ); if (!IsValidSize(iPositionsCount)) { continue; } // int maxInDIDX = FindMaxDrawdownIndex( iPositions // ); if (!IsValidIndex(maxInDIDX)) { continue; } // XPosition maxInDP = iPositions[maxInDIDX]; bool isLong = IsLong(maxInDP.type); // XOHCL iZBar; bool isInited = iZBar.Init( iSymbol, iPeriod, 0 // ); if (!isInited) { continue; } // double iSupport = 0; double iResistance = 0; bool isDrawn = DrawTrendState( ChartID(), "XTRND", iZBar, iSupport, iResistance // ); if (isDrawn) { // XSignal iSignal; // double iSL = 0; double iTP = 0; double iEntry = 0; ENUM_POSITION_TYPE iType; ENUM_X_ORDER_MODES iMode; double iVolume = maxInDP.volume * 3; // if (iSupport > 0 && isLong && iSupport > maxInDP.sl && maxInDP.sl > 0) { // // Add Short Support for Long ... iEntry = iSupport; iSL = maxInDP.tp; iTP = maxInDP.sl; iMode = X_ORDER_MODE_STOP; iType = POSITION_TYPE_SELL; // bool isPrepared = iSignal.Prepare( iSymbol, XEQMSupportToken, iPeriod, iType, iMode, iEntry, iVolume, iSL, iTP // ); if (isPrepared) { // iSignal.comment = GenerateSupportTag(maxInDP.ticket); // AddRef( iSignal, supports /// ); // iSignal.Clean(); } } // if (iResistance > 0 && !isLong && iResistance < maxInDP.sl && maxInDP.sl > 0) { // // Add Long Support for Short ... iEntry = iResistance; iSL = maxInDP.tp; iTP = maxInDP.sl; iMode = X_ORDER_MODE_STOP; iType = POSITION_TYPE_BUY; // bool isPrepared = iSignal.Prepare( iSymbol, XEQMSupportToken, iPeriod, iType, iMode, iEntry, iVolume, iSL, iTP // ); if (isPrepared) { // iSignal.comment = GenerateSupportTag(maxInDP.ticket); // AddRef( iSignal, supports /// ); // iSignal.Clean(); } } } } // int supportsCount = ArraySize(supports); if (!IsValidSize(supportsCount)) { return; } // ENUM_X_SIGNAL_EXECUTION_RESULT states[]; int executeds = mTrader.ExecuteSignals( supports, states, ORDER_TIME_GTC, false, false // Ignore Policies ); if (IsValidSize(executeds)) { // string message = XEQMSupportToken + " Execute " + ToString(executeds) + " Supports ..."; // Alert(message); } } ///////////////////////////////////////////////////////// // // // XSignal tmpSignal; // tmpSignal.Clean(); // // // double longEntry = GetEntry( // iPosition.symbol, // POSITION_TYPE_BUY // // ); // double shortEntry = GetEntry( // iPosition.symbol, // POSITION_TYPE_SELL // // ); // double mVolume = iPosition.volume * 2; // double mSL = 0; // double mTP = 0; // // // bool isLong = IsLong(iPosition.type); // // // // Here we Can Start a Recovery Zone ... // if (data[index].rLongEntry <= 0 && // data[index].rShortEntry <= 0 && // data[index].rVolume <= 0) // { // // // data[index].PrepareNextRecovery( // supportDistance, // volumeMultiplier, // iPosition.type // // ); // } // else // { // // // bool hasRecovery = data[index].HasRecovery( // tmpSignal, // supportDistance, // volumeMultiplier // // ); // if (hasRecovery) // { // // // // tmpSignal.sl = 0; // // tmpSignal.tp = 0; // string comment = GenerateEQMSupportTag(iPosition.ticket); // tmpSignal.comment = comment; // // // AddRef( // tmpSignal, // signals // // ); // } // else if (priceDiffPoints >= supportDistance) // { // // // // Reset // if (longEntry > data[index].rZoneUpper || shortEntry < data[index].rZoneLower) // { // // // // data[index].ResetRecovery(); // // // } // } // } /////////////////////////////////////////////////////////////// // // Create an Instance of Signal Generator Structure ... X121SignalGenerator signalGenerator; // int signalConditionsIDX = FindSignalConditionsIndex( signal, conditions // ); if (!IsValidIndex(signalConditionsIDX)) { return; } // int longValidations = 0; int shortValidations = 0; // bool isOSCValidForLong = signalGenerator .IsOSCLongVerified(conditions[signalConditionsIDX]); bool isOSCValidForShort = signalGenerator .IsOSCShortVerified(conditions[signalConditionsIDX]); // // Calculate Long/Short Validations ... for (int i = 0; i < ArraySize(conditions); i++) { // int longValids = signalGenerator .CountLongValidations(conditions[i]); longValidations += longValids; // int shortValids = signalGenerator .CountShortValidations(conditions[i]); shortValidations += shortValids; } // bool isLong = IsLong(signal.type); // // Reading Required Informations ... XPosition positions[]; int positionsCount = mTrader.GetPositions(positions); if (!IsValidSize(positionsCount)) { return; } // int longs = 0; double longVolumes = 0; double longProfits = 0; // int shorts = 0; double shortVolumes = 0; double shortProfits = 0; // // Retrieve Required Informations of Positions ... CountPositions( positions, longs, longProfits, longVolumes, shorts, shortProfits, shortVolumes // ); // longVolumes = NormalizeDouble(longVolumes, 2); shortVolumes = NormalizeDouble(shortVolumes, 2); // // Select Signal for Execution ... bool canSelect = // ((isLong && longProfits > 0 && bullishScore > 20) // || // (!isLong && shortProfits > 0 && bearishScore > 0)) // && // longVolumes == shortVolumes // ; if (canSelect) { // // Here we Can do Signals SL TP Manipulations ... signal.tp = 0; signal.sl = 0; // XSignal signals[]; AddRef( signal, signals // ); // // Add new Signal Info ... mTradeHandler.Add( signal, pushers, volumeOSC, bullishSigns, bearishSigns, bullishScore, bearishScore, conditions[0], conditions[1], conditions[2], conditions[3], conditions[4] // ); // EQMExecuteSignals(signals); // return; } // canSelect = // ((isLong && shortProfits > 0) || (!isLong && longProfits > 0)) // && // longVolumes == shortVolumes // ; if (canSelect) { // // Generate Opposit Signal ... // signal.tp = 0; signal.sl = 0; // XSignal oppositSignal; bool isGenerated = signal.GenerateOpposit( oppositSignal // ); // if (isGenerated) { // XSignal signals[]; AddRef( oppositSignal, signals // ); // // Add new Signal Info ... mTradeHandler.Add( oppositSignal, pushers, volumeOSC, bullishSigns, bearishSigns, bullishScore, bearishScore, conditions[0], conditions[1], conditions[2], conditions[3], conditions[4] // ); // EQMExecuteSignals(signals); // return; } } //////////////////////////////////////////////////////////////////////// // XPosition positions[]; int positionsCount = mTrader.GetPositions(positions); if (!IsValidSize(positionsCount)) { return; } // int longs = 0; double longVolumes = 0; double longProfits = 0; // int shorts = 0; double shortVolumes = 0; double shortProfits = 0; // // Retrieve Required Informations of Positions ... CountPositions( positions, longs, longProfits, longVolumes, shorts, shortProfits, shortVolumes // ); // longVolumes = NormalizeDouble(longVolumes, 2); shortVolumes = NormalizeDouble(shortVolumes, 2); // if (isValid) { // // Ignore Hind Time Frame Signals ... // signal.volume *= 1; // // Here we Can do Signals SL TP Manipulations ... signal.tp = 0; signal.sl = 0; // signal.provider = XEQMSupportToken; signal.comment = GenerateEQMSupportTag(0); // bool isLong = IsLong(signal.type); // bool canDirect = // (isLong && longProfits > shortProfits) // || // (!isLong && shortProfits > longProfits) // ; bool canInDirect = // (isLong && shortProfits > longProfits) // || // (!isLong && longProfits > shortProfits) // ; // XSignal tmpSignal; if (canDirect) { tmpSignal = signal; } else { // bool isGenerated = signal.GenerateOpposit( tmpSignal // ); // if (!isGenerated) { tmpSignal.Clean(); } } // if (tmpSignal.IsValid()) { // XSignal signals[]; AddRef( signal, signals // ); // // Add new Signal Info ... mTradeHandler.Add( signal, pushers, volumeOSC, bullishSigns, bearishSigns, bullishScore, bearishScore, conditions[0], conditions[1], conditions[2], conditions[3], conditions[4] // ); // EQMExecuteSignals(signals); } return; } ////////////////////////////////////////////////////////////////////// // // // // Check Signal Has TP and SL ... // if (signal.tp > 0 && signal.sl > 0) // { // // // // Here we Can Provide Orders based on Signal TP and SL ... // // // // Calculate TP/Entry Distance ... // double tpDistance = // isLong // ? signal.tp - signal.entry // : signal.entry - signal.tp; // // // // Calculate Recovery Zone Step ... // double slDistance = // isLong // ? signal.entry - signal.sl // : signal.sl - signal.entry; // } // // // // Add Zone Based Signals ... // if (canUseZones) // { // // // // signal.zones.DrawZones(); // // // // Try to Find a Hot Level based on Signal Direction // // as Resistance ... // // // for (int i = 0; i < signal.zones.CountZones(); i++) // { // // // // Retrieve Indexed Zone ... // XSCZone *iZone = signal.zones.GetZone(i); // // // // Check Zone is Hot Zone or not ... // bool isHotZone = false; // for (int j = 0; j < ArraySize(hotLevels); j++) // { // // // isHotZone = (iZone.percent / 100 >= hotLevels[j]); // if (isHotZone) // { // break; // } // } // // // // Prevent Moving Forward if there isn't Hot Zone ... // if (!isHotZone) // { // continue; // } // // // if (iZone.high > signal.entry && iZone.low > signal.entry) // { // // // // Here we can Use Resistance Zone as SL Recovery for // // Short Positions ... // if (!isLong && // (signal.sl <= 0 // ? true // : iZone.high < signal.sl && iZone.low < signal.sl)) // { // // // // Opposit Support on Resistance Upper ... // // // // rTP = signal.sl <= 0 // // ? iZone.high - (onePointValue * 15) // // : signal.sl; // // rSL = signal.entry; // rType = POSITION_TYPE_BUY; // rEntry = iZone.high + (onePointValue * 2); // rMode = X_ORDER_MODE_STOP; // // // isSignalPrepared = rSignal.Prepare( // signal.symbol, // signal.provider, // signal.period, // rType, // rMode, // rEntry, // rVolume, // rSL, // rTP // // ); // if (isSignalPrepared) // { // // // AddRef( // rSignal, // signal.supports // // ); // // // rSignal.Clean(); // // // rSL = 0; // rTP = 0; // rEntry = 0; // isSignalPrepared = false; // } // // // // Support Directional on Resistance Lower ... // // // // rTP = signal.entry; // // rSL = signal.sl <= 0 // // ? signal.entry - (onePointValue * 15) // // : signal.sl; // rEntry = iZone.low - (onePointValue * 2); // rVolume = signal.volume * 3; // rType = POSITION_TYPE_SELL; // rMode = X_ORDER_MODE_LIMIT; // // // isSignalPrepared = rSignal.Prepare( // signal.symbol, // signal.provider, // signal.period, // rType, // rMode, // rEntry, // rVolume, // rSL, // rTP // // ); // if (isSignalPrepared) // { // // // AddRef( // rSignal, // signal.supports // // ); // // // rSignal.Clean(); // // // rSL = 0; // rTP = 0; // rEntry = 0; // isSignalPrepared = false; // rVolume = signal.volume * 2; // } // } // } // // // if (iZone.high < signal.entry && iZone.low < signal.entry) // { // // // } // } // } // // // if (canUseTrend) // { // // // // Check Ask and Bid Price ... // // // XOHCL fHighBar = signal.trend.GetFirstSwingHighBar(); // XOHCL sHighBar = signal.trend.GetSecondSwingHighBar(); // // // XOHCL fLowBar = signal.trend.GetFirstSwingLowBar(); // XOHCL sLowBar = signal.trend.GetSecondSwingLowBar(); // // // double twoPoint = onePointValue * 2; // double fiftyPoint = onePointValue * 15; // // // // add resistance ... // bool canAdd = // isLong && // entryPrice < (sHighBar.high - fiftyPoint); // if (canAdd) // { // // // rSignal.Clean(); // // // rEntry = sHighBar.high - fiftyPoint; // rType = POSITION_TYPE_BUY; // rMode = X_ORDER_MODE_STOP; // rVolume = signal.volume * 2; // // // isSignalPrepared = rSignal.Prepare( // signal.symbol, // signal.provider, // signal.period, // rType, // rMode, // rEntry, // rVolume, // rSL, // rTP // // ); // if (isSignalPrepared) // { // // // AddRef( // rSignal, // signal.supports // // ); // // // rSignal.Clean(); // // // rSL = 0; // rTP = 0; // rEntry = 0; // isSignalPrepared = false; // } // // // rEntry = sHighBar.high - fiftyPoint; // rType = POSITION_TYPE_SELL; // rMode = X_ORDER_MODE_LIMIT; // rVolume = signal.volume * 3; // // // isSignalPrepared = rSignal.Prepare( // signal.symbol, // signal.provider, // signal.period, // rType, // rMode, // rEntry, // rVolume, // rSL, // rTP // // ); // if (isSignalPrepared) // { // // // AddRef( // rSignal, // signal.supports // // ); // // // rSignal.Clean(); // // // rSL = 0; // rTP = 0; // rEntry = 0; // isSignalPrepared = false; // } // } // // // canAdd = // isLong && // entryPrice > (sLowBar.low + fiftyPoint); // if (canAdd) // { // // // rSignal.Clean(); // // // rEntry = (sLowBar.low + fiftyPoint); // rType = POSITION_TYPE_SELL; // rMode = X_ORDER_MODE_STOP; // rVolume = signal.volume * 2; // // // isSignalPrepared = rSignal.Prepare( // signal.symbol, // signal.provider, // signal.period, // rType, // rMode, // rEntry, // rVolume, // rSL, // rTP // // ); // if (isSignalPrepared) // { // // // AddRef( // rSignal, // signal.supports // // ); // // // rSignal.Clean(); // // // rSL = 0; // rTP = 0; // rEntry = 0; // isSignalPrepared = false; // } // // // rEntry = (sLowBar.low - fiftyPoint); // rType = POSITION_TYPE_BUY; // rMode = X_ORDER_MODE_LIMIT; // rVolume = signal.volume * 3; // // // isSignalPrepared = rSignal.Prepare( // signal.symbol, // signal.provider, // signal.period, // rType, // rMode, // rEntry, // rVolume, // rSL, // rTP // // ); // if (isSignalPrepared) // { // // // AddRef( // rSignal, // signal.supports // // ); // // // rSignal.Clean(); // // // rSL = 0; // rTP = 0; // rEntry = 0; // isSignalPrepared = false; // } // } // // // // add support ... // canAdd = // !isLong && // entryPrice > (sLowBar.low + fiftyPoint); // if (canAdd) // { // // // rSignal.Clean(); // // // rEntry = sLowBar.low + fiftyPoint; // rType = POSITION_TYPE_SELL; // rMode = X_ORDER_MODE_STOP; // rVolume = signal.volume * 2; // // // isSignalPrepared = rSignal.Prepare( // signal.symbol, // signal.provider, // signal.period, // rType, // rMode, // rEntry, // rVolume, // rSL, // rTP // // ); // if (isSignalPrepared) // { // // // AddRef( // rSignal, // signal.supports // // ); // // // rSignal.Clean(); // // // rSL = 0; // rTP = 0; // rEntry = 0; // isSignalPrepared = false; // } // // // rEntry = sLowBar.low + fiftyPoint; // rType = POSITION_TYPE_BUY; // rMode = X_ORDER_MODE_LIMIT; // rVolume = signal.volume * 3; // // // isSignalPrepared = rSignal.Prepare( // signal.symbol, // signal.provider, // signal.period, // rType, // rMode, // rEntry, // rVolume, // rSL, // rTP // // ); // if (isSignalPrepared) // { // // // AddRef( // rSignal, // signal.supports // // ); // // // rSignal.Clean(); // // // rSL = 0; // rTP = 0; // rEntry = 0; // isSignalPrepared = false; // } // } // // // canAdd = // !isLong && // entryPrice < (sHighBar.high - fiftyPoint); // if (canAdd) // { // // // rSignal.Clean(); // // // rEntry = (sHighBar.high - fiftyPoint); // rType = POSITION_TYPE_BUY; // rMode = X_ORDER_MODE_STOP; // rVolume = signal.volume * 2; // // // isSignalPrepared = rSignal.Prepare( // signal.symbol, // signal.provider, // signal.period, // rType, // rMode, // rEntry, // rVolume, // rSL, // rTP // // ); // if (isSignalPrepared) // { // // // AddRef( // rSignal, // signal.supports // // ); // // // rSignal.Clean(); // // // rSL = 0; // rTP = 0; // rEntry = 0; // isSignalPrepared = false; // } // // // rEntry = (sHighBar.high - fiftyPoint); // rType = POSITION_TYPE_SELL; // rMode = X_ORDER_MODE_LIMIT; // rVolume = signal.volume * 3; // // // isSignalPrepared = rSignal.Prepare( // signal.symbol, // signal.provider, // signal.period, // rType, // rMode, // rEntry, // rVolume, // rSL, // rTP // // ); // if (isSignalPrepared) // { // // // AddRef( // rSignal, // signal.supports // // ); // // // rSignal.Clean(); // // // rSL = 0; // rTP = 0; // rEntry = 0; // isSignalPrepared = false; // } // } // } /////////////////////////////////////////////////////////////// // // Directional ... rEntry = signal.entry; rType = POSITION_TYPE_SELL; rMode = X_ORDER_MODE_LIMIT; rVolume = signal.volume * directionalVolumeMultiplier; // isSignalPrepared = rSignal.Prepare( signal.symbol, XEQMSupportToken, signal.period, rType, rMode, rEntry, rVolume, rSL, rTP // ); if (isSignalPrepared) { // AddRef( rSignal, signal.supports // ); // rSignal.Clean(); // rSL = 0; rTP = 0; rEntry = 0; isSignalPrepared = false; } // // Directional ... rEntry = signal.entry; rType = POSITION_TYPE_SELL; rMode = X_ORDER_MODE_STOP; rVolume = signal.volume * directionalVolumeMultiplier; // isSignalPrepared = rSignal.Prepare( signal.symbol, XEQMSupportToken, signal.period, rType, rMode, rEntry, rVolume, rSL, rTP // ); if (isSignalPrepared) { // AddRef( rSignal, signal.supports // ); // rSignal.Clean(); // rSL = 0; rTP = 0; rEntry = 0; isSignalPrepared = false; } /////////////////////////////////////////////////////////////////////// // if (canUseCF) { // signal.cf.Draw(); XOHCL cfBULLBar = signal.cf.GetBullishBar(); XOHCL cfBEARBar = signal.cf.GetBearishBar(); // if (isLong) { // // Supports For Longs ... // // CF Bullish ... // // HIGH ... // condition = entryPrice < cfBULLBar.high; if (condition) { // // InDirectional ... rEntry = cfBULLBar.high; rType = POSITION_TYPE_SELL; rMode = X_ORDER_MODE_LIMIT; rVolume = signal.volume * inDirectionalVolumeMultiplier; // isSignalPrepared = rSignal.Prepare( signal.symbol, XEQMSupportToken + XINDirectionalToken, signal.period, rType, rMode, rEntry, rVolume, rSL, rTP // ); if (isSignalPrepared) { // AddRef( rSignal, signal.supports // ); // rSignal.Clean(); // rSL = 0; rTP = 0; rEntry = 0; isSignalPrepared = false; } } // condition = entryPrice > cfBULLBar.high; if (condition) { // // InDirectional ... rEntry = cfBULLBar.high; rType = POSITION_TYPE_SELL; rMode = X_ORDER_MODE_STOP; rVolume = signal.volume * inDirectionalVolumeMultiplier; // isSignalPrepared = rSignal.Prepare( signal.symbol, XEQMSupportToken + XINDirectionalToken, signal.period, rType, rMode, rEntry, rVolume, rSL, rTP // ); if (isSignalPrepared) { // AddRef( rSignal, signal.supports // ); // rSignal.Clean(); // rSL = 0; rTP = 0; rEntry = 0; isSignalPrepared = false; } } // // LOW ... // condition = entryPrice > cfBULLBar.low; if (condition) { // // InDirectional ... rEntry = cfBULLBar.low; rType = POSITION_TYPE_SELL; rMode = X_ORDER_MODE_STOP; rVolume = signal.volume * inDirectionalVolumeMultiplier; // isSignalPrepared = rSignal.Prepare( signal.symbol, XEQMSupportToken + XINDirectionalToken, signal.period, rType, rMode, rEntry, rVolume, rSL, rTP // ); if (isSignalPrepared) { // AddRef( rSignal, signal.supports // ); // rSignal.Clean(); // rSL = 0; rTP = 0; rEntry = 0; isSignalPrepared = false; } } // condition = entryPrice < cfBULLBar.low; if (condition) { // // InDirectional ... rEntry = cfBULLBar.low; rType = POSITION_TYPE_SELL; rMode = X_ORDER_MODE_LIMIT; rVolume = signal.volume * inDirectionalVolumeMultiplier; // isSignalPrepared = rSignal.Prepare( signal.symbol, XEQMSupportToken + XINDirectionalToken, signal.period, rType, rMode, rEntry, rVolume, rSL, rTP // ); if (isSignalPrepared) { // AddRef( rSignal, signal.supports // ); // rSignal.Clean(); // rSL = 0; rTP = 0; rEntry = 0; isSignalPrepared = false; } } // // CF Bearish ... // // HIGH ... // condition = entryPrice < cfBEARBar.high; if (condition) { // // InDirectional ... rEntry = cfBEARBar.high; rType = POSITION_TYPE_SELL; rMode = X_ORDER_MODE_LIMIT; rVolume = signal.volume * inDirectionalVolumeMultiplier; // isSignalPrepared = rSignal.Prepare( signal.symbol, XEQMSupportToken + XINDirectionalToken, signal.period, rType, rMode, rEntry, rVolume, rSL, rTP // ); if (isSignalPrepared) { // AddRef( rSignal, signal.supports // ); // rSignal.Clean(); // rSL = 0; rTP = 0; rEntry = 0; isSignalPrepared = false; } } // condition = entryPrice > cfBEARBar.high; if (condition) { // // InDirectional ... rEntry = cfBEARBar.high; rType = POSITION_TYPE_SELL; rMode = X_ORDER_MODE_STOP; rVolume = signal.volume * inDirectionalVolumeMultiplier; // isSignalPrepared = rSignal.Prepare( signal.symbol, XEQMSupportToken + XINDirectionalToken, signal.period, rType, rMode, rEntry, rVolume, rSL, rTP // ); if (isSignalPrepared) { // AddRef( rSignal, signal.supports // ); // rSignal.Clean(); // rSL = 0; rTP = 0; rEntry = 0; isSignalPrepared = false; } } // // LOW ... // condition = entryPrice > cfBEARBar.low; if (condition) { // // InDirectional ... rEntry = cfBEARBar.low; rType = POSITION_TYPE_SELL; rMode = X_ORDER_MODE_STOP; rVolume = signal.volume * inDirectionalVolumeMultiplier; // isSignalPrepared = rSignal.Prepare( signal.symbol, XEQMSupportToken + XINDirectionalToken, signal.period, rType, rMode, rEntry, rVolume, rSL, rTP // ); if (isSignalPrepared) { // AddRef( rSignal, signal.supports // ); // rSignal.Clean(); // rSL = 0; rTP = 0; rEntry = 0; isSignalPrepared = false; } } // condition = entryPrice < cfBEARBar.low; if (condition) { // // InDirectional ... rEntry = cfBEARBar.low; rType = POSITION_TYPE_SELL; rMode = X_ORDER_MODE_LIMIT; rVolume = signal.volume * inDirectionalVolumeMultiplier; // isSignalPrepared = rSignal.Prepare( signal.symbol, XEQMSupportToken + XINDirectionalToken, signal.period, rType, rMode, rEntry, rVolume, rSL, rTP // ); if (isSignalPrepared) { // AddRef( rSignal, signal.supports // ); // rSignal.Clean(); // rSL = 0; rTP = 0; rEntry = 0; isSignalPrepared = false; } } } else { // // Supports For Shorts ... // // CF Bullish ... // // HIGH ... // condition = entryPrice < cfBULLBar.high; if (condition) { // // InDirectional ... rEntry = cfBULLBar.high; rType = POSITION_TYPE_BUY; rMode = X_ORDER_MODE_STOP; rVolume = signal.volume * inDirectionalVolumeMultiplier; // isSignalPrepared = rSignal.Prepare( signal.symbol, XEQMSupportToken + XINDirectionalToken, signal.period, rType, rMode, rEntry, rVolume, rSL, rTP // ); if (isSignalPrepared) { // AddRef( rSignal, signal.supports // ); // rSignal.Clean(); // rSL = 0; rTP = 0; rEntry = 0; isSignalPrepared = false; } } // condition = entryPrice > cfBULLBar.high; if (condition) { // // InDirectional ... rEntry = cfBULLBar.high; rType = POSITION_TYPE_BUY; rMode = X_ORDER_MODE_LIMIT; rVolume = signal.volume * inDirectionalVolumeMultiplier; // isSignalPrepared = rSignal.Prepare( signal.symbol, XEQMSupportToken + XINDirectionalToken, signal.period, rType, rMode, rEntry, rVolume, rSL, rTP // ); if (isSignalPrepared) { // AddRef( rSignal, signal.supports // ); // rSignal.Clean(); // rSL = 0; rTP = 0; rEntry = 0; isSignalPrepared = false; } } // // LOW ... // condition = entryPrice > cfBULLBar.low; if (condition) { // // InDirectional ... rEntry = cfBULLBar.low; rType = POSITION_TYPE_BUY; rMode = X_ORDER_MODE_LIMIT; rVolume = signal.volume * inDirectionalVolumeMultiplier; // isSignalPrepared = rSignal.Prepare( signal.symbol, XEQMSupportToken + XINDirectionalToken, signal.period, rType, rMode, rEntry, rVolume, rSL, rTP // ); if (isSignalPrepared) { // AddRef( rSignal, signal.supports // ); // rSignal.Clean(); // rSL = 0; rTP = 0; rEntry = 0; isSignalPrepared = false; } } // condition = entryPrice < cfBULLBar.low; if (condition) { // // InDirectional ... rEntry = cfBULLBar.low; rType = POSITION_TYPE_BUY; rMode = X_ORDER_MODE_STOP; rVolume = signal.volume * inDirectionalVolumeMultiplier; // isSignalPrepared = rSignal.Prepare( signal.symbol, XEQMSupportToken + XINDirectionalToken, signal.period, rType, rMode, rEntry, rVolume, rSL, rTP // ); if (isSignalPrepared) { // AddRef( rSignal, signal.supports // ); // rSignal.Clean(); // rSL = 0; rTP = 0; rEntry = 0; isSignalPrepared = false; } } // // CF Bearish ... // // HIGH ... // condition = entryPrice < cfBEARBar.high; if (condition) { // // InDirectional ... rEntry = cfBEARBar.high; rType = POSITION_TYPE_BUY; rMode = X_ORDER_MODE_STOP; rVolume = signal.volume * inDirectionalVolumeMultiplier; // isSignalPrepared = rSignal.Prepare( signal.symbol, XEQMSupportToken + XINDirectionalToken, signal.period, rType, rMode, rEntry, rVolume, rSL, rTP // ); if (isSignalPrepared) { // AddRef( rSignal, signal.supports // ); // rSignal.Clean(); // rSL = 0; rTP = 0; rEntry = 0; isSignalPrepared = false; } } // condition = entryPrice > cfBEARBar.high; if (condition) { // // InDirectional ... rEntry = cfBEARBar.high; rType = POSITION_TYPE_BUY; rMode = X_ORDER_MODE_LIMIT; rVolume = signal.volume * inDirectionalVolumeMultiplier; // isSignalPrepared = rSignal.Prepare( signal.symbol, XEQMSupportToken + XINDirectionalToken, signal.period, rType, rMode, rEntry, rVolume, rSL, rTP // ); if (isSignalPrepared) { // AddRef( rSignal, signal.supports // ); // rSignal.Clean(); // rSL = 0; rTP = 0; rEntry = 0; isSignalPrepared = false; } } // // LOW ... // condition = entryPrice > cfBEARBar.low; if (condition) { // // InDirectional ... rEntry = cfBEARBar.low; rType = POSITION_TYPE_BUY; rMode = X_ORDER_MODE_LIMIT; rVolume = signal.volume * inDirectionalVolumeMultiplier; // isSignalPrepared = rSignal.Prepare( signal.symbol, XEQMSupportToken + XINDirectionalToken, signal.period, rType, rMode, rEntry, rVolume, rSL, rTP // ); if (isSignalPrepared) { // AddRef( rSignal, signal.supports // ); // rSignal.Clean(); // rSL = 0; rTP = 0; rEntry = 0; isSignalPrepared = false; } } // condition = entryPrice < cfBEARBar.low; if (condition) { // // InDirectional ... rEntry = cfBEARBar.low; rType = POSITION_TYPE_BUY; rMode = X_ORDER_MODE_STOP; rVolume = signal.volume * inDirectionalVolumeMultiplier; // isSignalPrepared = rSignal.Prepare( signal.symbol, XEQMSupportToken + XINDirectionalToken, signal.period, rType, rMode, rEntry, rVolume, rSL, rTP // ); if (isSignalPrepared) { // AddRef( rSignal, signal.supports // ); // rSignal.Clean(); // rSL = 0; rTP = 0; rEntry = 0; isSignalPrepared = false; } } } } //////////////////////////////////////////////////////////////////////// // cPusher = 0; sPusher = 0; mPusher = 0; lPusher = 0; hPusher = 0; // cProvider = NULL; sProvider = NULL; mProvider = NULL; lProvider = NULL; hProvider = NULL; // cSignal.Clean(); sSignal.Clean(); mSignal.Clean(); lSignal.Clean(); hSignal.Clean(); // cHasSignal = false; sHasSignal = false; mHasSignal = false; lHasSignal = false; hHasSignal = false; // cConditions.Clean(); sConditions.Clean(); mConditions.Clean(); lConditions.Clean(); hConditions.Clean(); // datetime cTime = TimeCurrent(); // // Current ... bool canProcess = mSetups[i] .CanProcessBar( X_MARKET_CYCLE_UNKNOWN // ); // datetime next = mSetups[i].GetNextSignalTime(X_MARKET_CYCLE_UNKNOWN); if (IsValid(next)) { canProcess = canProcess && cTime >= next; } // if (canProcess) { // bool iHasConditions = mSetups[i].GetConditions( cConditions, X_MARKET_CYCLE_UNKNOWN, // Current Market ... 0, // Bar Index ... 5 // Loop Back ... ); // if (iHasConditions) { // // Parse Conditions for Signal ... cHasSignal = signalGenerator.HasSignal( cConditions, cSignal, cPusher, cProvider, AllowSupport(), mAllowLong, mAllowShort, mVolume, mSLPoint, mIgnoreSL, mTPPoint, mIgnoreTP // ); // if (cHasSignal) { // mSetups[i].WaitsUntilNextBar( X_MARKET_CYCLE_UNKNOWN // ); } } } // // Short ... canProcess = mSetups[i] .CanProcessBar( X_MARKET_CYCLE_SHORT // ); // next = mSetups[i].GetNextSignalTime(X_MARKET_CYCLE_SHORT); if (IsValid(next)) { sHasSignal = canProcess && cTime >= next; } // if (canProcess) { // bool iHasConditions = mSetups[i].GetConditions( sConditions, X_MARKET_CYCLE_SHORT, // Current Market ... 0, // Bar Index ... 5 // Loop Back ... ); // if (iHasConditions) { // // Parse Conditions for Signal ... sHasSignal = signalGenerator.HasSignal( sConditions, sSignal, sPusher, sProvider, AllowSupport(), mAllowLong, mAllowShort, mVolume, mSLPoint, mIgnoreSL, mTPPoint, mIgnoreTP // ); // if (sHasSignal) { // mSetups[i].WaitsUntilNextBar( X_MARKET_CYCLE_SHORT // ); } } } // // Medium ... canProcess = mSetups[i] .CanProcessBar( X_MARKET_CYCLE_MEDIUM // ); // next = mSetups[i].GetNextSignalTime(X_MARKET_CYCLE_MEDIUM); if (IsValid(next)) { mHasSignal = canProcess && cTime >= next; } // if (canProcess) { // bool iHasConditions = mSetups[i].GetConditions( mConditions, X_MARKET_CYCLE_MEDIUM, // Current Market ... 0, // Bar Index ... 5 // Loop Back ... ); // if (iHasConditions) { // // Parse Conditions for Signal ... mHasSignal = signalGenerator.HasSignal( mConditions, mSignal, mPusher, mProvider, AllowSupport(), mAllowLong, mAllowShort, mVolume, mSLPoint, mIgnoreSL, mTPPoint, mIgnoreTP // ); // if (mHasSignal) { // mSetups[i].WaitsUntilNextBar( X_MARKET_CYCLE_MEDIUM // ); } } } // // Long ... canProcess = mSetups[i] .CanProcessBar( X_MARKET_CYCLE_LONG // ); // next = mSetups[i].GetNextSignalTime(X_MARKET_CYCLE_LONG); if (IsValid(next)) { lHasSignal = canProcess && cTime >= next; } // if (canProcess) { // bool iHasConditions = mSetups[i].GetConditions( lConditions, X_MARKET_CYCLE_LONG, // Current Market ... 0, // Bar Index ... 5 // Loop Back ... ); // if (iHasConditions) { // // Parse Conditions for Signal ... lHasSignal = signalGenerator.HasSignal( lConditions, lSignal, lPusher, lProvider, AllowSupport(), mAllowLong, mAllowShort, mVolume, mSLPoint, mIgnoreSL, mTPPoint, mIgnoreTP // ); // if (lHasSignal) { // mSetups[i].WaitsUntilNextBar( X_MARKET_CYCLE_LONG // ); } } } // // Hind ... canProcess = mSetups[i] .CanProcessBar( X_MARKET_CYCLE_HIND // ); // next = mSetups[i].GetNextSignalTime(X_MARKET_CYCLE_HIND); if (IsValid(next)) { hHasSignal = canProcess && cTime >= next; } // if (canProcess) { // bool iHasConditions = mSetups[i].GetConditions( hConditions, X_MARKET_CYCLE_HIND, // Current Market ... 0, // Bar Index ... 5 // Loop Back ... ); // if (iHasConditions) { // // Parse Conditions for Signal ... hHasSignal = signalGenerator.HasSignal( hConditions, hSignal, hPusher, hProvider, AllowSupport(), mAllowLong, mAllowShort, mVolume, mSLPoint, mIgnoreSL, mTPPoint, mIgnoreTP // ); // if (hHasSignal) { // mSetups[i].WaitsUntilNextBar( X_MARKET_CYCLE_HIND // ); } } } //////////////////////////////////////////////////////////////////////////////// // // Handle Creating a new Signal Info ... // XSignal signal; // X121SetupConditions otherConditions[]; // if (hHasSignal) // { // // // signal = hSignal; // // // AddRef( // cConditions, // otherConditions // // ); // AddRef( // sConditions, // otherConditions // // ); // } // else if (lHasSignal) // { // // // signal = lSignal; // // // AddRef( // cConditions, // otherConditions // // ); // AddRef( // sConditions, // otherConditions // // ); // AddRef( // mConditions, // otherConditions // // ); // } // else if (mHasSignal) // { // // // signal = mSignal; // // // AddRef( // cConditions, // otherConditions // // ); // AddRef( // sConditions, // otherConditions // // ); // } // else if (sHasSignal) // { // // // signal = sSignal; // // // AddRef( // cConditions, // otherConditions // // ); // AddRef( // mConditions, // otherConditions // // ); // AddRef( // lConditions, // otherConditions // // ); // AddRef( // hConditions, // otherConditions // // ); // } // else if (cHasSignal) // { // // // signal = cSignal; // // // AddRef( // sConditions, // otherConditions // // ); // AddRef( // mConditions, // otherConditions // // ); // AddRef( // lConditions, // otherConditions // // ); // AddRef( // hConditions, // otherConditions // // ); // } // // // int pushers = cPusher + sPusher + mPusher + lPusher + hPusher; // // // bool isLong = IsLong(signal.type); // // // // Collecting Bullish/Bearish Signs ... // if (isLong) // { // mBullishSigns += pushers; // } // else // { // mBearishSigns += pushers; // } // // // // Validate Signal ... // bool isValid = // // // // Handle Pusher Validations ... // (mReuiredSignalVerifications <= 0 // ? true // : pushers >= mReuiredSignalVerifications) // // // && // // // // Handle Other Conditions Validations ... // (!mGetVerificationFromOtherTimeFrames // ? true // : isLong // ? signalGenerator.HasLongVerifications(otherConditions) // : signalGenerator.HasShortVerifications(otherConditions)) // // // ; // // // bool forceState = ForceState(); // // // if (!isValid || (forceState && isValid)) // { // // // // Clear Other Conditions ... // Clean(otherConditions); // // // // Fill All Conditions to Other Conditions ... // AddRef( // cConditions, // otherConditions // // ); // AddRef( // sConditions, // otherConditions // // ); // AddRef( // mConditions, // otherConditions // // ); // AddRef( // lConditions, // otherConditions // // ); // AddRef( // hConditions, // otherConditions // // ); // // // // If Recieved Any Unverified Signal // // we Passed it to EQM Manager ... // EQMHandleInvalidSignal( // signal, // pushers, // mVolumeOSC, // mBullishScore, // mBullishSigns, // mBearishScore, // mBearishSigns, // otherConditions, // isValid // // ); // continue; // } // // // if (!forceState) // { // // // // Add Signal to Execution Result ... // AddRef( // signal, // signals // // ); // // // // Add new Signal Info ... // mTradeHandler.Add( // signal, // pushers, // mVolumeOSC, // mBullishSigns, // mBearishSigns, // mBullishScore, // mBearishScore, // cConditions, // sConditions, // mConditions, // lConditions, // hConditions // // ); // } //////////////////////////////////////////////////////////////////////////////// // // // double profits = SpecifiedCalculatePositionsProfit(positions); // // // // Checking Force Sate Conditions ... // if (ForceState()) // { // // // // Check Force State Hedging ... // bool isHedged = DoEQMForceClose(); // if (isHedged) // { // // // ForceState(false); // return; // } // // // // Handle Act Based On Drawdow ... // if (mMaxDrawdownForce > 0) // { // // // double drawdown = CalculateMaxDrawdown(); // if (drawdown > mMaxDrawdownForce) // { // // // // Try to Hedge ... // if (profits > 0) // { // // // bool isHedged = DoEQMForceClose(profits); // if (isHedged) // { // // // ForceState(false); // return; // } // } // // // // Close Max In Drawdown Position ... // int maxInDIDX = FindMaxDrawdownIndex(positions); // if (IsValidIndex(maxInDIDX)) // { // // // string comment = XEQMSupportToken + " Max In D ..."; // // // bool isClosed = mTrader.Close( // positions[maxInDIDX].ticket, // comment // // ); // if (isClosed) // { // // // string message = XEQMSupportToken + " Close " + ToString(positions[maxInDIDX].ticket) + " Due Max In Drawdown ..."; // // // Alert(message); // } // // // return; // } // // // return; // } // } // // // // Handle Act Based on Positions Count ... // if (mMaxPositionsForce > 0 && positionsCount > mMaxPositionsForce) // { // // // double requiredProfit = SpecifiedCalculateRequiredProfitForHedge( // positions, // MinRequiredProfitPerTrade(), // MinRequiredProfitPerVolumeFactor() // // ); // // // double halfProfit = requiredProfit / 2; // if (halfProfit > 0 && profits > halfProfit) // { // // // bool isHedged = DoEQMForceClose(halfProfit); // if (isHedged) // { // // // ForceState(false); // return; // } // } // // // // Close Min In Profit Position ... // int minInPIDX = FindMinProfitIndex(positions); // if (IsValidIndex(minInPIDX)) // { // // // string comment = XEQMSupportToken + " Min In P ..."; // // // bool isClosed = mTrader.Close( // positions[minInPIDX].ticket, // comment // // ); // if (isClosed) // { // // // string message = XEQMSupportToken + " Close " + ToString(positions[minInPIDX].ticket) + " Due Min In Profit ..."; // // // Alert(message); // // // return; // } // } // // // // Close Max In Drawdown Position ... // int maxInDIDX = FindMaxDrawdownIndex(positions); // if (IsValidIndex(maxInDIDX)) // { // // // string comment = XEQMSupportToken + " Max In D ..."; // // // bool isClosed = mTrader.Close( // positions[maxInDIDX].ticket, // comment // // ); // if (isClosed) // { // // // string message = XEQMSupportToken + "Close " + ToString(positions[maxInDIDX].ticket) + " Due Max In Drawdown ..."; // // // Alert(message); // } // // // return; // } // // // return; // } // // // return; // } // // // int longs = 0; // double longVolumes = 0; // double longProfits = 0; // // // int shorts = 0; // double shortVolumes = 0; // double shortProfits = 0; // // // // Retrieve Required Informations of Positions ... // CountPositions( // positions, // longs, // longProfits, // longVolumes, // shorts, // shortProfits, // shortVolumes // // ); // // // // Retrieve Youngest Age ... // XPosition youngest; // int youngestAge = GetYoungest( // youngest, // positions // // ); // // // // Now Comparing items for enabling force State ... // bool isForceState = // // // youngestAge >= 20 && // // // (longProfits + shortProfits < 0) // // // ; // if (isForceState) // { // // // ForceState(true); // // // return; // } // // // XPosition supports[]; // int supportsCount = ExtractSupports( // positions, // supports // // ); // if (!IsValidSize(supportsCount)) // { // return; // } // // // int maxSupports = mTradeHandler.EnableSupport() // ? MaxNumberOfSupports() // : 0; // int maxGrids = mTradeHandler.EnableGrid() // ? MaxNumberOfGrids() // : 0; // int maxRecoveries = mTradeHandler.EnableRecovery() // ? MaxNumberOfRecoveries() // : 0; // // // // Supporting Force States ... // bool isProtectionForce = // supportsCount >= 1; // if (isProtectionForce) // { // // // ForceState(true); // // // return; // } ////////////////////////////////////////////////////////////////////////////////////////// double hotLevels[]; // Add( 0.25, hotLevels // ); // Add( 0.20, hotLevels // ); // Add( 0.15, hotLevels // ); // // Calculate Ticks Zone ... XSCZones *zones = new XSCZones( signal.symbol, signal.period // ); // XSCZonesInput zonesInput; zonesInput.length = 26; zonesInput.numberOfZones = 10; // zonesInput.AddLevelColor( hotLevels[0], clrRed // ); zonesInput.AddLevelColor( hotLevels[1], clrOrange // ); zonesInput.AddLevelColor( hotLevels[2], clrLightCoral // ); // bool canUseZones = zones.Init(zonesInput); if (canUseZones) { signal.zones = zones; } // // Calculate Trend ... XSCTrend *trend = new XSCTrend( signal.symbol, signal.period // ); // XSCTrendInput tInputs; tInputs.Default(); bool canUseTrend = trend.Init(tInputs); if (canUseTrend) { // signal.trend = trend; } // XSCCFInput cfInputs; cfInputs.Default(); XSCCF *cf = new XSCCF( signal.symbol, signal.period // ); bool canUseCF = cf.Init(cfInputs); if (canUseCF) { signal.cf = cf; } // void GenerateSupportSignals( XSignal &signal // Source Signal for Support Generating ... ) { // double pivots[]; int pivotsCount = GenerateSupportPivots( signal, pivots // ); if (!IsValidSize(pivotsCount)) { return; } // XSignal supports[]; int indirectionalsCount = PrepareInDirectionalSupportSignals( supports, signal, pivots // ); if (IsValidSize(indirectionalsCount)) { // Copy( supports, signal.supports // ); // Clean(supports); } } // int GenerateSupportPivots( XSignal &signal, // Source Signal for Support Generating ... double &pivots[] // ) { // int result = 0; // // Validate Signal ... if (!signal.IsValid()) { return result; } // // Retrieve Signal Direction ... bool isLong = IsLong(signal.type); // bool canUseCF = signal.cf != NULL && signal.cf.IsValid(); bool canUseZones = signal.zones != NULL && signal.zones.IsValid(); bool canUseTrend = signal.trend != NULL && signal.trend.IsValid(); // datetime prevTime = iTime( signal.symbol, signal.period, 1 // ); // datetime cTime = TimeCurrent(); // string entryLineName = "sEntry" + signal.symbol; DrawTrendLine( 0, entryLineName, 0, prevTime, signal.entry, cTime, signal.entry, clrYellow, STYLE_SOLID, 2, false, false, true // ); // Clean(pivots); double tmpPivots[]; // if (canUseCF) { // signal.cf.Draw(); XOHCL cfBULLBar = signal.cf.GetBullishBar(); XOHCL cfBEARBar = signal.cf.GetBearishBar(); // Add( cfBULLBar.high, tmpPivots // ); Add( cfBULLBar.low, tmpPivots // ); Add( cfBEARBar.high, tmpPivots // ); Add( cfBEARBar.low, tmpPivots // ); // signal.cf.Remove(); } // if (canUseTrend) { // signal.trend.Draw(); // // Lows ... Add( signal.trend.GetLows(), tmpPivots // ); // // Highs ... Add( signal.trend.GetHighs(), tmpPivots // ); // // Support ... Add( signal.trend.GetSupport(), tmpPivots // ); // // Resistance ... Add( signal.trend.GetResistance(), tmpPivots // ); // signal.trend.Remove(); } // if (canUseZones) { // signal.zones.Draw(); // // Find Hot Zones ... for (int i = 0; i < signal.zones.CountZones(); i++) { // // Retrieve Indexed Zone ... XSCZone *iZone = signal.zones.GetZone(i); // // Check Zone is Hot Zone or not ... bool isHotZone = false; for (int j = 0; j < ArraySize(hotLevels); j++) { // isHotZone = (iZone.percent / 100) >= hotLevels[j]; if (isHotZone) { break; } } // // Prevent Moving Forward if there isn't Hot Zone ... if (!isHotZone) { continue; } // // Zone High ... Add( iZone.high, tmpPivots // ); // // Zone Low ... Add( iZone.low, tmpPivots // ); } // signal.zones.Remove(); } // int tmpPivotsCount = ArraySize(tmpPivots); if (!IsValidSize(tmpPivotsCount)) { return result; } // for (int i = 0; i < tmpPivotsCount; i++) { // double iPivot = tmpPivots[i]; // bool isValidPivot = isLong ? signal.entry > iPivot : signal.entry < iPivot; if (isValidPivot) { // Add( iPivot, pivots // ); } } // ArrayFree(tmpPivots); // RemoveDraws(entryLineName); // result = ArraySize(pivots); // return result; } // bool PrepareDirectionalSupportSignals( XPosition &support, XPosition &parent, XSignal &result // ) { // bool mResult = false; // result.Clean(); // mResult = support.IsValid() && parent.IsValid(); if (!mResult) { return mResult; } // mResult = support.provider == XEQMSupportToken + XINDirectionalToken; if (!mResult) { return mResult; } // // Indirectional Supports Updated Using Directional ... // double entryPrice = GetEntry( parent.symbol, parent.type // ); // ENUM_X_ORDER_MODES rMode = X_ORDER_MODE_NOTHING; bool isParentLong = IsLong(parent.type); if (isParentLong) { // if (entryPrice < parent.entry) { rMode = X_ORDER_MODE_STOP; } } else { // if (entryPrice > parent.entry) { rMode = X_ORDER_MODE_STOP; } } // mResult = rMode != X_ORDER_MODE_NOTHING; if (!mResult) { return mResult; } // mResult = result.Prepare( parent.symbol, XEQMSupportToken + XDirectionalToken, parent.period, parent.type, rMode, parent.entry, parent.volume, 0, 0 // ); // if (mResult) { // string comment = GenerateSupportTag(parent.ticket); result.comment = comment; } else { result.Clean(); } // return mResult; } // int PrepareInDirectionalSupportSignals( XSignal &supports[], XSignal &source, double &pivots[] // ) { // int result = 0; // Clean(supports); // int pivotsCount = ArraySize(pivots); if (!IsValidSize(pivotsCount)) { return result; } // bool isLong = IsLong(source.type); // XSignal rSignal; // Recovery Signal ... // double rSL = 0; // Recovery Stop Loss ... double rTP = 0; // Recovery Take Profit ... double rEntry = 0; // Recovery Entry Point ... double rVolume = 0; // Recovery Volume ... ENUM_POSITION_TYPE rType; // Recovery Signal Type ... ENUM_X_ORDER_MODES rMode; // Recovery Signal Mode ... bool isSignalPrepared = false; // Check Signal Preparation Succeed ... // bool condition = false; // double onePointValue = PointToPrice(1, source.symbol); // double directionalVolumeMultiplier = 1; double inDirectionalVolumeMultiplier = 2; // // if Long we are Looking for lower prices than // entry price and vise verse ... // for (int i = 0; i < pivotsCount; i++) { // double iPivot = pivots[i]; // bool isValidPrice = isLong ? source.entry > iPivot : source.entry < iPivot; if (!isValidPrice) { continue; } // // InDirectional ... if (isLong) { // rType = POSITION_TYPE_SELL; rMode = X_ORDER_MODE_STOP; } else { // rType = POSITION_TYPE_BUY; rMode = X_ORDER_MODE_STOP; } // rEntry = iPivot; rVolume = source.volume; // isSignalPrepared = rSignal.Prepare( source.symbol, XEQMSupportToken + XINDirectionalToken, source.period, rType, rMode, rEntry, rVolume, rSL, rTP // ); if (isSignalPrepared) { // AddRef( rSignal, supports // ); // rSignal.Clean(); // rSL = 0; rTP = 0; rEntry = 0; isSignalPrepared = false; } } // result = ArraySize(supports); // return result; } ///////////////////////////////////////////////////////////////////////////////////////// double pivots[]; Clean(pivots); // X121SignalGenerator generator; XSignal tSignal = _signal; generator.GenerateSupportPivots( tSignal, pivots // ); tSignal.Clean(); int pivotsCount = ArraySize(pivots); // // Retrieve Support Signal ... bool HasSupport( XSignal &support // ) { // bool result = false; // result = IsValid(); if (!result) { return result; } // int pivotsCount = ArraySize(pivots); result = IsValidSize(pivotsCount); if (!result) { return result; } // support.Clean(); // ENUM_POSITION_TYPE sType = type == X_POSITION_TYPE_LONG ? POSITION_TYPE_BUY : POSITION_TYPE_SELL; // bool isLong = IsLong(type); // ENUM_POSITION_TYPE cType = GetOpposit(sType); double cEntry = GetEntry( symbol, cType // ); // double pivot = 0; int pivotIndex = -1; for (int i = 0; i < pivotsCount; i++) { // double iPivot = pivots[i]; if (iPivot <= 0) { continue; } // result = isLong ? cEntry < entry && cEntry <= iPivot : cEntry > entry && cEntry >= iPivot; if (result) { // pivot = iPivot; pivotIndex = i; break; } } // if (result) { // result = support.Prepare( symbol, XEQMSupportToken + XINDirectionalToken, period, cType, X_ORDER_MODE_MARKET, cEntry, volume * 2, 0, 0 // ); if (result) { // string comment = GenerateSupportTag(ticket); support.comment = comment; // // Prepare Directional Support ... XSignal mSup; result = mSup.Prepare( symbol, XEQMSupportToken + XDirectionalToken, period, sType, X_ORDER_MODE_STOP, entry, volume, 0, 0 // ); if (result) { // string comment = GenerateSupportTag(ticket); mSup.comment = comment; // AddRef( mSup, support.supports // ); // result = ArrayRemove( pivots, pivotIndex, 1 // ); } } } // if (!result) { support.Clean(); } // return result; } // bool RemovePivot( double pivot, int index // ) { // bool result = false; // result = IsValid() && IsValidIndex(index) && ArraySize(pivots) > index; if (!result) { return result; } // result = ArrayRemove( pivots, index, 1 // ); // return result; } /////////////////////////////////////////////////////////////////////////// // input double x121EAForceCloseProfit = 5; // Close All Positions Regardless of Policies when Profit Reached // input double x121EAMaxDrawdownForce = 5; // Max Drawdown Force State for Handling Guards // input int x121EAMaxPositionsForce = 10; // Max Number of Positions Force State for Handling Guards // input double x121EAMinFreeMargingForHandleForce = 800; // Min Free Margin for Force States // input bool x121EAAllowSymbolHedgeOnForce = false; // Allow Symbol Hedging on Force States // x121EA.ForceCloseProfit(x121EAForceCloseProfit); // x121EA.MaxDrawdownForce(x121EAMaxDrawdownForce); // x121EA.MaxPositionsForce(x121EAMaxPositionsForce); // x121EA.AllowSymbolHedgeOnForce(x121EAAllowSymbolHedgeOnForce); // x121EA.MinFreeMargingForHandleForce(x121EAMinFreeMargingForHandleForce); double mForceCloseProfit; // Close All Positions Regardless of Policies when Profit Reached // double ForceCloseProfit() { return mForceCloseProfit; } // void ForceCloseProfit(double value) { // if (value < 0) { value = 0; } // mForceCloseProfit = value; } // double MaxDrawdownForce() { return mMaxDrawdownForce; } // void MaxDrawdownForce(double value) { // if (value < 0) { value = 0; } // mMaxDrawdownForce = value; } // int MaxPositionsForce() { return mMaxPositionsForce; } // void MaxPositionsForce(int value) { // if (value < 0) { value = 0; } // mMaxPositionsForce = value; } // bool AllowSymbolHedgeOnForce() { return mAllowSymbolHedgeOnForce; } // void AllowSymbolHedgeOnForce(bool value) { mAllowSymbolHedgeOnForce = value; } return; // if (!IsValidSize(setupsCount)) { return; } // // Here i Can Check what to do In Force State ... // // Handle Hedging Based On Positions ... double drawdown = GetDrawdownPercent(); double forceDrawdown = MaxDrawdownForce(); int positionsForce = MaxPositionsForce(); double forceCloseProfit = ForceCloseProfit(); double minRequiredProfitPerTrade = MinRequiredProfitPerTrade(); double minRequiredProfitPerVolumeFactor = MinRequiredProfitPerVolumeFactor(); // // Try To Force Hedging ... bool canForceHedge = (positionsForce <= 0 ? true : positionsCount > positionsForce) // || // (forceDrawdown > 0 && drawdown >= forceDrawdown); if (canForceHedge) { // // Check Required Profit ... // double profit = SpecifiedCalculatePositionsProfit(positions); // // Check Force Close Profit ... if (forceCloseProfit > 0) { // canForceHedge = profit >= forceCloseProfit; if (canForceHedge) { // bool isHedged = DoEQMForceClose(); if (isHedged) { return; } } } // // Calculate Required Profit ... double requiredProfit = SpecifiedCalculateRequiredProfitForHedge( positions, minRequiredProfitPerTrade, minRequiredProfitPerVolumeFactor // ); // canForceHedge = requiredProfit <= 0 ? profit > 0 : profit >= (requiredProfit / 2); if (canForceHedge) { // bool isHedged = DoEQMForceClose(); if (isHedged) { return; } } // // At Least Hedgeing ... // Minimal Hedge ... // // Check Symbol Hedging ... bool allowSymbolHedge = AllowSymbolHedgeOnForce(); if (allowSymbolHedge) { for (int i = 0; i < setupsCount; i++) { // string iSymbol = mSetups[i].GetSymbol(); // XPosition iSymbolPositions[]; int iSymbolPositionsCount = mTrader.GetPositions( iSymbolPositions, // iSymbol, NULL, // All Providers ... NULL, // All Periods ... NULL, // All Types ... true // Filter By Magic ... ); if (!IsValidSize(iSymbolPositionsCount)) { continue; } // double profit = SpecifiedCalculatePositionsProfit(iSymbolPositions); // double requiredProfit = SpecifiedCalculateRequiredProfitForHedge( iSymbolPositions, minRequiredProfitPerTrade, minRequiredProfitPerVolumeFactor // ); // bool canHedge = requiredProfit <= 0 ? profit > 0 : profit >= requiredProfit; if (canHedge) { // string comment = XEQMSupportToken + " Hedge Symbol ..."; // int closed = mTrader.Close( iSymbolPositions, comment // ); // if (closed == iSymbolPositionsCount) { // mSetups[i].ForceState(false); // string message = XEQMSupportToken + " Hedge Symbol (" + iSymbol + "): " + ToString(profit); Alert(message); } } } } return; } // // Implement Other Senarios ... // bool isMarginPassed = IsMarginPassed(); bool isMaxNumberPassed = IsNumberOfPositionsPassed(); bool canProtect = !isMarginPassed || !isMaxNumberPassed; if (canProtect) { // int maxInDIDX = FindMaxDrawdownIndex( positions // ); int setupIDX = FindSetupIndex(positions[maxInDIDX].symbol); if (IsValidIndex(maxInDIDX) && IsValidIndex(setupIDX)) { // string iSymbol = positions[maxInDIDX].symbol; ENUM_TIMEFRAMES iPeriod = mSetups[setupIDX].GetPeriod(); // // Check Position Age ... int age = GetAge( positions[maxInDIDX], iPeriod // ); if (age >= 700) { // // Calculate Trend ... XSCTrend *trend = new XSCTrend( iSymbol, iPeriod // ); // XSCTrendInput tInputs; tInputs.Default(); bool canUseTrend = trend.Init(tInputs); if (canUseTrend) { // trend.Draw(); Print("UseTrend"); trend.Remove(); } // string comment = XEQMSupportToken + " Close Max In D ..."; // bool isClosed = mTrader.Close( // positions[maxInDIDX].ticket, // comment // // ); // if (isClosed) // { // // // string message = XEQMSupportToken + " Close Position (" + ToString(positions[maxInDIDX].ticket) + ") Due Max In Drawdown ..."; // Alert(message); // } } } } //////////////////////////////////////////////////////////////////////////////////// void EQMHandleForceState() { // XPosition positions[]; int positionsCount = mTrader.GetPositions(positions); if (!IsValidSize(positionsCount) || positionsCount <= 4) { return; } // double minRequiredProfitPerTrade = MinRequiredProfitPerTrade(); double minRequiredProfitPerVolumeFactor = MinRequiredProfitPerVolumeFactor(); // double profit = SpecifiedCalculatePositionsProfit(positions); double requiredProfit = SpecifiedCalculateRequiredProfitForHedge( positions, minRequiredProfitPerTrade, minRequiredProfitPerVolumeFactor // ); // bool canClose = profit > 0 && (profit == requiredProfit || profit >= requiredProfit / 2); if (canClose) { DoEQMForceClose(); } return; // // // XPosition positions[]; // int positionsCount = mTrader.GetPositions(positions); // if (!IsValidSize(positionsCount)) // { // // // EQMClearAllForceStates(); // // // return; // } // // // // Search For Force State Per Each Setup ... // // // int forceCount = 0; // int setupsCount = CountSetups(); // if (IsValidSize(setupsCount)) // { // // // int maxAllowed = MaxAllowedTrades(); // bool perDirection = UseMaxAllowedPerDirection(); // // // for (int i = 0; i < setupsCount; i++) // { // // // string iSymbol = mSetups[i].GetSymbol(); // ENUM_TIMEFRAMES iPeriod = mSetups[i].GetPeriod(); // // // XPosition iPositions[]; // int iPositionsCount = mTrader.GetPositions( // iPositions, // iSymbol, // NULL, // All Providers ... // NULL, // All Periods ... // NULL, // All Types ... // true // Filter By Magic ... // ); // if (!IsValidSize(iPositionsCount)) // { // continue; // } // // // // Counting Positions ... // int longs; // double longProfits; // double longVolumes; // // // int shorts; // double shortProfits; // double shortVolumes; // // // CountPositions( // iPositions, // // // longs, // longProfits, // longVolumes, // // // shorts, // shortProfits, // shortVolumes // // ); // // // bool isMaxReached = // maxAllowed <= 0 // ? false // : !perDirection // ? longs + shorts >= maxAllowed // : longs >= maxAllowed && shorts >= maxAllowed; // double volumeSummary = longVolumes + shortVolumes; // double profitsSummary = longProfits + shortProfits; // // // bool isIInForce = // // // maxAllowed <= 0 // ? profitsSummary < 0 && // longVolumes == shortVolumes // : isMaxReached && // profitsSummary < 0 && // longVolumes == shortVolumes // // // ; // if (isIInForce) // { // // // forceCount++; // mSetups[i].ForceState(true); // } // } // } // // // bool isForce = forceCount >= 1; // if (!isForce) // { // return; // } // } // void EQMHandleForceSignals( XSignal &signals[] // ) { // // Validate Signals Count ... int signalsCount = ArraySize(signals); if (!IsValidSize(signalsCount)) { return; } // // Validate Force Marigin ... double marigin = mTrader.mAccount.GetMargin(); double forceMargin = 100; // TODO: Make It Configurable bool isInForceMarigin = marigin >= forceMargin; if (!isInForceMarigin) { return; } // // Now we are Sure we in Force State Margin amd we Have Signals ... // // here we Must Symbol Categorized Positions ... int setupsCount = CountSetups(); if (!IsValidSize(setupsCount)) { return; } // // Retrieving Positions ... XPosition positions[]; int positionsCount = mTrader.GetPositions(positions); if (!IsValidSize(positionsCount)) { return; } // XSymbolPositions symbolPositions[]; int symbolPositionsCount = ExtractSymbolPositions( positions, symbolPositions // ); if (!IsValidSize(symbolPositionsCount)) { return; } // Log("symbolPositionsCount: " + ToString(symbolPositionsCount)); // } ///////////////////////////////////////////////////////////// // // Handle Force State Management ... bool mForce; void EQMHandleForceState(XSignal &forceSignals[]) { // // Validate Force Marigin ... double marigin = mTrader.mAccount.GetMargin(); double minFreeMarigin = MinFreeMargingForOpenTrades(); double forceMargin = 2 * minFreeMarigin; // TODO: Make It Configurable bool isMarginForce = marigin >= forceMargin; // // Retrieving Positions ... XPosition positions[]; int positionsCount = mTrader.GetPositions(positions); if (!IsValidSize(positionsCount)) { // mForce = false; // datetime cTime = TimeCurrent(); string message = "Exit From Force State: " + ToString(cTime); // // Log(message); return; } // XPosition oldest; int oldestAge = GetOldest( oldest, positions // ); // // Check Force State ... bool isForce = isMarginForce; // && oldestAge >= 288; if (!isForce) { // if (mForce) { // mForce = false; // datetime cTime = TimeCurrent(); string message = "Exit From Force State: " + ToString(cTime); // // Log(message); } return; } else { mForce = true; } // // Prevent Moving Forward From Non Force State ... if (!mForce) { return; } // int forceSignalsCount = ArraySize(forceSignals); if (IsValidSize(forceSignalsCount)) { // Log("Force Signals Count: " + ToString(forceSignalsCount)); } // // // double minProfitPerTrade = MinProfitPerTrade(); // double minProfitPerVolumeFactor = MinProfitPerVolumeFactor(); // // // double profit = SpecifiedCalculatePositionsProfit(positions); // double requiredProfit = SpecifiedCalculateRequiredProfitForHedge( // positions, // minProfitPerTrade, // minProfitPerVolumeFactor // // ); // // // XSymbolPositions symbolPositions[]; // int symbolPositionsCount = ExtractSymbolPositions( // positions, // symbolPositions, // minProfitPerTrade, // minProfitPerVolumeFactor // // ); // if (!IsValidSize(symbolPositionsCount)) // { // return; // } // // Log("symbolPositionsCount: " + ToString(symbolPositionsCount)); } ///////////////////////////////////////////////////////////////// // // Handle any Invalid Signals ... void EQMHandleInvalidSignal( XSignal &signal, // Invalid Signal int pushers, // Pushers bool isValid, // IsValid Signal ... X121SetupConditions &conditions[] // All Time Frames Conditions ) { // // Check Force State ... // if (!ForceState()) // { // return; // } // int setupIDX = FindSetupIndex(signal.symbol); if (!IsValidIndex(setupIDX)) { return; } // bool isForce = mForce; // mSetups[setupIDX].ForceState(); if (!isForce) { return; } // // Check Delay Between Two Signals ... // bool isMarginPassed = IsMarginPassed(); // bool isDelayPassed = IsSignalDelayPassed(signal); // bool isNumberOfPositionsPassed = IsNumberOfPositionsPassed(); // bool canUseSignal = // isMarginPassed && // isDelayPassed && // isNumberOfPositionsPassed; // XSignal signals[]; // if (isValid) { // Log("IsValid Invalid Signal ..."); // bool canSupport = // EnableSupport() && SupportOnlyForces() // ; bool canGrid = // EnableGrid() && GridOnlyForces() // ; bool canRecover = // EnableRecovery() && RecoverOnlyForces() // ; // if (canUseSignal) { // AddRef( signal, signals // ); // // Add new Signal Info ... mTradeHandler.Add( signal, pushers, canGrid, canRecover, canSupport, conditions[0], conditions[1], conditions[2], conditions[3], conditions[4] // ); } } else { Log("IsValid Invalid Signal INN ..."); } // // if (ArraySize(signals) > 0) // { // EQMExecuteSignals(signals); // } } ///////////////////////////////////////////////////////// // void EQMClearAllForceStates() { // int setupsCount = CountSetups(); if (!IsValidSize(setupsCount)) { return; } // for (int i = 0; i < setupsCount; i++) { mSetups[i].ForceState(false); } } /////////////////////////////////////////////////////////// // // // result = // // // // Check Price Place ... // ( // // // (hh4 > resistance.low || // (MathAbs(hh4 - resistance.low) <= threshold)) // // // && // // // ll4 < resistance.low // // // ) // // // && // // // // Check Candlestick Pattern ... // ( // // // cBar.HasBearishTrend( // tmpSWH, // tmpSWL, // true // // ) // // // && // // // ( // // // cBar.IsShootingStar() // // // || // // // cBar.IsEveningStar() // // // || // // // cBar.IsBearishEngulfing() // // // ) // // // ) // // // ; // // // result = // // // // Check Price Place ... // ( // // // (ll4 < support.high || // (MathAbs(ll4 - support.high) <= threshold)) // // // && // // // hh4 > support.high // // // ) // // // && // // // // Check Candlestick Pattern ... // ( // // // cBar.HasBullishTrend( // tmpSWH, // tmpSWL, // true // // ) // // // && // // // ( // // // cBar.IsHammer() // // // || // // // cBar.IsMorningStar() // // // || // // // cBar.IsBullishEngulfing() // // // ) // // // ) // // // ;