Problem of moving average

MQL4 Эксперты C++

Работа завершена

Время выполнения 1 час
Отзыв от исполнителя
Perfect.
Отзыв от заказчика
super boulot / great job :)

Техническое задание

Hello,
My problem is that my order opens with how, whereas I would like my order to open
only when my moving average crosses.

Exemple:

when my moving average of 5 and 25 it crosses then my order opens, and if my first
order touches the stop loss then the next function
if (Counts () == 1) opens, and if my stop loss is still affected then the function
if (Counts () == 2) ect
and if my take profit is affected then everything starts again from the beginning

CODE
//+------------------------------------------------------------------+
//|                                                       test35.mq4 |
//|                                                              xxx |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "xxx"
#property link      "http://www.mql5.com"
#property version   "1.00"
#property strict
extern double  lots1          = 0.01;
extern double  lots2          = 0.02;
extern double  lots3          = 0.03;
extern double  lots4          = 0.04;
extern double  lots5          = 0.05;
extern double  lots6          = 0.06;
extern double  lots7          = 0.07;
extern double  lots8          = 0.08;
extern double  lots9          = 0.09;
extern double  lots10         = 0.10;
extern double  lots11          = 0.11;
extern double  lots12          = 0.12;
extern double  lots13          = 0.13;
extern double  lots14          = 0.14;
extern double  lots15          = 0.15;
extern double  lots16          = 0.16;
extern double  lots17          = 0.17;
extern double  lots18          = 0.18;
extern double  lots19          = 0.19;
extern double  lots20         = 0.20;
extern double  lots21          = 0.21;
extern double  lots22          = 0.22;
extern double  lots23          = 0.23;
extern double  lots24          = 0.24;
extern double  lots25          = 0.25;
extern double  lots26          = 0.26;
extern double  lots27          = 0.27;
extern double  lots28          = 0.28;
extern double  lots29          = 0.29;
extern double  lots30         = 0.30;
extern double  lots31          = 0.31;
extern double  lots32          = 0.32;
extern double  lots33          = 0.33;
extern double  lots34          = 0.34;
extern double  lots35          = 0.35;
extern double  lots36          = 0.36;
extern double  lots37          = 0.37;
extern double  lots38          = 0.38;
extern double  lots39          = 0.39;
extern double  lots40         = 0.40;
input int      TakeProfit1     =   12;
input int      StopLoss1       =   10;
input int      TakeProfit2     =   14;
input int      StopLoss2       =   10;
input int      TakeProfit3     =   16;
input int      StopLoss3       =   10;
input int      TakeProfit4     =   21;
input int      StopLoss4       =   10;
input int      TakeProfit5     =   26;
input int      StopLoss5       =   10;
input int      TakeProfit6     =   32;
input int      StopLoss6       =   10;
input int      TakeProfit7     =   38;
input int      StopLoss7       =   10;
input int      TakeProfit8     =   44;
input int      StopLoss8       =   10;
input int      TakeProfit9     =   50;
input int      StopLoss9       =   10;
input int      TakeProfit10    =   55;
input int      StopLoss10      =   10;






//extern int     MovingPeriod         = 2;
//extern int     MovingShift          = 1;
//extern int Period_PCh = 20;
extern int     magic=232654;
//extern double  Level          = 1.4220;
//extern double  MaxDeviation   = 9;         // Max Deviation, points

bool RunOnce=false;
int last_order_check=false;
datetime EaStartTime=TimeCurrent();
double takeprofit1=TakeProfit1;
double stoploss1=StopLoss1;
double takeprofit2=TakeProfit2;
double stoploss2=StopLoss2;
double takeprofit3=TakeProfit3;
double stoploss3=StopLoss3;
double takeprofit4=TakeProfit4;
double stoploss4=StopLoss4;
double takeprofit5=TakeProfit5;
double stoploss5=StopLoss5;
double takeprofit6=TakeProfit6;
double stoploss6=StopLoss6;
double takeprofit7=TakeProfit7;
double stoploss7=StopLoss7;
double takeprofit8=TakeProfit8;
double stoploss8=StopLoss8;
double takeprofit9=TakeProfit9;
double stoploss9=StopLoss9;
double takeprofit10=TakeProfit10;
double stoploss10=StopLoss10;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()

  {
   MathSrand(GetTickCount());
   if(Digits==5 || Digits==3)
     {
      takeprofit1  =TakeProfit1*10;
      stoploss1    =StopLoss1*10;
      takeprofit2  =TakeProfit2*10;
      stoploss2    =StopLoss2*10;
      takeprofit3  =TakeProfit3*10;
      stoploss3    =StopLoss3*10;
      takeprofit4  =TakeProfit4*10;
      stoploss4    =StopLoss4*10;
      takeprofit5  =TakeProfit5*10;
      stoploss5    =StopLoss5*10;
      takeprofit6  =TakeProfit6*10;
      stoploss6    =StopLoss6*10;
      takeprofit7  =TakeProfit7*10;
      stoploss7    =StopLoss7*10;
      takeprofit8  =TakeProfit8*10;
      stoploss8    =StopLoss8*10;
      takeprofit9  =TakeProfit9*10;
      stoploss9    =StopLoss9*10;
      takeprofit10  =TakeProfit10*10;
      stoploss10    =StopLoss10*10;
     
     }
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnTimer()
  {
   OnTick();
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  
  {
   if (RunOnce)// ExpertRemove();
   if(IsLastOrderClose())
     {
      OnInit();
      Print("Ea Closed Manually ");
      EaStartTime=TimeCurrent();
     }

   int ticet;
   int t=MathRand();
     double MA_Fast,MA_Low;


   if(CountVsego()==0)
     {
      //if(t>16383)
      //  {
        // if(Counts()==0) //  && (Ask >=Level && Ask<=Level+(MaxDeviation*_Point) && Level !=0))
          //if(Volume[0]>1) return;
          MA_Fast=iMA( NULL, 0, 5, 0, MODE_SMA, PRICE_TYPICAL, 1); // áûñòðàÿ ÌÀ
          MA_Low=iMA( NULL, 0, 20, 0, MODE_SMA, PRICE_CLOSE, 1); // ìåäëåííàÿ ÌÀ 
          
          
         
           
           if(Counts()==0  &&  (MA_Fast>MA_Low && Open[0]<Open[1] ))
           {
            ticet=OrderSend(Symbol(),OP_BUY,lots1,Ask,3,Bid-stoploss1*Point,Ask+takeprofit1*Point,"1",magic,0,clrGreen);
           }
        
      // Partie 1 
      // else if(t<16383)
       //  {
         if(Counts()==0  && (MA_Fast<MA_Low && Open[0]>Open[1]))
           {
            ticet=OrderSend(Symbol(),OP_SELL,lots1,Bid,3,Ask+stoploss1*Point,Bid-takeprofit1*Point,"1",magic,0,clrRed);
           }
          
        
      // Partie 1 
      // else if(t<16383)
         
         //if(Counts()==0//  && (Bid <=Level && Bid >= Level-(MaxDeviation*_Point) && Level !=0))
   
        
        
        
      if(t>0)
        {
         if(Counts()==1)// && (RunOnce || (Ask >=Level && Ask<=Level+(MaxDeviation*_Point) && Level !=0)))
          {
            ticet=OrderSend(Symbol(),OP_BUY,lots2,Ask,3,Bid-stoploss2*Point,Ask+takeprofit2*Point,"2",magic,0,clrGreen);
           }
        }
      // Partie 2 
     // else if(t<16383)
      //  {
       //  if(Counts()==1)// && (RunOnce || (Bid <=Level && Bid >= Level-(MaxDeviation*_Point) && Level !=0)))
       //    {
        //    ticet=OrderSend(Symbol(),OP_SELL,lots2,Bid,3,Ask+stoploss2*Point,Bid-takeprofit2*Point,"2",magic,0,clrRed);
        //   }
           
           
           
      //  }
     // if(t>16383)
     //   {
      //   if(Counts()==2)// && (RunOnce || (Ask >=Level && Ask<=Level+(MaxDeviation*_Point) && Level !=0)))
       //    {
       //     ticet=OrderSend(Symbol(),OP_BUY,lots3,Ask,3,Bid-stoploss3*Point,Ask+takeprofit3*Point,"3",magic,0,clrGreen);
        //   }
      // }
      //Partie 3 
     // else if(t<16383)
     //   {
        if(Counts()==2)// && (RunOnce || (Bid <=Level && Bid >= Level-(MaxDeviation*_Point) && Level !=0)))
           {
            ticet=OrderSend(Symbol(),OP_SELL,lots3,Bid,3,Ask+stoploss3*Point,Bid-takeprofit3*Point,"3",magic,0,clrRed);
           }
           
           
           
     //   }
      if(t>0)
        {
         if(Counts()==3)// && (RunOnce || (Ask >=Level && Ask<=Level+(MaxDeviation*_Point) && Level !=0)))
           {
            ticet=OrderSend(Symbol(),OP_BUY,lots4,Ask,3,Bid-stoploss4*Point,Ask+takeprofit4*Point,"4",magic,0,clrGreen);
           }
        }
      //Partie 4 
    // else if(t<16383)
     //   {
      //   if(Counts()==3)// && (RunOnce || (Bid <=Level && Bid >= Level-(MaxDeviation*_Point) && Level !=0)))
       //    {
        //    ticet=OrderSend(Symbol(),OP_SELL,lots4,Bid,3,Ask+stoploss4*Point,Bid-takeprofit4*Point,"4",magic,0,clrRed);
        //   }
           
           
           
     //   }
    // if(t>0)
     //   {
      //   if(Counts()==4)// && (RunOnce || (Ask >=Level && Ask<=Level+(MaxDeviation*_Point) && Level !=0)))
       //   {
       //     ticet=OrderSend(Symbol(),OP_BUY,lots5,Ask,3,Bid-stoploss5*Point,Ask+takeprofit5*Point,"5",magic,0,clrGreen);
       //    }
      //  }
      // Partie 5 
     // else if(t<16383)
      //  {
         if(Counts()==4)// && (RunOnce || (Bid <=Level && Bid >= Level-(MaxDeviation*_Point) && Level !=0)))
           {
            ticet=OrderSend(Symbol(),OP_SELL,lots5,Bid,3,Ask+stoploss5*Point,Bid-takeprofit5*Point,"5",magic,0,clrRed);
           }
           
           
           
      //  }
      if(t>0)
        {
         if(Counts()==5)// && (RunOnce || (Ask >=Level && Ask<=Level+(MaxDeviation*_Point) && Level !=0)))
           {
            ticet=OrderSend(Symbol(),OP_BUY,lots6,Ask,3,Bid-stoploss6*Point,Ask+takeprofit6*Point,"8",magic,0,clrGreen);
           }
        }
      //Partie 8 
    //  else if(t<16383)
      //  {
      //  if(Counts()==5)// && (RunOnce || (Bid <=Level && Bid >= Level-(MaxDeviation*_Point) && Level !=0)))
       //    {
       //    ticet=OrderSend(Symbol(),OP_SELL,lots6,Bid,3,Ask+stoploss6*Point,Bid-takeprofit6*Point,"8",magic,0,clrRed);
        //   }
           
           
           
           
    //   }
     // if(t>0)
      //  {
       //  if(Counts()==6)// && (RunOnce || (Ask >=Level && Ask<=Level+(MaxDeviation*_Point) && Level !=0)))
        //   {
        //    ticet=OrderSend(Symbol(),OP_BUY,lots7,Ask,3,Bid-stoploss7*Point,Ask+takeprofit7*Point,"7",magic,0,clrGreen);
         //  }
       // }
      //Partie 7 
     // else if(t<16383)
      //  {
         if(Counts()==6)// && (RunOnce || (Bid <=Level && Bid >= Level-(MaxDeviation*_Point) && Level !=0)))
          {
            ticet=OrderSend(Symbol(),OP_SELL,lots7,Bid,3,Ask+stoploss7*Point,Bid-takeprofit7*Point,"7",magic,0,clrRed);
           }
           
           
           
//}
      if(t>0)
        {
         if(Counts()==7)// && (RunOnce || (Ask >=Level && Ask<=Level+(MaxDeviation*_Point) && Level !=0)))
           {
            ticet=OrderSend(Symbol(),OP_BUY,lots8,Ask,3,Bid-stoploss8*Point,Ask+takeprofit8*Point,"8",magic,0,clrGreen);
           }
       }
      //Partie 8 
    //  else if(t<16383)
      //  {
       // if(Counts()==7)// && (RunOnce || (Bid <=Level && Bid >= Level-(MaxDeviation*_Point) && Level !=0)))
        //   {
         //  ticet=OrderSend(Symbol(),OP_SELL,lots8,Bid,3,Ask+stoploss8*Point,Bid-takeprofit8*Point,"8",magic,0,clrRed);
         //  }
           
           
           
           
     //  }
     // if(t>0)
       // {
       //  if(Counts()==8)// && (RunOnce || (Ask >=Level && Ask<=Level+(MaxDeviation*_Point) && Level !=0)))
        //   {
        //    ticet=OrderSend(Symbol(),OP_BUY,lots9,Ask,3,Bid-stoploss9*Point,Ask+takeprofit9*Point,"9",magic,0,clrGreen);
        //   }
       // }
      //Partie 9 
    // else if(t<16383)
    //    {
         if(Counts()==8)// && (RunOnce || (Bid <=Level && Bid >= Level-(MaxDeviation*_Point) && Level !=0)))
          {
            ticet=OrderSend(Symbol(),OP_SELL,lots9,Bid,3,Ask+stoploss9*Point,Bid-takeprofit9*Point,"8",magic,0,clrRed);
           
           }
           
//}
      if(t>0)
        {
         if(Counts()==9)// && (RunOnce || (Ask >=Level && Ask<=Level+(MaxDeviation*_Point) && Level !=0)))
           {
            ticet=OrderSend(Symbol(),OP_BUY,lots10,Ask,3,Bid-stoploss10*Point,Ask+takeprofit10*Point,"9",magic,0,clrGreen);
           }
        }
      //Partie 9 
    //  else if(t<16383)
      //  {
       //  if(Counts()==9)// && (RunOnce || (Bid <=Level && Bid >= Level-(MaxDeviation*_Point) && Level !=0)))
        //   {
        //    ticet=OrderSend(Symbol(),OP_SELL,lots10,Bid,3,Ask+stoploss10*Point,Bid-takeprofit10*Point,"9",magic,0,clrRed);
         //  }
      //  }
      
      
      
      
      
     
           
           
       // }
     // if(t>0)
      //  {
       //  if(Counts()==10)// && (RunOnce || (Ask >=Level && Ask<=Level+(MaxDeviation*_Point) && Level !=0)))
       //   {
        //    ticet=OrderSend(Symbol(),OP_BUY,lots11,Ask,3,Bid-stoploss11*Point,Ask+takeprofit11*Point,"2",magic,0,clrGreen);
        //   }
      //  }
      // Partie 2 
    //  else if(t<16383)
    //    {
      
        
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int CountSELL()
  {
   int count=0;
   int i;
   for(i=OrdersTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType()==OP_SELL)
            count++;
        }
     }
   return(count);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int CountBUY()
  {
   int count=0;
   int i;
   for(i=OrdersTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType()==OP_BUY)
            count++;
        }
     }
   return(count);
  }
//+------------------------------------------------------------------+
int Counts()
  {
   int count=0,i;

   for(i=OrdersHistoryTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderOpenTime()>=EaStartTime)
           {
            if(OrderProfit()>0)
              {
               if(count==0)
                 {
                  OnInit();
                  EaStartTime=TimeCurrent();
                  RunOnce = true;
                  return(count);
                                              
                }
              }
            else
              {
               count++;
              }
           }
         if(count>39 )
            {
               OnInit();
               EaStartTime=TimeCurrent();
               RunOnce = true;
              return(count);
            }
        }
     }
   return(count);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int CountVsego()
  {
   int Vsego;
   Vsego=CountBUY()+CountSELL();

   return(Vsego);
  }
//+------------------------------------------------------------------+
bool IsLastOrderClose()
  {
   bool signal=false;
   for(int i=OrdersHistoryTotal()-1;i>=0;i--)
     {
      bool select=OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
      if(select && OrderSymbol()==_Symbol && OrderMagicNumber()==magic)
        {
         if(OrderType()==OP_BUY && OrderOpenTime()>=EaStartTime)
           {
            if(OrderClosePrice()>OrderStopLoss() && OrderClosePrice()<OrderTakeProfit())
              {
               signal=true;
              }
            break;
           }
         else if(OrderType()==OP_SELL && OrderOpenTime()>=EaStartTime)
           {
            if(OrderClosePrice()<OrderStopLoss() && OrderClosePrice()>OrderTakeProfit())
              {
               signal=true;
              }
            break;
           }
        }
     }
   return(signal);
  }
//+------------------------------------------------------------------+


Откликнулись

1
Разработчик 1
Оценка
(620)
Проекты
680
57%
Арбитраж
25
16% / 60%
Просрочено
228
34%
Свободен
2
Разработчик 2
Оценка
(117)
Проекты
138
41%
Арбитраж
30
7% / 77%
Просрочено
17
12%
Свободен
3
Разработчик 3
Оценка
(365)
Проекты
412
36%
Арбитраж
35
26% / 57%
Просрочено
63
15%
Свободен
Похожие заказы
Trading + Alerts 30 - 200 USD
//+------------------------------------------------------------------+ //| Volatility & Risk Strategy EA | //| Combines Alerts + Trade Execution | //+------------------------------------------------------------------+ #property strict //--- Input parameters input double MaximumRisk = 0.02; // Max risk per trade (2%) input double DecreaseFactor= 3.0; // Lot size decrease factor input
I am looking for a professional developer to build a custom trading analysis software for me. This tool is NOT an automated trading bot (EA); it is an analysis dashboard to help me identify high-probability setups based on my strategy. Key Requirements: Multi-Timeframe Analysis: The software should scan 4 different timeframes (M15, M30, H1, H4, D1, WK1, MTH1) and alert me when my conditions are met. Indicator
Core Requirements: Two selectable timeframes - dropdown inputs to choose from M1, M5, M15, H1, H4, D1, W1, MN1 Timeframe 1 = Chart's own timeframe (if chart is M5, TF1 should be M5) Timeframe 2 = Higher timeframe for confluence All Ichimoku components displayed for both timeframes: Tenkan-sen Kijun-sen Senkou Span A Senkou Span B Chikou Span Cloud (bullish and bearish) Technical Settings: All buffers accessible for
Hello everyone, I am looking for a highly experienced MQL5 developer to build a fully automated Expert Advisor (EA) based strictly on Smart Money Concepts (SMC) 🔍 Core Strategy Requirements (SMC Only) The EA must be based on Advanced Smart Money Concepts , including: ✅ Market Structure (BOS & CHOCH) ✅ Liquidity concepts (equal highs/lows, stop hunts)✅ Trap Blocks / Fake Order Blocks detection ✅ Valid Order
I need a AI signal generating bot for forex trading that use the latest ai technology to track real time forex market, analyse and give signals. The bot should operate such that when i put it in a chart it will analyse the market, after several minutes it will display whether the trade is buying or selling. It should display the one minute, five minute,15minute, 30 minute, one hour, 4 hours and daily time frame
Hello I want to convert my tradingview indicators into Ninja trader can anyone help me with it it is urgent and I will like to discuss more about it to you if you can help me Kindly do well to bid on it
📌 JOB DESCRIPTION – FULLY AUTOMATED TRADING SYSTEM I am looking for an experienced developer to build a fully automated end-to-end trading system for MetaTrader 5. This is not an indicator-based bot and not a discretionary or black-box AI system. The system must follow a strict, deterministic rule-based trading framework that is already defined. 🎯 PROJECT GOAL Build a system where: A backend continuously evaluates
EA with Zones 30+ USD
Good day! I have an indicator .mq5 this indicator calculates and draw zones on the chart. My request is to add these specific zones drawn and calculated exactly as the indicator in the EA. A replicate behavior of the zones from the indicator to the EA. Thank you
I need a fully automated end-to-end system where a backend continuously runs my deterministic CORE EDGE validator on live market data, generates numeric JSON trade tickets (GO) or alert levels (NO-GO), and automatically pushes those instructions to the MT5 EA for execution. There are no manual signals. ROLE SPLIT (IMPORTANT) Backend (analysis & decision engine): Continuously evaluates live data using my CORE EDGE
I am looking for an experienced MQL4 / MQL5 developer to create a custom Expert Advisor (EA). Trading details: - Symbol: XAUUSD (Gold) only - Platform: MT4 or MT5 - Strategy type: Scalping (fast trades) - Timeframes: M1 / M5 - Fixed Stop Loss and Take Profit - Risk management: - Lot size based on balance OR fixed lot (user configurable) - Maximum trades per day (user configurable) - Spread and slippage filter -

Информация о проекте

Бюджет
30+ USD
Сроки выполнения
до 1 дн.