// 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 < bullishScore / 3.5 && longVerifications > 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 < bearishScore / 3.5 && shortVerifications > 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; } } } }