شروط تلبية طلبات الإكسبيرتات أوالمؤشرات

تقليص
X
 
  • تصفية - فلترة
  • الوقت
  • عرض
إلغاء تحديد الكل
مشاركات جديدة

  • السلام عليكم

    قومت بعمل التعديل هذا:

    كود HTML:
    double InpOrderSizeBxx = (Amount_of_money/(((iClose(Symbol() ,PERIOD_CURRENT,1))-(Lowest(Symbol() , _Period, Range, 0)))*10000))/10;
    double InpOrderSizeSxx = (Amount_of_money/(((Highest(Symbol() , _Period, Range, 0))-(iClose(Symbol() ,PERIOD_CURRENT,1)))*10000))/10;
    
    double InpOrderSizeBx=InpOrderSizeBxx;
    Print("InpOrderSizeBx = ",DoubleToString(InpOrderSizeBx,16));
    
    double InpOrderSizeB=NormalizeDouble(InpOrderSizeBxx,0);
    Print("NormalizeDouble(InpOrderSizeBx,0) = ",DoubleToString(InpOrderSizeB,16));
    
    double InpOrderSizeSx=InpOrderSizeSxx;
    Print("InpOrderSizeSx = ",DoubleToString(InpOrderSizeSx,16));
    
    double InpOrderSizeS=NormalizeDouble(InpOrderSizeSxx,0);
    Print("NormalizeDouble(InpOrderSizeSx,0) = ",DoubleToString(InpOrderSizeS,16));
    
    Trade.PositionOpen(Symbol(), ORDER_TYPE_BUY, InpOrderSizeB, openPrice, stopLossPrice, takeProfitPrice, InpTradeComment);
    Trade.PositionOpen(Symbol(), ORDER_TYPE_SELL, InpOrderSizeS, openPrice, stopLossPrice, takeProfitPrice, InpTradeComment);
    return((int)Trade.ResultOrder());
    
    }
    
    
    وهذا هو الكود كامل:

    كود HTML:
    input int InpTakeProfitPts = 0;
    input int InpStopLossPts = 0;
    input double Amount_of_money = 100;
    //
    // Standard inputs
    //
    input string InpTradeComment = __FILE__; // Trade comment
    input int InpMagicNumber = 2000001; // Magic number
    input int Range=121;
    input double Goal=6;
    
    double TakeProfit;
    double StopLoss;
    bool CloseOpposite;
    const string IndicatorName="TEST";
    const int Handle_Buy = 0;
    const int Handle_Sell = 1;
    int Handle;
    double BufferBuy[3];
    double BufferSell[3];
    datetime lastTime = 0;
    //
    // Use CTrade, easier than doing our own coding
    //
    #include <Trade\Trade.mqh>
    CTrade *Trade;
    
    int OnInit() {
    
    //
    // Create a pointer to a ctrade object
    //
    Trade = new CTrade();
    Trade.SetExpertMagicNumber(InpMagicNumber);
    Handle=iCustom(Symbol(),Period(),IndicatorName);
    
    if(Handle==INVALID_HANDLE)
    {
    PrintFormat("Failed",GetLastError());
    return(INIT_FAILED);
    }
    return(INIT_SUCCEEDED);
    }
    
    void OnDeinit(const int reason) {
    IndicatorRelease(Handle);
    
    }
    void OnTick()
    {
    int cnt_B = CopyBuffer(Handle,Handle_Buy,0,3,BufferBuy);
    int cnt_S = CopyBuffer(Handle,Handle_Sell,0,3,BufferSell);
    
    double Previous_Candle_Buy = BufferBuy[1];
    double Current_Candle_Buy = BufferBuy[0];
    
    double Previous_Candle_Sell = BufferSell[1];
    double Current_Candle_Sell = BufferSell[0];
    
    
    bool buyCondition = false;
    bool sellCondition = false;
    
    if(lastTime != iTime(Symbol(), 0, 1))
    {
    lastTime = iTime(Symbol(), 0, 1);
    }
    else
    {
    return;
    }
    if( Previous_Candle_Buy ==iLow(_Symbol, PERIOD_CURRENT,1)) { buyCondition = true;}
    if( Previous_Candle_Sell ==iHigh(_Symbol, PERIOD_CURRENT,1)) { sellCondition = true;}
    
    double point = SymbolInfoDouble(Symbol(), SYMBOL_POINT);
    TakeProfit = InpTakeProfitPts * point;
    StopLoss = InpStopLossPts * point;
    
    CloseOpposite = false;
    
    
    if (buyCondition) {
    if (CloseOpposite) CloseAll(POSITION_TYPE_SELL);
    OrderOpen(ORDER_TYPE_BUY, StopLoss, TakeProfit);
    } else
    if (sellCondition) {
    if (CloseOpposite) CloseAll(POSITION_TYPE_BUY);
    OrderOpen(ORDER_TYPE_SELL, StopLoss, TakeProfit);
    }
    
    //
    // Save any information for next time
    //
    
    return;
    
    }
    
    //+------------------------------------------------------------------+
    //| |
    //+------------------------------------------------------------------+
    double Highest(string symbol,ENUM_TIMEFRAMES timeframe,int count=WHOLE_ARRAY,int start=0)
    {
    double highest=0;
    double High[];
    ArraySetAsSeries(High,true);
    int copied=CopyHigh(symbol,timeframe,start,count,High) ;
    int index=ArrayMaximum(High,0,count)+start;
    if(copied>0 && index<copied) highest=High[index];
    return(highest);
    }
    //+------------------------------------------------------------------+
    //| |
    //+------------------------------------------------------------------+
    double Lowest(string symbol,ENUM_TIMEFRAMES timeframe,int count=WHOLE_ARRAY,int start=0)
    {
    double lowest=0;
    double Low[];
    ArraySetAsSeries(Low,true);
    int copied=CopyLow(symbol,timeframe,start,count,Low);
    int index=ArrayMinimum(Low,0,count)+start;
    if(copied>0 && index<copied) lowest=Low[index];
    return(lowest);
    }
    
    
    //
    // true/false has the bar changed
    //
    bool NewBar() {
    
    static datetime priorTime = 0;
    datetime currentTime = iTime(Symbol(), Period(), 0);
    bool result = (currentTime!=priorTime);
    priorTime = currentTime;
    return(result);
    
    }
    
    //
    // Close all trades of the specified type - for strategies that call for closing the opposite side
    //
    void CloseAll(ENUM_POSITION_TYPE positionType) {
    
    int cnt = PositionsTotal();
    for (int i = cnt-1; i>=0; i--) {
    ulong ticket = PositionGetTicket(i);
    if (ticket>0) {
    if (PositionGetString(POSITION_SYMBOL)==Symbol() && PositionGetInteger(POSITION_MAGIC)==InpMagicNumber && PositionGetInteger(POSITION_TYPE)==positionType) {
    Trade.PositionClose(ticket);
    }
    }
    }
    
    }
    
    //
    // Simple function to open a new order
    //
    int OrderOpen(ENUM_ORDER_TYPE orderType, double stopLoss, double takeProfit) {
    
    double openPrice;
    double stopLossPrice;
    double takeProfitPrice;
    
    //
    // Calculate the open price, take profit and stop loss prices ****d on the order type
    //
    if (orderType==ORDER_TYPE_BUY) {
    openPrice = NormalizeDouble(SymbolInfoDouble(Symbol(), SYMBOL_ASK), Digits());
    stopLossPrice = ((Lowest(Symbol() , _Period, Range, 0)));
    takeProfitPrice =((((iClose(Symbol() ,PERIOD_CURRENT,1))-(Lowest(Symbol() , _Period, Range, 0)))*Goal)+(Lowest(Symbol() , _Period, Range, 0)));
    } else if (orderType==ORDER_TYPE_SELL) {
    openPrice = NormalizeDouble(SymbolInfoDouble(Symbol(), SYMBOL_BID), Digits());
    stopLossPrice = ((Highest(Symbol() , _Period, Range, 0)));
    takeProfitPrice =((Highest(Symbol() , _Period, Range, 0))-(((Highest(Symbol() , _Period, Range, 0))-(iClose(Symbol() ,PERIOD_CURRENT,1)))*Goal));
    } else {
    // This function only works with type buy or sell
    return(-1);
    }
    double InpOrderSizeBxx = (Amount_of_money/(((iClose(Symbol() ,PERIOD_CURRENT,1))-(Lowest(Symbol() , _Period, Range, 0)))*10000))/10;
    double InpOrderSizeSxx = (Amount_of_money/(((Highest(Symbol() , _Period, Range, 0))-(iClose(Symbol() ,PERIOD_CURRENT,1)))*10000))/10;
    
    double InpOrderSizeBx=InpOrderSizeBxx;
    Print("InpOrderSizeBx = ",DoubleToString(InpOrderSizeBx,16));
    
    double InpOrderSizeB=NormalizeDouble(InpOrderSizeBxx,0);
    Print("NormalizeDouble(InpOrderSizeBx,0) = ",DoubleToString(InpOrderSizeB,16));
    
    double InpOrderSizeSx=InpOrderSizeSxx;
    Print("InpOrderSizeSx = ",DoubleToString(InpOrderSizeSx,16));
    
    double InpOrderSizeS=NormalizeDouble(InpOrderSizeSxx,0);
    Print("NormalizeDouble(InpOrderSizeSx,0) = ",DoubleToString(InpOrderSizeS,16));
    
    Trade.PositionOpen(Symbol(), ORDER_TYPE_BUY, InpOrderSizeB, openPrice, stopLossPrice, takeProfitPrice, InpTradeComment);
    Trade.PositionOpen(Symbol(), ORDER_TYPE_SELL, InpOrderSizeS, openPrice, stopLossPrice, takeProfitPrice, InpTradeComment);
    return((int)Trade.ResultOrder());
    
    }
    
    
    ولكنه لا يدخل صفقات!

    تعليق


    • المشاركة الأصلية بواسطة zooz1o مشاهدة المشاركة
      السلام عليكم

      قومت بعمل التعديل هذا:

      كود HTML:
      double InpOrderSizeBxx = (Amount_of_money/(((iClose(Symbol() ,PERIOD_CURRENT,1))-(Lowest(Symbol() , _Period, Range, 0)))*10000))/10;
      double InpOrderSizeSxx = (Amount_of_money/(((Highest(Symbol() , _Period, Range, 0))-(iClose(Symbol() ,PERIOD_CURRENT,1)))*10000))/10;
      
      double InpOrderSizeBx=InpOrderSizeBxx;
      Print("InpOrderSizeBx = ",DoubleToString(InpOrderSizeBx,16));
      
      double InpOrderSizeB=NormalizeDouble(InpOrderSizeBxx,0);
      Print("NormalizeDouble(InpOrderSizeBx,0) = ",DoubleToString(InpOrderSizeB,16));
      
      double InpOrderSizeSx=InpOrderSizeSxx;
      Print("InpOrderSizeSx = ",DoubleToString(InpOrderSizeSx,16));
      
      double InpOrderSizeS=NormalizeDouble(InpOrderSizeSxx,0);
      Print("NormalizeDouble(InpOrderSizeSx,0) = ",DoubleToString(InpOrderSizeS,16));
      
      Trade.PositionOpen(Symbol(), ORDER_TYPE_BUY, InpOrderSizeB, openPrice, stopLossPrice, takeProfitPrice, InpTradeComment);
      Trade.PositionOpen(Symbol(), ORDER_TYPE_SELL, InpOrderSizeS, openPrice, stopLossPrice, takeProfitPrice, InpTradeComment);
      return((int)Trade.ResultOrder());
      
      }
      
      
      وهذا هو الكود كامل:

      كود HTML:
      input int InpTakeProfitPts = 0;
      input int InpStopLossPts = 0;
      input double Amount_of_money = 100;
      //
      // Standard inputs
      //
      input string InpTradeComment = __FILE__; // Trade comment
      input int InpMagicNumber = 2000001; // Magic number
      input int Range=121;
      input double Goal=6;
      
      double TakeProfit;
      double StopLoss;
      bool CloseOpposite;
      const string IndicatorName="TEST";
      const int Handle_Buy = 0;
      const int Handle_Sell = 1;
      int Handle;
      double BufferBuy[3];
      double BufferSell[3];
      datetime lastTime = 0;
      //
      // Use CTrade, easier than doing our own coding
      //
      #include <Trade\Trade.mqh>
      CTrade *Trade;
      
      int OnInit() {
      
      //
      // Create a pointer to a ctrade object
      //
      Trade = new CTrade();
      Trade.SetExpertMagicNumber(InpMagicNumber);
      Handle=iCustom(Symbol(),Period(),IndicatorName);
      
      if(Handle==INVALID_HANDLE)
      {
      PrintFormat("Failed",GetLastError());
      return(INIT_FAILED);
      }
      return(INIT_SUCCEEDED);
      }
      
      void OnDeinit(const int reason) {
      IndicatorRelease(Handle);
      
      }
      void OnTick()
      {
      int cnt_B = CopyBuffer(Handle,Handle_Buy,0,3,BufferBuy);
      int cnt_S = CopyBuffer(Handle,Handle_Sell,0,3,BufferSell);
      
      double Previous_Candle_Buy = BufferBuy[1];
      double Current_Candle_Buy = BufferBuy[0];
      
      double Previous_Candle_Sell = BufferSell[1];
      double Current_Candle_Sell = BufferSell[0];
      
      
      bool buyCondition = false;
      bool sellCondition = false;
      
      if(lastTime != iTime(Symbol(), 0, 1))
      {
      lastTime = iTime(Symbol(), 0, 1);
      }
      else
      {
      return;
      }
      if( Previous_Candle_Buy ==iLow(_Symbol, PERIOD_CURRENT,1)) { buyCondition = true;}
      if( Previous_Candle_Sell ==iHigh(_Symbol, PERIOD_CURRENT,1)) { sellCondition = true;}
      
      double point = SymbolInfoDouble(Symbol(), SYMBOL_POINT);
      TakeProfit = InpTakeProfitPts * point;
      StopLoss = InpStopLossPts * point;
      
      CloseOpposite = false;
      
      
      if (buyCondition) {
      if (CloseOpposite) CloseAll(POSITION_TYPE_SELL);
      OrderOpen(ORDER_TYPE_BUY, StopLoss, TakeProfit);
      } else
      if (sellCondition) {
      if (CloseOpposite) CloseAll(POSITION_TYPE_BUY);
      OrderOpen(ORDER_TYPE_SELL, StopLoss, TakeProfit);
      }
      
      //
      // Save any information for next time
      //
      
      return;
      
      }
      
      //+------------------------------------------------------------------+
      //| |
      //+------------------------------------------------------------------+
      double Highest(string symbol,ENUM_TIMEFRAMES timeframe,int count=WHOLE_ARRAY,int start=0)
      {
      double highest=0;
      double High[];
      ArraySetAsSeries(High,true);
      int copied=CopyHigh(symbol,timeframe,start,count,High) ;
      int index=ArrayMaximum(High,0,count)+start;
      if(copied>0 && index<copied) highest=High[index];
      return(highest);
      }
      //+------------------------------------------------------------------+
      //| |
      //+------------------------------------------------------------------+
      double Lowest(string symbol,ENUM_TIMEFRAMES timeframe,int count=WHOLE_ARRAY,int start=0)
      {
      double lowest=0;
      double Low[];
      ArraySetAsSeries(Low,true);
      int copied=CopyLow(symbol,timeframe,start,count,Low);
      int index=ArrayMinimum(Low,0,count)+start;
      if(copied>0 && index<copied) lowest=Low[index];
      return(lowest);
      }
      
      
      //
      // true/false has the bar changed
      //
      bool NewBar() {
      
      static datetime priorTime = 0;
      datetime currentTime = iTime(Symbol(), Period(), 0);
      bool result = (currentTime!=priorTime);
      priorTime = currentTime;
      return(result);
      
      }
      
      //
      // Close all trades of the specified type - for strategies that call for closing the opposite side
      //
      void CloseAll(ENUM_POSITION_TYPE positionType) {
      
      int cnt = PositionsTotal();
      for (int i = cnt-1; i>=0; i--) {
      ulong ticket = PositionGetTicket(i);
      if (ticket>0) {
      if (PositionGetString(POSITION_SYMBOL)==Symbol() && PositionGetInteger(POSITION_MAGIC)==InpMagicNumber && PositionGetInteger(POSITION_TYPE)==positionType) {
      Trade.PositionClose(ticket);
      }
      }
      }
      
      }
      
      //
      // Simple function to open a new order
      //
      int OrderOpen(ENUM_ORDER_TYPE orderType, double stopLoss, double takeProfit) {
      
      double openPrice;
      double stopLossPrice;
      double takeProfitPrice;
      
      //
      // Calculate the open price, take profit and stop loss prices ****d on the order type
      //
      if (orderType==ORDER_TYPE_BUY) {
      openPrice = NormalizeDouble(SymbolInfoDouble(Symbol(), SYMBOL_ASK), Digits());
      stopLossPrice = ((Lowest(Symbol() , _Period, Range, 0)));
      takeProfitPrice =((((iClose(Symbol() ,PERIOD_CURRENT,1))-(Lowest(Symbol() , _Period, Range, 0)))*Goal)+(Lowest(Symbol() , _Period, Range, 0)));
      } else if (orderType==ORDER_TYPE_SELL) {
      openPrice = NormalizeDouble(SymbolInfoDouble(Symbol(), SYMBOL_BID), Digits());
      stopLossPrice = ((Highest(Symbol() , _Period, Range, 0)));
      takeProfitPrice =((Highest(Symbol() , _Period, Range, 0))-(((Highest(Symbol() , _Period, Range, 0))-(iClose(Symbol() ,PERIOD_CURRENT,1)))*Goal));
      } else {
      // This function only works with type buy or sell
      return(-1);
      }
      double InpOrderSizeBxx = (Amount_of_money/(((iClose(Symbol() ,PERIOD_CURRENT,1))-(Lowest(Symbol() , _Period, Range, 0)))*10000))/10;
      double InpOrderSizeSxx = (Amount_of_money/(((Highest(Symbol() , _Period, Range, 0))-(iClose(Symbol() ,PERIOD_CURRENT,1)))*10000))/10;
      
      double InpOrderSizeBx=InpOrderSizeBxx;
      Print("InpOrderSizeBx = ",DoubleToString(InpOrderSizeBx,16));
      
      double InpOrderSizeB=NormalizeDouble(InpOrderSizeBxx,0);
      Print("NormalizeDouble(InpOrderSizeBx,0) = ",DoubleToString(InpOrderSizeB,16));
      
      double InpOrderSizeSx=InpOrderSizeSxx;
      Print("InpOrderSizeSx = ",DoubleToString(InpOrderSizeSx,16));
      
      double InpOrderSizeS=NormalizeDouble(InpOrderSizeSxx,0);
      Print("NormalizeDouble(InpOrderSizeSx,0) = ",DoubleToString(InpOrderSizeS,16));
      
      Trade.PositionOpen(Symbol(), ORDER_TYPE_BUY, InpOrderSizeB, openPrice, stopLossPrice, takeProfitPrice, InpTradeComment);
      Trade.PositionOpen(Symbol(), ORDER_TYPE_SELL, InpOrderSizeS, openPrice, stopLossPrice, takeProfitPrice, InpTradeComment);
      return((int)Trade.ResultOrder());
      
      }
      
      
      ولكنه لا يدخل صفقات!
      اخي الكريم دائما شوف نافذة الجورنال

      بعدين انا بمشاركتي السابقة قلت لك شوف القيم يلي معادلتك بتخرجها بعدين بامكانك تشوف هل هالقيم مقبولة لحجم اللوت

      تعليق


      • المشاركة الأصلية بواسطة Turkm مشاهدة المشاركة

        اخي الكريم دائما شوف نافذة الجورنال

        بعدين انا بمشاركتي السابقة قلت لك شوف القيم يلي معادلتك بتخرجها بعدين بامكانك تشوف هل هالقيم مقبولة لحجم اللوت
        ونصيحة من مبرمج قديم: لاتعمل اكتر من تعديل بوقت واحد بعدين بتختبر النتائج, فقط كل مرة اعمل تعديل واحد وشوف النتيجة اذا تمام اذن بامكانك تتابع للتعديل التالي

        تعليق


        • المشاركة الأصلية بواسطة Turkm مشاهدة المشاركة

          ونصيحة من مبرمج قديم: لاتعمل اكتر من تعديل بوقت واحد بعدين بتختبر النتائج, فقط كل مرة اعمل تعديل واحد وشوف النتيجة اذا تمام اذن بامكانك تتابع للتعديل التالي
          اخي انت استاذي وانا اتعلم منك
          ومشكور جزيل الشكر على هذا الكم من المعلومات الذي ااخذه منك
          لكن الموضوع معقد معي وارغب في فتح كل صفقة بمبلغ معين وليس بلوت معين
          فهل هذا سهل تنفيذه دون الحاجة لتقريب الارقام والمعادلات؟

          تعليق


          • المشاركة الأصلية بواسطة zooz1o مشاهدة المشاركة

            اخي انت استاذي وانا اتعلم منك
            ومشكور جزيل الشكر على هذا الكم من المعلومات الذي ااخذه منك
            لكن الموضوع معقد معي وارغب في فتح كل صفقة بمبلغ معين وليس بلوت معين
            فهل هذا سهل تنفيذه دون الحاجة لتقريب الارقام والمعادلات؟
            التقريب امر لامفر منه فلازم تستعملو
            ساحاول ان ابحث لك عن دالة لعملية التقريب وتجعلك تعمل بشكل اوتوماتيكي مع جميع المنصات

            اما المعادلات فهذا راجع لك

            تعليق


            • المشاركة الأصلية بواسطة Turkm مشاهدة المشاركة

              التقريب امر لامفر منه فلازم تستعملو
              ساحاول ان ابحث لك عن دالة لعملية التقريب وتجعلك تعمل بشكل اوتوماتيكي مع جميع المنصات

              اما المعادلات فهذا راجع لك
              حسنا اخي مشكور وفي انتظارك

              تعليق


              • السلام عليكم

                انا حقيقي حاولت كتير اظبط تريلينج لكنه مش شغال عند اختباره
                ممكن اخي تشوفلي المشكلة فين؟
                الكود سليم لكن التريلينج مش شغال

                كود HTML:
                input int InpTakeProfitPts = 0;
                input int InpStopLossPts = 0;
                input int TrailingStop = 50;
                //
                // Standard inputs
                //
                input double InpOrderSize = 0.10; // Order size
                input string InpTradeComment = __FILE__; // Trade comment
                input int InpMagicNumber = 2000001; // Magic number
                input int RangeS=121;
                input int RangeT=121;
                input double Goal=3.5;
                input double Spread = 35;
                
                double TakeProfit;
                double StopLoss;
                bool CloseOpposite;
                const string IndicatorName="Test []";
                const int Handle_Buy = 0;
                const int Handle_Sell = 1;
                int Handle;
                double BufferBuy[3];
                double BufferSell[3];
                datetime lastTime = 0;
                //
                // Use CTrade, easier than doing our own coding
                //
                #include <Trade\Trade.mqh>
                CTrade *Trade;
                
                int OnInit() {
                
                //
                // Create a pointer to a ctrade object
                //
                Trade = new CTrade();
                Trade.SetExpertMagicNumber(InpMagicNumber);
                Handle=iCustom(Symbol(),Period(),IndicatorName);
                
                if(Handle==INVALID_HANDLE)
                {
                PrintFormat("Failed",GetLastError());
                return(INIT_FAILED);
                }
                return(INIT_SUCCEEDED);
                }
                
                void OnDeinit(const int reason) {
                IndicatorRelease(Handle);
                
                }
                void OnTick()
                {
                int cnt_B = CopyBuffer(Handle,Handle_Buy,0,3,BufferBuy);
                int cnt_S = CopyBuffer(Handle,Handle_Sell,0,3,BufferSell);
                
                double Previous_Candle_Buy = BufferBuy[1];
                double Current_Candle_Buy = BufferBuy[0];
                
                double Previous_Candle_Sell = BufferSell[1];
                double Current_Candle_Sell = BufferSell[0];
                
                
                bool buyCondition = false;
                bool sellCondition = false;
                
                if(lastTime != iTime(Symbol(), 0, 1))
                {
                lastTime = iTime(Symbol(), 0, 1);
                }
                else
                {
                return;
                }
                if( Previous_Candle_Buy ==iLow(_Symbol, PERIOD_CURRENT,1)) { buyCondition = true;}
                if( Previous_Candle_Sell ==iHigh(_Symbol, PERIOD_CURRENT,1)) { sellCondition = true;}
                
                double point = SymbolInfoDouble(Symbol(), SYMBOL_POINT);
                TakeProfit = InpTakeProfitPts * point;
                StopLoss = InpStopLossPts * point;
                
                CloseOpposite = false;
                
                
                if (buyCondition) {
                if (CloseOpposite) CloseAll(POSITION_TYPE_SELL);
                OrderOpen(ORDER_TYPE_BUY, StopLoss, TakeProfit);
                } else
                if (sellCondition) {
                if (CloseOpposite) CloseAll(POSITION_TYPE_BUY);
                OrderOpen(ORDER_TYPE_SELL, StopLoss, TakeProfit);
                }
                
                //
                // Save any information for next time
                //
                
                return;
                
                }
                
                //+------------------------------------------------------------------+
                //| |
                //+------------------------------------------------------------------+
                double Highest(string symbol,ENUM_TIMEFRAMES timeframe,int count=WHOLE_ARRAY,int start=0)
                {
                double highest=0;
                double High[];
                ArraySetAsSeries(High,true);
                int copied=CopyHigh(symbol,timeframe,start,count,High) ;
                int index=ArrayMaximum(High,0,count)+start;
                if(copied>0 && index<copied) highest=High[index];
                return(highest);
                }
                //+------------------------------------------------------------------+
                //| |
                //+------------------------------------------------------------------+
                double Lowest(string symbol,ENUM_TIMEFRAMES timeframe,int count=WHOLE_ARRAY,int start=0)
                {
                double lowest=0;
                double Low[];
                ArraySetAsSeries(Low,true);
                int copied=CopyLow(symbol,timeframe,start,count,Low);
                int index=ArrayMinimum(Low,0,count)+start;
                if(copied>0 && index<copied) lowest=Low[index];
                return(lowest);
                }
                
                
                //
                // true/false has the bar changed
                //
                bool NewBar() {
                
                static datetime priorTime = 0;
                datetime currentTime = iTime(Symbol(), Period(), 0);
                bool result = (currentTime!=priorTime);
                priorTime = currentTime;
                return(result);
                
                }
                
                //
                // Close all trades of the specified type - for strategies that call for closing the opposite side
                //
                void CloseAll(ENUM_POSITION_TYPE positionType) {
                
                int cnt = PositionsTotal();
                for (int i = cnt-1; i>=0; i--) {
                ulong ticket = PositionGetTicket(i);
                if (ticket>0) {
                if (PositionGetString(POSITION_SYMBOL)==Symbol() && PositionGetInteger(POSITION_MAGIC)==InpMagicNumber && PositionGetInteger(POSITION_TYPE)==positionType) {
                Trade.PositionClose(ticket);
                }
                }
                }
                
                }
                
                //
                // Simple function to open a new order
                //
                int OrderOpen(ENUM_ORDER_TYPE orderType, double stopLoss, double takeProfit) {
                
                double openPrice;
                double stopLossPrice;
                double takeProfitPrice;
                
                //
                // Calculate the open price, take profit and stop loss prices ****d on the order type
                //
                double point = SymbolInfoDouble(Symbol(), SYMBOL_POINT);
                if (orderType==ORDER_TYPE_BUY) {
                openPrice = NormalizeDouble(SymbolInfoDouble(Symbol(), SYMBOL_ASK), Digits());
                stopLossPrice = (((Lowest(Symbol() , _Period, RangeS, 0)))-(Spread*point));
                takeProfitPrice =(((((iClose(Symbol() ,PERIOD_CURRENT,1))-(Lowest(Symbol() , _Period, RangeT, 0)))*Goal)+(Lowest(Symbol() , _Period, RangeT, 0)))-(Spread*point));
                int cnt = PositionsTotal();
                for (int i = cnt-1; i>=0; i--) {
                ulong ticket = PositionGetTicket(i);
                if(TrailingStop>0)
                {
                if(SymbolInfoDouble(_Symbol,SYMBOL_BID)-PositionGetDouble(POSITION_PRICE_OPEN)>point*Trail ingStop)
                {
                if(PositionGetDouble(POSITION_SL)<SymbolInfoDouble (_Symbol,SYMBOL_BID)-point*TrailingStop)
                {
                Trade.PositionModify(ticket,SymbolInfoDouble(_Symb ol,SYMBOL_BID)-point*TrailingStop,PositionGetDouble(POSITION_TP)) ;
                return (0);
                }
                }
                }
                }
                } else if (orderType==ORDER_TYPE_SELL) {
                openPrice = NormalizeDouble(SymbolInfoDouble(Symbol(), SYMBOL_BID), Digits());
                stopLossPrice = (((Highest(Symbol() , _Period, RangeS, 0)))+(Spread*point));
                takeProfitPrice =(((Highest(Symbol() , _Period, RangeT, 0))-(((Highest(Symbol() , _Period, RangeT, 0))-(iClose(Symbol() ,PERIOD_CURRENT,1)))*Goal))+(Spread*point));
                int cnt = PositionsTotal();
                for (int i = cnt-1; i>=0; i--) {
                ulong ticket = PositionGetTicket(i);
                if(TrailingStop>0)
                {
                if(PositionGetDouble(POSITION_PRICE_OPEN)-SymbolInfoDouble(_Symbol,SYMBOL_ASK)>point*Trailin gStop)
                {
                if(PositionGetDouble(POSITION_SL)>SymbolInfoDouble (_Symbol,SYMBOL_ASK)+point*TrailingStop)
                {
                Trade.PositionModify(ticket,SymbolInfoDouble(_Symb ol,SYMBOL_ASK)+point*TrailingStop,PositionGetDoubl e(POSITION_TP));
                return (0);
                }
                }
                }
                }
                } else {
                // This function only works with type buy or sell
                return(-1);
                }
                
                Trade.PositionOpen(Symbol(), orderType, InpOrderSize, openPrice, stopLossPrice, takeProfitPrice, InpTradeComment);
                
                return((int)Trade.ResultOrder());
                
                }
                
                
                الملفات المرفقة

                تعليق


                • دالة التقريب

                  ضع هذه المتغيرات في قسم المتغيرات العامة يعني فوق
                  كود:
                  double point;
                  int _digits,P;
                  int lot_digits;
                  بعدين داخل دالة OnInit() ضع هذا الكود

                  كود:
                  if(SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_MIN) < 0.1)
                  lot_digits=2;
                  else
                  lot_digits=1;
                  if(Digits() == 5 || Digits() == 3)
                  P = 10;
                  else
                  P=1;
                  if(Digits() < 4)
                  {
                  point=0.01;
                  _digits=2;
                  }
                  else
                  {
                  point=0.0001;
                  _digits=4;
                  }
                  الآن قبل ان تقوم بارسال امر البيع او الشراء قم بحساب اللوت على الشكل التالي:

                  كود:
                  double sLot = NormalizeDouble(Lots, lot_digits);
                  طبعا متغير Lots تقوم بادخاله من متغيرات الاكسبيرت ويمكنك ايضا ان تقوم بحساب قيمة هذه المتغير الجديدة حسب المعادلة التي تريدها

                  تعليق


                  • المشاركة الأصلية بواسطة zooz1o مشاهدة المشاركة
                    السلام عليكم

                    انا حقيقي حاولت كتير اظبط تريلينج لكنه مش شغال عند اختباره
                    ممكن اخي تشوفلي المشكلة فين؟
                    الكود سليم لكن التريلينج مش شغال

                    كود HTML:
                    input int InpTakeProfitPts = 0;
                    input int InpStopLossPts = 0;
                    input int TrailingStop = 50;
                    //
                    // Standard inputs
                    //
                    input double InpOrderSize = 0.10; // Order size
                    input string InpTradeComment = __FILE__; // Trade comment
                    input int InpMagicNumber = 2000001; // Magic number
                    input int RangeS=121;
                    input int RangeT=121;
                    input double Goal=3.5;
                    input double Spread = 35;
                    
                    double TakeProfit;
                    double StopLoss;
                    bool CloseOpposite;
                    const string IndicatorName="Test []";
                    const int Handle_Buy = 0;
                    const int Handle_Sell = 1;
                    int Handle;
                    double BufferBuy[3];
                    double BufferSell[3];
                    datetime lastTime = 0;
                    //
                    // Use CTrade, easier than doing our own coding
                    //
                    #include <Trade\Trade.mqh>
                    CTrade *Trade;
                    
                    int OnInit() {
                    
                    //
                    // Create a pointer to a ctrade object
                    //
                    Trade = new CTrade();
                    Trade.SetExpertMagicNumber(InpMagicNumber);
                    Handle=iCustom(Symbol(),Period(),IndicatorName);
                    
                    if(Handle==INVALID_HANDLE)
                    {
                    PrintFormat("Failed",GetLastError());
                    return(INIT_FAILED);
                    }
                    return(INIT_SUCCEEDED);
                    }
                    
                    void OnDeinit(const int reason) {
                    IndicatorRelease(Handle);
                    
                    }
                    void OnTick()
                    {
                    int cnt_B = CopyBuffer(Handle,Handle_Buy,0,3,BufferBuy);
                    int cnt_S = CopyBuffer(Handle,Handle_Sell,0,3,BufferSell);
                    
                    double Previous_Candle_Buy = BufferBuy[1];
                    double Current_Candle_Buy = BufferBuy[0];
                    
                    double Previous_Candle_Sell = BufferSell[1];
                    double Current_Candle_Sell = BufferSell[0];
                    
                    
                    bool buyCondition = false;
                    bool sellCondition = false;
                    
                    if(lastTime != iTime(Symbol(), 0, 1))
                    {
                    lastTime = iTime(Symbol(), 0, 1);
                    }
                    else
                    {
                    return;
                    }
                    if( Previous_Candle_Buy ==iLow(_Symbol, PERIOD_CURRENT,1)) { buyCondition = true;}
                    if( Previous_Candle_Sell ==iHigh(_Symbol, PERIOD_CURRENT,1)) { sellCondition = true;}
                    
                    double point = SymbolInfoDouble(Symbol(), SYMBOL_POINT);
                    TakeProfit = InpTakeProfitPts * point;
                    StopLoss = InpStopLossPts * point;
                    
                    CloseOpposite = false;
                    
                    
                    if (buyCondition) {
                    if (CloseOpposite) CloseAll(POSITION_TYPE_SELL);
                    OrderOpen(ORDER_TYPE_BUY, StopLoss, TakeProfit);
                    } else
                    if (sellCondition) {
                    if (CloseOpposite) CloseAll(POSITION_TYPE_BUY);
                    OrderOpen(ORDER_TYPE_SELL, StopLoss, TakeProfit);
                    }
                    
                    //
                    // Save any information for next time
                    //
                    
                    return;
                    
                    }
                    
                    //+------------------------------------------------------------------+
                    //| |
                    //+------------------------------------------------------------------+
                    double Highest(string symbol,ENUM_TIMEFRAMES timeframe,int count=WHOLE_ARRAY,int start=0)
                    {
                    double highest=0;
                    double High[];
                    ArraySetAsSeries(High,true);
                    int copied=CopyHigh(symbol,timeframe,start,count,High) ;
                    int index=ArrayMaximum(High,0,count)+start;
                    if(copied>0 && index<copied) highest=High[index];
                    return(highest);
                    }
                    //+------------------------------------------------------------------+
                    //| |
                    //+------------------------------------------------------------------+
                    double Lowest(string symbol,ENUM_TIMEFRAMES timeframe,int count=WHOLE_ARRAY,int start=0)
                    {
                    double lowest=0;
                    double Low[];
                    ArraySetAsSeries(Low,true);
                    int copied=CopyLow(symbol,timeframe,start,count,Low);
                    int index=ArrayMinimum(Low,0,count)+start;
                    if(copied>0 && index<copied) lowest=Low[index];
                    return(lowest);
                    }
                    
                    
                    //
                    // true/false has the bar changed
                    //
                    bool NewBar() {
                    
                    static datetime priorTime = 0;
                    datetime currentTime = iTime(Symbol(), Period(), 0);
                    bool result = (currentTime!=priorTime);
                    priorTime = currentTime;
                    return(result);
                    
                    }
                    
                    //
                    // Close all trades of the specified type - for strategies that call for closing the opposite side
                    //
                    void CloseAll(ENUM_POSITION_TYPE positionType) {
                    
                    int cnt = PositionsTotal();
                    for (int i = cnt-1; i>=0; i--) {
                    ulong ticket = PositionGetTicket(i);
                    if (ticket>0) {
                    if (PositionGetString(POSITION_SYMBOL)==Symbol() && PositionGetInteger(POSITION_MAGIC)==InpMagicNumber && PositionGetInteger(POSITION_TYPE)==positionType) {
                    Trade.PositionClose(ticket);
                    }
                    }
                    }
                    
                    }
                    
                    //
                    // Simple function to open a new order
                    //
                    int OrderOpen(ENUM_ORDER_TYPE orderType, double stopLoss, double takeProfit) {
                    
                    double openPrice;
                    double stopLossPrice;
                    double takeProfitPrice;
                    
                    //
                    // Calculate the open price, take profit and stop loss prices ****d on the order type
                    //
                    double point = SymbolInfoDouble(Symbol(), SYMBOL_POINT);
                    if (orderType==ORDER_TYPE_BUY) {
                    openPrice = NormalizeDouble(SymbolInfoDouble(Symbol(), SYMBOL_ASK), Digits());
                    stopLossPrice = (((Lowest(Symbol() , _Period, RangeS, 0)))-(Spread*point));
                    takeProfitPrice =(((((iClose(Symbol() ,PERIOD_CURRENT,1))-(Lowest(Symbol() , _Period, RangeT, 0)))*Goal)+(Lowest(Symbol() , _Period, RangeT, 0)))-(Spread*point));
                    int cnt = PositionsTotal();
                    for (int i = cnt-1; i>=0; i--) {
                    ulong ticket = PositionGetTicket(i);
                    if(TrailingStop>0)
                    {
                    if(SymbolInfoDouble(_Symbol,SYMBOL_BID)-PositionGetDouble(POSITION_PRICE_OPEN)>point*Trail ingStop)
                    {
                    if(PositionGetDouble(POSITION_SL)<SymbolInfoDouble (_Symbol,SYMBOL_BID)-point*TrailingStop)
                    {
                    Trade.PositionModify(ticket,SymbolInfoDouble(_Symb ol,SYMBOL_BID)-point*TrailingStop,PositionGetDouble(POSITION_TP)) ;
                    return (0);
                    }
                    }
                    }
                    }
                    } else if (orderType==ORDER_TYPE_SELL) {
                    openPrice = NormalizeDouble(SymbolInfoDouble(Symbol(), SYMBOL_BID), Digits());
                    stopLossPrice = (((Highest(Symbol() , _Period, RangeS, 0)))+(Spread*point));
                    takeProfitPrice =(((Highest(Symbol() , _Period, RangeT, 0))-(((Highest(Symbol() , _Period, RangeT, 0))-(iClose(Symbol() ,PERIOD_CURRENT,1)))*Goal))+(Spread*point));
                    int cnt = PositionsTotal();
                    for (int i = cnt-1; i>=0; i--) {
                    ulong ticket = PositionGetTicket(i);
                    if(TrailingStop>0)
                    {
                    if(PositionGetDouble(POSITION_PRICE_OPEN)-SymbolInfoDouble(_Symbol,SYMBOL_ASK)>point*Trailin gStop)
                    {
                    if(PositionGetDouble(POSITION_SL)>SymbolInfoDouble (_Symbol,SYMBOL_ASK)+point*TrailingStop)
                    {
                    Trade.PositionModify(ticket,SymbolInfoDouble(_Symb ol,SYMBOL_ASK)+point*TrailingStop,PositionGetDoubl e(POSITION_TP));
                    return (0);
                    }
                    }
                    }
                    }
                    } else {
                    // This function only works with type buy or sell
                    return(-1);
                    }
                    
                    Trade.PositionOpen(Symbol(), orderType, InpOrderSize, openPrice, stopLossPrice, takeProfitPrice, InpTradeComment);
                    
                    return((int)Trade.ResultOrder());
                    
                    }
                    
                    


                    راجع هذه المقالة

                    The basic rule of trader - let profit to grow, cut off losses! This article considers one of the basic techniques, allowing to follow this rule - moving the protective stop level (Stop loss level) after increasing position profit, i.e. - Trailing Stop level. You'll find the step by step procedure to create a class for trailing stop on SAR and NRTR indicators. Everyone will be able to insert this trailing stop into their experts or use it independently to control positions in their accounts.

                    تعليق


                    • المشاركة الأصلية بواسطة Turkm مشاهدة المشاركة



                      راجع هذه المقالة

                      https://www.mql5.com/en/articles/134
                      مشكور اخي تم حل مشكلة التريلينج بنجاح جزاك الله خيرا
                      سأجرب دالة التقريب في اقرب وقت وسأخبرك بالنتائج ان شاء الله

                      الان لدي مشكلة وهو ان هذا الكود الذي اعطيتهوني:
                      كود HTML:
                      if(lastTime != iTime(Symbol(), 0, 1))
                      {
                      lastTime = iTime(Symbol(), 0, 1);
                      }
                      else
                      {
                      return;
                      }
                      عندما قومت بأضافته في الاكسبيرت هو فعلا منع فتح صفقات زيادة في نفس الشمعة ونجح في ذلك،
                      لكن عندما اضع شرط الدخول هو ملامسة هاي الشمعة 0 (الحالية) لمستوى معين؛ بسبب هذا الكود يمنع اخذ الصفقات

                      السؤال: كيف أوفّق بين شرط عدم دخول اكثر من صفقة في نفس الشمعة وشرط الفتح عند الملامسة؟

                      ملحوظة: عندما قومت بتكرار دالة الوقت مرتان في الشراء والبيع بعد شرط الملامسة نجحت في عدم اخذ اكثر من صفقة بيع ونجحت في الفتح عند الملامسة ولكنها منعت فتح صفقات الشراء!

                      هذا الكود:

                      كود HTML:
                      double MyPoint=_Point;
                      if(_Digits==2 || _Digits==5) MyPoint=_Point*10;
                      double TheStopLoss=0;
                      double TheTakeProfit=0;
                      
                      {
                      
                      if(((iHigh(_Symbol, PERIOD_D1,1))-(iLow(_Symbol, PERIOD_D1,1)))<5
                      && iOpen(_Symbol, PERIOD_D1,0)>((iClose(_Symbol, PERIOD_D1,1))-(((iHigh(_Symbol, PERIOD_D1,1))-(iLow(_Symbol, PERIOD_D1,1)))/4))
                      && iLow(_Symbol, PERIOD_D1,0)<=((iClose(_Symbol, PERIOD_D1,1))-(((iHigh(_Symbol, PERIOD_D1,1))-(iLow(_Symbol, PERIOD_D1,1)))/4))
                      
                      )
                      {
                      if(lastTime != iTime(Symbol(), 0, 1))
                      {
                      lastTime = iTime(Symbol(), 0, 1);
                      }
                      else
                      {
                      return;
                      }
                      if(StopLoss>0) TheStopLoss=SymbolInfoDouble(_Symbol,SYMBOL_ASK)-StopLoss*MyPoint;
                      if(TakeProfit>0) TheTakeProfit=SymbolInfoDouble(_Symbol,SYMBOL_ASK) +TakeProfit*MyPoint;
                      Trade.PositionOpen(_Symbol,ORDER_TYPE_BUY,Lots,Sym bolInfoDouble(_Symbol,SYMBOL_ASK),TheStopLoss,TheT akeProfit);
                      return;
                      }
                      if(((iHigh(_Symbol, PERIOD_D1,1))-(iLow(_Symbol, PERIOD_D1,1)))<5
                      && iOpen(_Symbol, PERIOD_D1,0)<((iClose(_Symbol, PERIOD_D1,1))+(((iHigh(_Symbol, PERIOD_D1,1))-(iLow(_Symbol, PERIOD_D1,1)))/4))
                      && iHigh(_Symbol, PERIOD_D1,0)>=((iClose(_Symbol, PERIOD_D1,1))+(((iHigh(_Symbol, PERIOD_D1,1))-(iLow(_Symbol, PERIOD_D1,1)))/4))
                      
                      )
                      {
                      if(lastTime != iTime(Symbol(), 0, 1))
                      {
                      lastTime = iTime(Symbol(), 0, 1);
                      }
                      else
                      {
                      return;
                      }
                      if(StopLoss>0) TheStopLoss=SymbolInfoDouble(_Symbol,SYMBOL_ASK)+S topLoss*MyPoint;
                      if(TakeProfit>0) TheTakeProfit=SymbolInfoDouble(_Symbol,SYMBOL_ASK)-TakeProfit*MyPoint;
                      Trade.PositionOpen(_Symbol,ORDER_TYPE_SELL,Lots,Sy mbolInfoDouble(_Symbol,SYMBOL_BID),TheStopLoss,The TakeProfit);
                      return;
                      }
                      الملفات المرفقة

                      تعليق


                      • المشاركة الأصلية بواسطة Turkm مشاهدة المشاركة



                        راجع هذه المقالة

                        https://www.mql5.com/en/articles/134
                        مشكور اخي تم حل مشكلة التريلينج بنجاح جزاك الله خيرا
                        سأجرب دالة التقريب في اقرب وقت وسأخبرك بالنتائج ان شاء الله

                        الان لدي مشكلة وهو ان هذا الكود الذي اعطيتهوني:
                        كود HTML:
                        if(lastTime != iTime(Symbol(), 0, 1))
                        {
                        lastTime = iTime(Symbol(), 0, 1);
                        }
                        else
                        {
                        return;
                        }
                        عندما قومت بأضافته في الاكسبيرت هو فعلا منع فتح صفقات زيادة في نفس الشمعة ونجح في ذلك،
                        لكن عندما اضع شرط الدخول هو ملامسة هاي الشمعة 0 (الحالية) لمستوى معين؛ بسبب هذا الكود يمنع اخذ الصفقات

                        السؤال: كيف أوفّق بين شرط عدم دخول اكثر من صفقة في نفس الشمعة وشرط الفتح عند الملامسة؟

                        ملحوظة: عندما قومت بتكرار دالة الوقت مرتان في الشراء والبيع بعد شرط الملامسة نجحت في عدم اخذ اكثر من صفقة بيع ونجحت في الفتح عند الملامسة ولكنها منعت فتح صفقات الشراء!

                        هذا الكود:

                        كود HTML:
                        double MyPoint=_Point;
                        if(_Digits==2 || _Digits==5) MyPoint=_Point*10;
                        double TheStopLoss=0;
                        double TheTakeProfit=0;
                        
                        {
                        
                        if(((iHigh(_Symbol, PERIOD_D1,1))-(iLow(_Symbol, PERIOD_D1,1)))<5
                        && iOpen(_Symbol, PERIOD_D1,0)>((iClose(_Symbol, PERIOD_D1,1))-(((iHigh(_Symbol, PERIOD_D1,1))-(iLow(_Symbol, PERIOD_D1,1)))/4))
                        && iLow(_Symbol, PERIOD_D1,0)<=((iClose(_Symbol, PERIOD_D1,1))-(((iHigh(_Symbol, PERIOD_D1,1))-(iLow(_Symbol, PERIOD_D1,1)))/4))
                        
                        )
                        {
                        if(lastTime != iTime(Symbol(), 0, 1))
                        {
                        lastTime = iTime(Symbol(), 0, 1);
                        }
                        else
                        {
                        return;
                        }
                        if(StopLoss>0) TheStopLoss=SymbolInfoDouble(_Symbol,SYMBOL_ASK)-StopLoss*MyPoint;
                        if(TakeProfit>0) TheTakeProfit=SymbolInfoDouble(_Symbol,SYMBOL_ASK) +TakeProfit*MyPoint;
                        Trade.PositionOpen(_Symbol,ORDER_TYPE_BUY,Lots,Sym bolInfoDouble(_Symbol,SYMBOL_ASK),TheStopLoss,TheT akeProfit);
                        return;
                        }
                        if(((iHigh(_Symbol, PERIOD_D1,1))-(iLow(_Symbol, PERIOD_D1,1)))<5
                        && iOpen(_Symbol, PERIOD_D1,0)<((iClose(_Symbol, PERIOD_D1,1))+(((iHigh(_Symbol, PERIOD_D1,1))-(iLow(_Symbol, PERIOD_D1,1)))/4))
                        && iHigh(_Symbol, PERIOD_D1,0)>=((iClose(_Symbol, PERIOD_D1,1))+(((iHigh(_Symbol, PERIOD_D1,1))-(iLow(_Symbol, PERIOD_D1,1)))/4))
                        
                        )
                        {
                        if(lastTime != iTime(Symbol(), 0, 1))
                        {
                        lastTime = iTime(Symbol(), 0, 1);
                        }
                        else
                        {
                        return;
                        }
                        if(StopLoss>0) TheStopLoss=SymbolInfoDouble(_Symbol,SYMBOL_ASK)+S topLoss*MyPoint;
                        if(TakeProfit>0) TheTakeProfit=SymbolInfoDouble(_Symbol,SYMBOL_ASK)-TakeProfit*MyPoint;
                        Trade.PositionOpen(_Symbol,ORDER_TYPE_SELL,Lots,Sy mbolInfoDouble(_Symbol,SYMBOL_BID),TheStopLoss,The TakeProfit);
                        return;
                        }
                        الملفات المرفقة

                        تعليق


                        • المشاركة الأصلية بواسطة Turkm مشاهدة المشاركة



                          راجع هذه المقالة

                          https://www.mql5.com/en/articles/134
                          مشكور اخي تم حل مشكلة التريلينج بنجاح جزاك الله خيرا
                          سأجرب دالة التقريب في اقرب وقت وسأخبرك بالنتائج ان شاء الله
                          وليس هناك اي مشاكل اخرى في الوقت الحالي ولله الحمد

                          تعليق


                          • المشاركة الأصلية بواسطة zooz1o مشاهدة المشاركة

                            مشكور اخي تم حل مشكلة التريلينج بنجاح جزاك الله خيرا
                            سأجرب دالة التقريب في اقرب وقت وسأخبرك بالنتائج ان شاء الله

                            الان لدي مشكلة وهو ان هذا الكود الذي اعطيتهوني:
                            كود HTML:
                            if(lastTime != iTime(Symbol(), 0, 1))
                            {
                            lastTime = iTime(Symbol(), 0, 1);
                            }
                            else
                            {
                            return;
                            }
                            عندما قومت بأضافته في الاكسبيرت هو فعلا منع فتح صفقات زيادة في نفس الشمعة ونجح في ذلك،
                            لكن عندما اضع شرط الدخول هو ملامسة هاي الشمعة 0 (الحالية) لمستوى معين؛ بسبب هذا الكود يمنع اخذ الصفقات

                            السؤال: كيف أوفّق بين شرط عدم دخول اكثر من صفقة في نفس الشمعة وشرط الفتح عند الملامسة؟


                            لايمكن لان هذا الكود فقط يسمح بتنفيذ مابعده فقط عىد افتتاح شمعة جديدة



                            ملحوظة: عندما قومت بتكرار دالة الوقت مرتان في الشراء والبيع بعد شرط الملامسة نجحت في عدم اخذ اكثر من صفقة بيع ونجحت في الفتح عند الملامسة ولكنها منعت فتح صفقات الشراء!

                            هذا الكود:

                            كود HTML:
                            double MyPoint=_Point;
                            if(_Digits==2 || _Digits==5) MyPoint=_Point*10;
                            double TheStopLoss=0;
                            double TheTakeProfit=0;
                            
                            {
                            
                            if(((iHigh(_Symbol, PERIOD_D1,1))-(iLow(_Symbol, PERIOD_D1,1)))<5
                            && iOpen(_Symbol, PERIOD_D1,0)>((iClose(_Symbol, PERIOD_D1,1))-(((iHigh(_Symbol, PERIOD_D1,1))-(iLow(_Symbol, PERIOD_D1,1)))/4))
                            && iLow(_Symbol, PERIOD_D1,0)<=((iClose(_Symbol, PERIOD_D1,1))-(((iHigh(_Symbol, PERIOD_D1,1))-(iLow(_Symbol, PERIOD_D1,1)))/4))
                            
                            )
                            {
                            if(lastTime != iTime(Symbol(), 0, 1))
                            {
                            lastTime = iTime(Symbol(), 0, 1);
                            }
                            else
                            {
                            return;
                            }
                            if(StopLoss>0) TheStopLoss=SymbolInfoDouble(_Symbol,SYMBOL_ASK)-StopLoss*MyPoint;
                            if(TakeProfit>0) TheTakeProfit=SymbolInfoDouble(_Symbol,SYMBOL_ASK) +TakeProfit*MyPoint;
                            Trade.PositionOpen(_Symbol,ORDER_TYPE_BUY,Lots,Sym bolInfoDouble(_Symbol,SYMBOL_ASK),TheStopLoss,TheT akeProfit);
                            return;
                            }
                            if(((iHigh(_Symbol, PERIOD_D1,1))-(iLow(_Symbol, PERIOD_D1,1)))<5
                            && iOpen(_Symbol, PERIOD_D1,0)<((iClose(_Symbol, PERIOD_D1,1))+(((iHigh(_Symbol, PERIOD_D1,1))-(iLow(_Symbol, PERIOD_D1,1)))/4))
                            && iHigh(_Symbol, PERIOD_D1,0)>=((iClose(_Symbol, PERIOD_D1,1))+(((iHigh(_Symbol, PERIOD_D1,1))-(iLow(_Symbol, PERIOD_D1,1)))/4))
                            
                            )
                            {
                            if(lastTime != iTime(Symbol(), 0, 1))
                            {
                            lastTime = iTime(Symbol(), 0, 1);
                            }
                            else
                            {
                            return;
                            }
                            if(StopLoss>0) TheStopLoss=SymbolInfoDouble(_Symbol,SYMBOL_ASK)+S topLoss*MyPoint;
                            if(TakeProfit>0) TheTakeProfit=SymbolInfoDouble(_Symbol,SYMBOL_ASK)-TakeProfit*MyPoint;
                            Trade.PositionOpen(_Symbol,ORDER_TYPE_SELL,Lots,Sy mbolInfoDouble(_Symbol,SYMBOL_BID),TheStopLoss,The TakeProfit);
                            return;
                            }

                            اهلا اخي الكريم

                            الرد في الاقتباس

                            تعليق


                            • انظر اخي وضعت الشروط كما اخبرتني
                              واستبدلت الرقم 0.1 الموجود في الكود:
                              كود HTML:
                              double MyPoint=_Point;
                              if(_Digits==2 || _Digits==5) MyPoint=_Point*10;
                              double TheStopLoss=0;
                              double TheTakeProfit=0;
                              double Lots =0.1;
                              double sLot = NormalizeDouble(Lots, lot_digits);
                              {
                              بهذه المعادلة:
                              كود HTML:
                              double MyPoint=_Point;
                              if(_Digits==2 || _Digits==5) MyPoint=_Point*10;
                              double TheStopLoss=0;
                              double TheTakeProfit=0;
                              double Lots =400/1000;
                              double sLot = NormalizeDouble(Lots, lot_digits);
                              {
                              وكنت متوقع انه سيأخذ صفقات بلوت 0.4
                              ولكنه لم يأخذ اي صفقات!
                              الملفات المرفقة

                              تعليق


                              • المشاركة الأصلية بواسطة zooz1o مشاهدة المشاركة
                                انظر اخي وضعت الشروط كما اخبرتني
                                واستبدلت الرقم 0.1 الموجود في الكود:
                                كود HTML:
                                double MyPoint=_Point;
                                if(_Digits==2 || _Digits==5) MyPoint=_Point*10;
                                double TheStopLoss=0;
                                double TheTakeProfit=0;
                                double Lots =0.1;
                                double sLot = NormalizeDouble(Lots, lot_digits);
                                {
                                بهذه المعادلة:
                                كود HTML:
                                double MyPoint=_Point;
                                if(_Digits==2 || _Digits==5) MyPoint=_Point*10;
                                double TheStopLoss=0;
                                double TheTakeProfit=0;
                                double Lots =400/1000;
                                double sLot = NormalizeDouble(Lots, lot_digits);
                                {
                                وكنت متوقع انه سيأخذ صفقات بلوت 0.4
                                ولكنه لم يأخذ اي صفقات!


                                طيب استبدل قيمة متغير اللوت ب 0.4 مباشرة وشوف لو كان حياخد اللوت او لا

                                تعليق

                                يعمل...
                                X