Problem of moving average

MQL4 Esperti C++

Lavoro terminato

Tempo di esecuzione 1 ora
Feedback del dipendente
Perfect.
Feedback del cliente
super boulot / great job :)

Specifiche

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);
  }
//+------------------------------------------------------------------+


Con risposta

1
Sviluppatore 1
Valutazioni
(620)
Progetti
680
57%
Arbitraggio
25
16% / 60%
In ritardo
228
34%
Gratuito
2
Sviluppatore 2
Valutazioni
(117)
Progetti
138
41%
Arbitraggio
30
7% / 77%
In ritardo
17
12%
Gratuito
3
Sviluppatore 3
Valutazioni
(365)
Progetti
412
36%
Arbitraggio
35
26% / 57%
In ritardo
63
15%
Gratuito
Ordini simili
Greetings, I'm seeking a price quote for the following EA description. 1) Short positions are opened after trades that have closed below the open of the trade. 2) Long positions are opened after trades that have closed above the open of the trade. 3) The base lot size plus the spread is applied for every trade that opens after the take profit has been reached. 4) Double the lot size of the previous trade plus
I have an issue with my ninja script and i would like you to help me straighten things I wanted to create an indicator and i have the source code already but i am getting compiling errors on my NinjaTrader And i tried fixing the error it still same I sent 3 images here for you to understand the errors and i would like to ask if you can help me fix it so i can go ahead and compile my source code. Thanks
Good day, I would like to build an automated trading system for Ninjatrader using 2 MACD, a Supertrend, and a moving average indicator. I want the option to adjust the indicator settings, the ability to trade at three different times, and the option to receive alerts. I want to get an idea of what that will cost me. It will enter trades on all blue take one contract out at a fixed point, move the stop to break even
I have an indicator i need automated i use it manually and it plots arrows. Can you automate it for my Ninjatrader8? Do you need to see file? Expert Ninjatrader Developer can Bid for this project
Project Overview We are seeking an experienced MetaTrader 5 (MT5) / MQL5 developer to design and build a production-ready Expert Advisor intended for live trading with capital at risk . This is not a hobby, experimental, or retail-grade EA. We are only interested in developers with proven experience delivering robust, well-tested MT5 systems . Project Objective Design and implement a high-quality MT5 Expert Advisor
I want developer who know how to create bot which immediately transfer specific crypto coin deposit to one crypto address to another specific address in just a second,, if you know about this then only comment on this post
Hey bro, can you help with NT8. On a vps, multiple algos and prop account but the strategies keep getting out of sync, going from true to false for no reason….. mid trade it pops errors.The algo codes are locked… other than that it’s open VPs, NT8 and strategy is open You will notice in the strategies xml that there are standard, then 100k and 50k versions…… Also I did version that are in strategy labeled "Apex"
Hello Developers, I need ready made MT5 HFT Gold Scalper. Must pass in backtesting lower DD work with minimum $50 if you have ready made scalper than send file for Demo test and than we Final the deal. Thanks
I would like to create an indicator for my strategy on trading view , my strategy involves a liquidity sweep , wick or candle body closure , this needs to happen inside a higher time frame pd array such as a fair value gap that’s atleast 5m + and there needs to be an inversion fair value gap for my entry , I want the fair value gaps on all time frames so I can see them all on the 1 minute chart but i want the fair
can you help me with making a simple tradingview/script that draws boxes labeling consolidation areas according to my specifications? IF anyone can help with this kindly do well to bid to this so we can discuss more about the project thanka

Informazioni sul progetto

Budget
30+ USD
Scadenze
a 1 giorno(i)