Lavagem cerebral: desenvolvimento do sistema - página 6

 

O mesmo EA , use o sinal BrainTrend1Sig

//+------------------------------------------------------------------+
//|                                            EA_BrainTrend1Sig.mq4 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

extern bool open_buy = true;
extern bool open_sell = true;

 extern int  MagicNumber   = 451;
 extern  double StopLoss   = 135;
 extern  double TakeProfit = 400;
 extern  double lots       = 0.1; 
 string Text ; 
extern int Tral_Stop      = 180;                       

 // double signal_up = iCustom(NULL,0,"NK//Plus//BrainTrend//BrainTrend1Sig", EnableAlerts,SignalID, Input_Price_Customs,0,1 );

extern int       EnableAlerts=0;
extern int       SignalID=0;
extern int Input_Price_Customs = 0;  //Âûáîð öåí, ïî êîòîðûì ïðîèçâîäèòñÿ ðàñ÷¸ò èíäèêàòîðà 

datetime time0; 
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   if( time0 == Time[0] ) return;
       time0= Time[0];
   
   if( count_tip(OP_BUY) > 0 ) trailing_stop();
   if( count_tip(OP_SELL) > 0 ) trailing_stop();
   
   
  //  double signal_up = iCustom(NULL,0,"NK//Plus//BrainTrend//BrainTrend1Sig", EnableAlerts,SignalID, Input_Price_Customs,1,1 );
    double signal_up = iCustom(NULL,0,"BrainTrend1Sig", EnableAlerts,SignalID, Input_Price_Customs,1,1 );
    double sl_buy = MathMin( Bid - StopLoss*Point, signal_up );
      
      
       if( signal_up != 0.0 && open_buy && count_tip(OP_BUY ) == 0 )
         {
          int ticket_buy = OrderSend(_Symbol, OP_BUY, lots, Ask, 3, sl_buy, Ask +TakeProfit*Point, "RsiEma", MagicNumber);
         }
  
    // double signal_down =  iCustom(NULL,0,"NK//Pluas//BrainTrend//BrainTrend1Sig", EnableAlerts,SignalID, Input_Price_Customs,0,1 );
    double signal_down =  iCustom(NULL,0,"BrainTrend1Sig", EnableAlerts,SignalID, Input_Price_Customs,0,1 );
    double sl_sell = MathMax( Ask + StopLoss*Point, signal_down );
      
      
       if( signal_down != 0.0 && open_sell && count_tip(OP_SELL) == 0 )
         {
          int ticket_sell  = OrderSend(_Symbol, OP_SELL, lots, Bid, 3, sl_sell, Bid - TakeProfit*Point, "RsiEma", MagicNumber);
         }
   
   
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
int count_tip( int tip = -1)
{
   int cpte_order = 0; 
  for (int i = (OrdersTotal()-1); i >=0; i--)
  {
    if( OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == false) continue;    
    if( OrderMagicNumber()==MagicNumber && OrderType()== tip) cpte_order++;
   }
  return(cpte_order);
}

//+------------------------------------------------------------------+
//   https://book.mql4.com/trading/ordermodify
//------------------------------------------------------------------------------- 1 --
void trailing_stop ( )                                  // Special function 'start'
  {
   string Symb=Symbol();                        // Symbol
//------------------------------------------------------------------------------- 2 --
   for(int i=1; i<=OrdersTotal(); i++)          // Cycle searching in orders
     {
      if (OrderSelect(i-1,SELECT_BY_POS)==true) // If the next is available
        {                                       // Analysis of orders:
         int Tip=OrderType();                   // Order type
         if(OrderSymbol()!=Symb||Tip>1)continue;// The order is not "ours"
         double SL=OrderStopLoss();             // SL of the selected order
         //---------------------------------------------------------------------- 3 --
         while(true)                            // Modification cycle
           {
            double TS=Tral_Stop;                // Initial value
            int Min_Dist= (int) MarketInfo(Symb,MODE_STOPLEVEL);//Min. distance
            if (TS < Min_Dist)                  // If less than allowed
               TS=Min_Dist;                     // New value of TS
            //------------------------------------------------------------------- 4 --
            bool Modify=false;                  // Not to be modified
            switch(Tip)                         // By order type
              {
               case 0 :                         // Order Buy
                  if (NormalizeDouble(SL,Digits)< // If it is lower than we want
                     NormalizeDouble(Bid-TS*Point,Digits))
                    {
                     SL=Bid-TS*Point;           // then modify it
                      Text="Buy ";        // Text for Buy 
                     Modify=true;               // To be modified
                    }
                  break;                        // Exit 'switch'
               case 1 :                         // Order Sell
                  if (NormalizeDouble(SL,Digits)> // If it is higher than we want
                     NormalizeDouble(Ask+TS*Point,Digits)
                     || NormalizeDouble(SL,Digits)==0)//or equal to zero
                    {
                     SL=Ask+TS*Point;           // then modify it
                     Text="Sell ";              // Text for Sell 
                     Modify=true;               // To be modified
                    }
              }                                 // End of 'switch'
            if (Modify==false)                  // If it is not modified
               break;                           // Exit 'while'
            //------------------------------------------------------------------- 5 --
            double TP    =OrderTakeProfit();    // TP of the selected order
            double Price =OrderOpenPrice();     // Price of the selected order
            int    Ticket=OrderTicket();        // Ticket of the selected order
 
            Alert ("Modification ",Text,Ticket,". Awaiting response..");
            bool Ans=OrderModify(Ticket,Price,SL,TP,0);//Modify it!
            //------------------------------------------------------------------- 6 --
            if (Ans==true)                      // Got it! :)
              {
               Alert ("Order ",Text,Ticket," is modified:)");
               break;                           // From modification cycle.
              }
            //------------------------------------------------------------------- 7 --
            int Error=GetLastError();           // Failed :(
            switch(Error)                       // Overcomable errors
              {
               case 130:Alert("Wrong stops. Retrying.");
                  RefreshRates();               // Update data
                  continue;                     // At the next iteration
               case 136:Alert("No prices. Waiting for a new tick..");
                  while(RefreshRates()==false)  // To the new tick
                     Sleep(1);                  // Cycle delay
                  continue;                     // At the next iteration
               case 146:Alert("Trading subsystem is busy. Retrying ");
                  Sleep(500);                   // Simple solution
                  RefreshRates();               // Update data
                  continue;                     // At the next iteration
                  // Critical errors
               case 2 : Alert("Common error.");
                  break;                        // Exit 'switch'
               case 5 : Alert("Old version of the client terminal.");
                  break;                        // Exit 'switch'
               case 64: Alert("Account is blocked.");
                  break;                        // Exit 'switch'
               case 133:Alert("Trading is prohibited");
                  break;                        // Exit 'switch'
               default: Alert("Occurred error ",Error);//Other errors
              }
            break;                              // From modification cycle
           }                                    // End of modification cycle
         //---------------------------------------------------------------------- 8 --
        }                                       // End of order analysis
     }                                          // End of order search
//------------------------------------------------------------------------------- 9 --
   return;                                      // Exit start()
  }
//----------------------------------------------------------------
 

bt ;


 

Você vê o gráfico de lucro?

um ganha um perde , então pode trabalhar com martingale, EA_BrainTrend1Sig

//+------------------------------------------------------------------+
//|                                            EA_BrainTrend1Sig.mq4 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

extern bool open_buy = 0;
extern bool open_sell = true;

 extern int  MagicNumber   = 451;
 extern  double StopLoss   = 135;
 extern  double TakeProfit = 400;
 extern  double lots       = 0.1; 
 string Text ; 
extern int Tral_Stop      = 180; 

extern bool use_mart      = true; 
 // double signal_up = iCustom(NULL,0,"NK//Plus//BrainTrend//BrainTrend1Sig", EnableAlerts,SignalID, Input_Price_Customs,0,1 );

extern int       EnableAlerts=0;
extern int       SignalID=0;
extern int Input_Price_Customs = 0;  //Âûáîð öåí, ïî êîòîðûì ïðîèçâîäèòñÿ ðàñ÷¸ò èíäèêàòîðà 

datetime time0;  double llots =0.0;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   if( time0 == Time[0] ) return;
       time0= Time[0];
   
   if( count_tip(OP_BUY) > 0 ) trailing_stop();
   if( count_tip(OP_SELL) > 0 ) trailing_stop();
   
   
   llots = lots; 
  if(use_mart ) llots =  martingale_lots();
             
       Print("   llots   ",(string) llots);

   
    double signal_up = iCustom(NULL,0,"NK//Plus//BrainTrend//BrainTrend1Sig", EnableAlerts,SignalID, Input_Price_Customs,1,1 );
   // double signal_up = iCustom(NULL,0,"BrainTrend1Sig", EnableAlerts,SignalID, Input_Price_Customs,1,1 );
    double sl_buy = MathMin( Bid - StopLoss*Point, signal_up );
      
      
       if( signal_up != 0.0 && open_buy && count_tip(OP_BUY ) == 0 )
         {
          int ticket_buy = OrderSend(_Symbol, OP_BUY, llots, Ask, 3, sl_buy, Ask +TakeProfit*Point, "RsiEma", MagicNumber);
         }
  
     double signal_down =  iCustom(NULL,0,"NK//Plus//BrainTrend//BrainTrend1Sig", EnableAlerts,SignalID, Input_Price_Customs,0,1 );
   // double signal_down =  iCustom(NULL,0,"BrainTrend1Sig", EnableAlerts,SignalID, Input_Price_Customs,0,1 );
    double sl_sell = MathMax( Ask + StopLoss*Point, signal_down );
      
      
       if( signal_down != 0.0 && open_sell && count_tip(OP_SELL) == 0 )
         {
          int ticket_sell  = OrderSend(_Symbol, OP_SELL, llots, Bid, 3, sl_sell, Bid - TakeProfit*Point, "RsiEma", MagicNumber);
         }
   
   
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
int count_tip( int tip = -1)
{
   int cpte_order = 0; 
  for (int i = (OrdersTotal()-1); i >=0; i--)
  {
    if( OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == false) continue;    
    if( OrderMagicNumber()==MagicNumber && OrderType()== tip) cpte_order++;
   }
  return(cpte_order);
}

//+------------------------------------------------------------------+
//   https://book.mql4.com/trading/ordermodify
//------------------------------------------------------------------------------- 1 --
void trailing_stop ( )                                  // Special function 'start'
  {
   string Symb=Symbol();                        // Symbol
//------------------------------------------------------------------------------- 2 --
   for(int i=1; i<=OrdersTotal(); i++)          // Cycle searching in orders
     {
      if (OrderSelect(i-1,SELECT_BY_POS)==true) // If the next is available
        {                                       // Analysis of orders:
         int Tip=OrderType();                   // Order type
         if(OrderSymbol()!=Symb||Tip>1)continue;// The order is not "ours"
         double SL=OrderStopLoss();             // SL of the selected order
         //---------------------------------------------------------------------- 3 --
         while(true)                            // Modification cycle
           {
            double TS=Tral_Stop;                // Initial value
            int Min_Dist= (int) MarketInfo(Symb,MODE_STOPLEVEL);//Min. distance
            if (TS < Min_Dist)                  // If less than allowed
               TS=Min_Dist;                     // New value of TS
            //------------------------------------------------------------------- 4 --
            bool Modify=false;                  // Not to be modified
            switch(Tip)                         // By order type
              {
               case 0 :                         // Order Buy
                  if (NormalizeDouble(SL,Digits)< // If it is lower than we want
                     NormalizeDouble(Bid-TS*Point,Digits))
                    {
                     SL=Bid-TS*Point;           // then modify it
                      Text="Buy ";        // Text for Buy 
                     Modify=true;               // To be modified
                    }
                  break;                        // Exit 'switch'
               case 1 :                         // Order Sell
                  if (NormalizeDouble(SL,Digits)> // If it is higher than we want
                     NormalizeDouble(Ask+TS*Point,Digits)
                     || NormalizeDouble(SL,Digits)==0)//or equal to zero
                    {
                     SL=Ask+TS*Point;           // then modify it
                     Text="Sell ";              // Text for Sell 
                     Modify=true;               // To be modified
                    }
              }                                 // End of 'switch'
            if (Modify==false)                  // If it is not modified
               break;                           // Exit 'while'
            //------------------------------------------------------------------- 5 --
            double TP    =OrderTakeProfit();    // TP of the selected order
            double Price =OrderOpenPrice();     // Price of the selected order
            int    Ticket=OrderTicket();        // Ticket of the selected order
 
            Alert ("Modification ",Text,Ticket,". Awaiting response..");
            bool Ans=OrderModify(Ticket,Price,SL,TP,0);//Modify it!
            //------------------------------------------------------------------- 6 --
            if (Ans==true)                      // Got it! :)
              {
               Alert ("Order ",Text,Ticket," is modified:)");
               break;                           // From modification cycle.
              }
            //------------------------------------------------------------------- 7 --
            int Error=GetLastError();           // Failed :(
            switch(Error)                       // Overcomable errors
              {
               case 130:Alert("Wrong stops. Retrying.");
                  RefreshRates();               // Update data
                  continue;                     // At the next iteration
               case 136:Alert("No prices. Waiting for a new tick..");
                  while(RefreshRates()==false)  // To the new tick
                     Sleep(1);                  // Cycle delay
                  continue;                     // At the next iteration
               case 146:Alert("Trading subsystem is busy. Retrying ");
                  Sleep(500);                   // Simple solution
                  RefreshRates();               // Update data
                  continue;                     // At the next iteration
                  // Critical errors
               case 2 : Alert("Common error.");
                  break;                        // Exit 'switch'
               case 5 : Alert("Old version of the client terminal.");
                  break;                        // Exit 'switch'
               case 64: Alert("Account is blocked.");
                  break;                        // Exit 'switch'
               case 133:Alert("Trading is prohibited");
                  break;                        // Exit 'switch'
               default: Alert("Occurred error ",Error);//Other errors
              }
            break;                              // From modification cycle
           }                                    // End of modification cycle
         //---------------------------------------------------------------------- 8 --
        }                                       // End of order analysis
     }                                          // End of order search
//------------------------------------------------------------------------------- 9 --
   return;                                      // Exit start()
  }
//----------------------------------------------------------------

//+------------------------------------------------------------------+
double  martingale_lots()
{
   int cpte_loss= 0; 
  if(  OrdersHistoryTotal() == 0 )   return(0.1) ;
   
  for (int i = (OrdersHistoryTotal()-10); i <=OrdersHistoryTotal()-1; i++)
  {
    if( OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) == false) continue;    
    if( OrderMagicNumber()==MagicNumber ) 
      {
      if( OrderProfit() < 0 ) cpte_loss++;
      else                    cpte_loss = 1;
      }
    Print("   cpte_loss   ",(string) cpte_loss);
   }
  return(cpte_loss*lots ) ;
}




 

BT ;


 

Se dobrarmos os lotes uma vez em caso de perda

:

extern int max_cpte_loss = 2;
//+------------------------------------------------------------------+
double  martingale_lots()
{
   int cpte_loss= 0; 
  if(  OrdersHistoryTotal() == 0 )   return(0.1) ;
   
  for (int i = (OrdersHistoryTotal()-10); i <=OrdersHistoryTotal()-1; i++)
  {
    if( OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) == false) continue;    
    if( OrderMagicNumber()==MagicNumber ) 
      {
      if( OrderProfit() < 0 ) cpte_loss++;
      else                    cpte_loss = 1;
      }
    Print("   cpte_loss   ",(string) cpte_loss);
   }
   
  if( cpte_loss <=  max_cpte_loss) return(cpte_loss*lots*2 ) ;
   else                             return(lots ) ;

}


BT jan 2018 out 2018 melhor :


 
Sistema de lavagem cerebral

O início

  1. Lavagem cerebral. Ofícios: manualmente e usando EAs (MT4)
  2. Lavagem cerebral EAs -o fio(MT4)
  3. Lavagem cerebral: configuração do sistema para negociação manual e para EAs (MT4) -a rosca
  4. Lavagem cerebral: desenvolvimento do sistema (MT4) -o fio

Depois de

  1. Sistema de lavagem cerebral/sistema ASCTrend (MT5) -o fio
Razão: