Download MetaTrader 5

Arráy help

To add comments, please log in or register
Write articles, help other developers and make money
matheustn12
69
matheustn12 2016.11.15 15:26 

My array dont work for lots

 

help me please 

//+------------------------------------------------------------------+

//                        DO NOT DELETE THIS HEADER

//             DELETING THIS HEADER IS COPYRIGHT INFRIGMENT

//

//                   Copyright ©2011, ForexEAdvisor.com

//                 ForexEAdvisor Strategy Builder version 0.2

//                        http://www.ForexEAdvisor.com

//

// THIS EA CODE HAS BEEN GENERATED USING FOREXEADVISOR STRATEGY BUILDER 0.2

// on: 11/7/2016 8:23:42 PM

// Disclaimer: This EA is provided to you "AS-IS", and ForexEAdvisor disclaims any warranty

// or liability obligations to you of any kind.

// UNDER NO CIRCUMSTANCES WILL FOREXEADVISOR BE LIABLE TO YOU, OR ANY OTHER PERSON OR ENTITY,

// FOR ANY LOSS OF USE, REVENUE OR PROFIT, LOST OR DAMAGED DATA, OR OTHER COMMERCIAL OR

// ECONOMIC LOSS OR FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, STATUTORY, PUNITIVE,

// EXEMPLARY OR CONSEQUENTIAL DAMAGES WHATSOEVER RELATED TO YOUR USE OF THIS EA OR

// FOREXEADVISOR STRATEGY BUILDER    

// Because software is inherently complex and may not be completely free of errors, you are

// advised to verify this EA. Before using this EA, please read the ForexEAdvisor Strategy Builder

// license for a complete understanding of ForexEAdvisor' disclaimers.  

// USE THIS EA AT YOUR OWN RISK.

//  

// Before adding this expert advisor to a chart, make sure there are NO

// open positions.

//                      DO NOT DELETE THIS HEADER

//             DELETING THIS HEADER IS COPYRIGHT INFRIGMENT

//+------------------------------------------------------------------+



extern int MagicNumber=10001;

extern double Lots =0.1;

extern double StopLoss=50;

extern double TakeProfit=50;

extern int TrailingStop=50;

extern int Slippage=3;

//+------------------------------------------------------------------+

//    expert start function

//+------------------------------------------------------------------+


double lot[1]={1};




int lot1[];







int start()

{

  double MyPoint=Point;

  if(Digits==3 || Digits==5) MyPoint=Point*10;

  

  double TheStopLoss=0;

  double TheTakeProfit=0;

  if( TotalOrdersCount()==0 )

  {

     int result=0;

     if((Bid>Open[0])) // Here is your open buy rule

     {

    

    

     {

lot[0]=5;

lot[1]=2;

lot[2]=3;

lot[3]=4;


    

        result=OrderSend(Symbol(),OP_BUY,lot[0],Ask,Slippage,0,0,"EA Generator www.ForexEAdvisor.com",MagicNumber,0,Blue);

        result=OrderSend(Symbol(),OP_BUY,lot[1],Ask,Slippage,0,0,"EA Generator www.ForexEAdvisor.com",MagicNumber,0,Blue);

        return(result);

        

        }

        if(result>0)

        {

         TheStopLoss=0;

         TheTakeProfit=0;

         if(TakeProfit>0) TheTakeProfit=Ask+TakeProfit*MyPoint;

         if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;

         OrderSelect(result,SELECT_BY_TICKET);

         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);

        }

        return(0);

     }

     if((Bid<Open[0])) // Here is your open Sell rule

     {

    

{

lot[0]=5;

lot[1]=2;

lot[2]=3;

lot[3]=4;


    

        result=OrderSend(Symbol(),OP_SELL,lot[0],Bid,Slippage,0,0,"EA Generator www.ForexEAdvisor.com",MagicNumber,0,Red);

        result=OrderSend(Symbol(),OP_SELL,lot[1],Bid,Slippage,0,0,"EA Generator www.ForexEAdvisor.com",MagicNumber,0,Red);

        return(result);

        }

        if(result>0)

        {

         TheStopLoss=0;

         TheTakeProfit=0;

         if(TakeProfit>0) TheTakeProfit=Bid-TakeProfit*MyPoint;

         if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint;

         OrderSelect(result,SELECT_BY_TICKET);

         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);

        }

        return(0);

     }

  }

  

  for(int cnt=0;cnt<OrdersTotal();cnt++)

     {

      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

      if(OrderType()<=OP_SELL &&  

         OrderSymbol()==Symbol() &&

         OrderMagicNumber()==MagicNumber

         )  

        {

         if(OrderType()==OP_BUY)  

           {

            if(TrailingStop>0)  

              {                

               if(Bid-OrderOpenPrice()>MyPoint*TrailingStop)

                 {

                  if(OrderStopLoss()<Bid-MyPoint*TrailingStop)

                    {

                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*MyPoint,OrderTakeProfit(),0,Green);

                     return(0);

                    }

                 }

              }

           }

         else

           {

            if(TrailingStop>0)  

              {                

               if((OrderOpenPrice()-Ask)>(MyPoint*TrailingStop))

                 {

                  if((OrderStopLoss()>(Ask+MyPoint*TrailingStop)) || (OrderStopLoss()==0))

                    {

                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+MyPoint*TrailingStop,OrderTakeProfit(),0,Red);

                     return(0);

                    }

                 }

              }

           }

        }

     }

   return(0);

}


int TotalOrdersCount()

{

  int result=0;

  for(int i=0;i<OrdersTotal();i++)

  {

     OrderSelect(i,SELECT_BY_POS ,MODE_TRADES);

     if (OrderMagicNumber()==MagicNumber) result++;


   }

  return (result);

}
Carl Schreiber
6592
Carl Schreiber 2016.11.15 15:50  
Can you specify "does not work"? What do you expect, what do you get - have you tried the debugger, checked _LastError, ....?
whroeder1
14518
whroeder1 2016.11.15 15:59  
  1. Don't paste
code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. matheustn12: My array dont work for lots
    "Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. There are no mind readers here.
  3. //                   Copyright ©2011, ForexEAdvisor.com
    • We hate EA builder
    • You couldn't be bothered to learn mql4, therefor there is no common language for us to communicate.
    • There are only two choices: learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem, but we are not going to debug your hundreds lines of code.
    • EA builder makes bad code counting up while closing multiple orders.
    • EA builder makes bad code Bars is unreliable (max bars on chart) volume is unreliable (miss ticks) Always use time
    • EA builder makes bad code Not adjusting for 4/5 digit brokers
    • EA builder makes bad code not adjusting for ECN brokers.
    • EA builder makes bad code not checking return codes.
    • EATree uses objects on chart to save values - not persistent storage (files or GV+Flush.) No recovery (crash/reboot.)

  4. How big did you define lot? It is big enough for the assignments?
    double lot[1]={1};
    int start(){
      :
      
         {
    lot[0]=5;
    lot[1]=2;
    lot[2]=3;
    lot[3]=4;
matheustn12
69
matheustn12 2016.11.15 16:34  
whroeder1:
  1. Please edit your post.
    For large amounts of code, attach it.

  2. "Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. There are no mind readers here.
  3. //                   Copyright ©2011, ForexEAdvisor.com

  4. How big did you define lot? It is big enough for the assignments?
    double lot[1]={1};
    int start(){
      :
      
         {
    lot[0]=5;
    lot[1]=2;
    lot[2]=3;
    lot[3]=4;

 

 

Sorry,I want lots fixed ,I just made one here, Lots goes from 1 to 9 and then to not return to the initial lots.

 

SorrY EA Generation  

 

extern int MagicNumber=10001;
extern double Lots =0.1;
extern double StopLoss=50;
extern double TakeProfit=50;
extern int TrailingStop=50;
extern int Slippage=3;
//+------------------------------------------------------------------+
//    expert start function
//+------------------------------------------------------------------+

int numero[]={1,3,3,4,5,6,7,8,9};
int n,result;








int start()
{
  double MyPoint=Point;
  if(Digits==3 || Digits==5) MyPoint=Point*10;
  
  double TheStopLoss=0;
  double TheTakeProfit=0;
  if( TotalOrdersCount()==0 )
  {
     int result=0;
     if((Bid>Open[0])) // Here is your open buy rule
     {
    
    
     {
for(n=0;n<1000;n++){
     result=numero[n]+OrderLots();
    
    result=OrderSend(Symbol(),OP_BUY,numero[n],Ask,Slippage,0,0,"EA Generator www.ForexEAdvisor.com",MagicNumber,0,Blue);
      
     }
        
        
        if(result>0)
        {
         TheStopLoss=0;
         TheTakeProfit=0;
         if(TakeProfit>0) TheTakeProfit=Ask+TakeProfit*MyPoint;
         if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
         OrderSelect(result,SELECT_BY_TICKET);
         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
        }
        return(0);
        
        
     }
     if((Bid<Open[0])) // Here is your open Sell rule
     {
    
{

     for(n=0;n<1000;n++){
     result=numero[n]+OrderLots();
    
        result=OrderSend(Symbol(),OP_SELL,numero[n],Bid,Slippage,0,0,"EA Generator www.ForexEAdvisor.com",MagicNumber,0,Red);
        
        }
        
        if(result>0)
        {
         TheStopLoss=0;
         TheTakeProfit=0;
         if(TakeProfit>0) TheTakeProfit=Bid-TakeProfit*MyPoint;
         if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint;
         OrderSelect(result,SELECT_BY_TICKET);
         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
        }
        return(0);
        }
     }
  }
  
  for(int cnt=0;cnt<OrdersTotal();cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()<=OP_SELL &&  
         OrderSymbol()==Symbol() &&
         OrderMagicNumber()==MagicNumber
         )  
        {
         if(OrderType()==OP_BUY)  
           {
            if(TrailingStop>0)  
              {                
               if(Bid-OrderOpenPrice()>MyPoint*TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-MyPoint*TrailingStop)
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*MyPoint,OrderTakeProfit(),0,Green);
                     return(0);
                    }
                 }
              }
           }
         else
           {
            if(TrailingStop>0)  
              {                
               if((OrderOpenPrice()-Ask)>(MyPoint*TrailingStop))
                 {
                  if((OrderStopLoss()>(Ask+MyPoint*TrailingStop)) || (OrderStopLoss()==0))
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+MyPoint*TrailingStop,OrderTakeProfit(),0,Red);
                     return(0);
                    }
                 }
              }
           }
        }
     }
   return(0);
}

}

int TotalOrdersCount()
{
  int result=0;
  for(int i=0;i<OrdersTotal();i++)
  {
     OrderSelect(i,SELECT_BY_POS ,MODE_TRADES);
     if (OrderMagicNumber()==MagicNumber) result++;

   }
  return (result);
}

matheustn12
69
matheustn12 2016.11.15 16:49  

So, the order of the lot is 1,2,3,4,5,6,7,8,9. I want it when it gets back pro lot initial

 

 

At each loss continues the fixed lots, and when it wins back to initial lots 

 

New post=https://www.mql5.com/en/forum/161112

 

You can delete this Post

Array HELP Update
Array HELP Update
  • www.mql5.com
So, the order of the lot is 1,2,3,4,5,6,7,8,9...
Marco vd Heijden
Moderator
4704
Marco vd Heijden 2016.11.15 17:13  
Or you can continue here.
matheustn12
69
matheustn12 2016.11.15 17:23  
Marco vd Heijden:
Or you can continue here.
:( okay
matheustn12
69
matheustn12 2016.11.15 18:14  

What's wrong with this? 

Only open purchase order.

 

extern int MagicNumber=10001;
extern double Lots =0.1;
extern double StopLoss=50;
extern double TakeProfit=50;
extern int TrailingStop=50;
extern int Slippage=3;
//+------------------------------------------------------------------+
//    expert start function
//+------------------------------------------------------------------+

double lotsfactor=1,ilots;
double initiallotsfactor=1;




int numero[]={2,3,3,4,5,6,7,8,9};
int n,result;



int start()
{
  double MyPoint=Point;
  if(Digits==3 || Digits==5) MyPoint=Point*10;
  
  double TheStopLoss=0;
  double TheTakeProfit=0;
  if( TotalOrdersCount()==0 )
  {
     int result=0;
     if((Bid>Open[0])) // Here is your open buy rule
     {
    
    
     {
     for(n=0;n<numero[n];n++){
     result=numero[n]+OrderLots();
    
    result=OrderSend(Symbol(),OP_BUY,numero[n],Ask,Slippage,0,0,MagicNumber,0,Blue);
      
    
        
        
        if(result>0)
        {
         TheStopLoss=0;
         TheTakeProfit=0;
         if(TakeProfit>0) TheTakeProfit=Ask+TakeProfit*MyPoint;
         if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
         OrderSelect(result,SELECT_BY_TICKET);
         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
        }
        
        }
        return(0);
     }
     if((Bid<Open[0])) // Here is your open Sell rule
     {
    
{

     for(n=0;n<numero[n];n++){
     result=numero[n]+OrderLots();
    
        result=OrderSend(Symbol(),OP_SELL,numero[n],Bid,Slippage,0,0,MagicNumber,0,Red);
        
      
        
        if(result>0)
        {
         TheStopLoss=0;
         TheTakeProfit=0;
         if(TakeProfit>0) TheTakeProfit=Bid-TakeProfit*MyPoint;
         if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint;
         OrderSelect(result,SELECT_BY_TICKET);
         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
        }
         return(0);
        }
      
        }
     }
  }
  
  for(int cnt=0;cnt<OrdersTotal();cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()<=OP_SELL &&  
         OrderSymbol()==Symbol() &&
         OrderMagicNumber()==MagicNumber
         )  
        {
         if(OrderType()==OP_BUY)  
           {
            if(TrailingStop>0)  
              {                
               if(Bid-OrderOpenPrice()>MyPoint*TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-MyPoint*TrailingStop)
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*MyPoint,OrderTakeProfit(),0,Green);
                     return(0);
                    }
                 }
              }
           }
         else
           {
            if(TrailingStop>0)  
              {                
               if((OrderOpenPrice()-Ask)>(MyPoint*TrailingStop))
                 {
                  if((OrderStopLoss()>(Ask+MyPoint*TrailingStop)) || (OrderStopLoss()==0))
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+MyPoint*TrailingStop,OrderTakeProfit(),0,Red);
                     return(0);
                    }
                 }
              }
           }
        }
     }
   return(0);
}

}

int TotalOrdersCount()
{
  int result=0;
  for(int i=0;i<OrdersTotal();i++)
  {
     OrderSelect(i,SELECT_BY_POS ,MODE_TRADES);
     if (OrderMagicNumber()==MagicNumber) result++;

   }
  return (result);
}


int martingalefactor()
{
   int histotal=OrdersHistoryTotal();
   if (histotal>0)
   {
      for(int cnt=histotal-1;cnt>=0;cnt++)
      {
         if(OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY))
         {
            if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
            {
               if(OrderProfit()<0)
               {
                  
                  
                  
                  
               }
               else
               {
                  lotsfactor=initiallotsfactor;
                  if(lotsfactor<=0)
                  {
                     lotsfactor=1;
                  }
                  return(lotsfactor);
               }
            }
         }
      }
   }
   return(lotsfactor);
}


 

To add comments, please log in or register