MQL4 ve MQL5 ile ilgili herhangi bir acemi sorusu, algoritmalar ve kodlar hakkında yardım ve tartışma - sayfa 1371

 
MakarFX :

Danışmanın en dibine

Maalesef çoğalmıyor! (((

 
Сергей Дыбленко :

Maalesef çoğalmıyor! (((

Bu fonksiyon, lotu serbest marj ve belirtilen riske göre hesaplar!

Ne çarpımından bahsediyorsun?

 
MakarFX :

Bu fonksiyon, lotu serbest marj ve belirtilen riske göre hesaplar!

Ne çarpımından bahsediyorsun?

her kardan sonra lotları artırma hakkında!

 
Сергей Дыбленко :

her kârdan sonra lotları artırma hakkında!

Bu fonksiyon kardan sonraki lotu artıracaktır, ancak eğer kar minimum lot adımı kadar artışa izin veriyorsa

 
Сергей Дыбленко :

her kârdan sonra lotları artırma hakkında!

İşte bakiyenizin 10.000'e kadar olan bir örneği, bir lot 0,5 lot ile 10.000'den 20.000'e 0.1 açılacaktır

lot 1.0 ile 20.000'den 40.000'e kadar lot 2.0 ile 40.000'in üzerinde

 //+------------------------------------------------------------------+
//|                                               Moving Average.mq4 |
//|                   Copyright 2005-2014, MetaQuotes Software Corp. |
//|                                              http://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright    "2005-2014, MetaQuotes Software Corp."
#property link          "http://www.mql4.com"
#property description "Moving Average sample expert advisor"

#define MAGICMA   20131111
//--- Inputs
input double InpLots       = 0.1 ;
input int     MovingPeriod  = 12 ;
input int     MovingShift   = 6 ;
//+------------------------------------------------------------------+
//| Calculate open positions                                         |
//+------------------------------------------------------------------+
int CalculateCurrentOrders( string symbol)
  {
   int buys= 0 ,sells= 0 ;
//---
   for ( int i= 0 ; i< OrdersTotal (); i++)
     {
       if ( OrderSelect (i,SELECT_BY_POS,MODE_TRADES)== false )
         break ;
       if (OrderSymbol()== Symbol () && OrderMagicNumber()==MAGICMA)
        {
         if (OrderType()==OP_BUY)
            buys++;
         if (OrderType()==OP_SELL)
            sells++;
        }
     }
//--- return orders volume
   if (buys> 0 )
       return (buys);
   else
       return (-sells);
  }
//+------------------------------------------------------------------+
//| Calculate optimal lot size                                       |
//+------------------------------------------------------------------+
double LotsOptimized()
  {
   double Lots=InpLots;
   double ab=AccountBalance();
   if (ab>= 10000 && ab< 20000 )
      Lots= 0.5 ;
   if (ab>= 20000 && ab< 40000 )
      Lots= 1.0 ;
   if (ab>= 40000 )
      Lots= 2.0 ;
   return (Lots);
  }
//+------------------------------------------------------------------+
//| Check for open order conditions                                  |
//+------------------------------------------------------------------+
void CheckForOpen()
  {
   double ma;
   int     res;
//--- go trading only for first tiks of new bar
   if (Volume[ 0 ]> 1 )
       return ;
//--- get Moving Average
   ma= iMA ( NULL , 0 ,MovingPeriod,MovingShift, MODE_SMA , PRICE_CLOSE , 0 );
//--- sell conditions
   if (Open[ 1 ]>ma && Close[ 1 ]<ma)
     {
      res= OrderSend ( Symbol (),OP_SELL, LotsOptimized() ,Bid, 3 , 0 , 0 , "" ,MAGICMA, 0 ,Red);
       return ;
     }
//--- buy conditions
   if (Open[ 1 ]<ma && Close[ 1 ]>ma)
     {
      res= OrderSend ( Symbol (),OP_BUY, LotsOptimized() ,Ask, 3 , 0 , 0 , "" ,MAGICMA, 0 ,Blue);
       return ;
     }
//---
  }
//+------------------------------------------------------------------+
//| Check for close order conditions                                 |
//+------------------------------------------------------------------+
void CheckForClose()
  {
   double ma;
//--- go trading only for first tiks of new bar
   if (Volume[ 0 ]> 1 )
       return ;
//--- get Moving Average
   ma= iMA ( NULL , 0 ,MovingPeriod,MovingShift, MODE_SMA , PRICE_CLOSE , 0 );
//---
   for ( int i= 0 ; i< OrdersTotal (); i++)
     {
       if ( OrderSelect (i,SELECT_BY_POS,MODE_TRADES)== false )
         break ;
       if (OrderMagicNumber()!=MAGICMA || OrderSymbol()!= Symbol ())
         continue ;
       //--- check order type
       if (OrderType()==OP_BUY)
        {
         if (Open[ 1 ]>ma && Close[ 1 ]<ma)
           {
             if (!OrderClose(OrderTicket(),OrderLots(),Bid, 3 ,White))
               Print ( "OrderClose error " , GetLastError ());
           }
         break ;
        }
       if (OrderType()==OP_SELL)
        {
         if (Open[ 1 ]<ma && Close[ 1 ]>ma)
           {
             if (!OrderClose(OrderTicket(),OrderLots(),Ask, 3 ,White))
               Print ( "OrderClose error " , GetLastError ());
           }
         break ;
        }
     }
//---
  }
//+------------------------------------------------------------------+
//| OnTick function                                                  |
//+------------------------------------------------------------------+
void OnTick ()
  {
//--- check for history and trading
   if ( Bars < 100 || IsTradeAllowed()== false )
       return ;
//--- calculate open orders by current symbol
   if (CalculateCurrentOrders( Symbol ())== 0 )
      CheckForOpen();
   else
      CheckForClose();
//---
  }
//+------------------------------------------------------------------+
 
SanAlex :

İşte bakiyenizin 10.000'e kadar olan bir örneği, bir lot 0,5 lot ile 10.000'den 20.000'e 0.1 açılacaktır

lot 1.0 ile 20.000'den 40.000'e kadar lot 2.0 ile 40.000'in üzerinde

bu sabit bir lot artışıdır.

Kar, daha büyük veya eşitse

 MarketInfo( Symbol (), MODE_MARGINREQUIRED)*MarketInfo( Symbol (), MODE_LOTSTEP)

o zaman lotta bir artış olacak,

ancak marj kullanan başka açık emir yoksa.

 
MakarFX :

bu sabit bir lot artışıdır.

Kar, daha büyük veya eşitse

o zaman lotta bir artış olacak,

ancak marj kullanan başka açık emir yoksa.

bu yüzden hile yaptım - pozisyonlar kırmızıysa, lot artar

 //+------------------------------------------------------------------+
//| Calculate optimal lot size                                       |
//+------------------------------------------------------------------+
double OptimizedBuy( void )
  {
   double PROFIT_BUY= 0.00 ;
   for ( int i= OrdersTotal ()- 1 ; i>= 0 ; i--) // returns the number of open positions
     {
       if ( OrderSelect (i,SELECT_BY_POS) && OrderSymbol()== Symbol ())
        {
         if (OrderSymbol()== Symbol () && OrderType()==OP_BUY)
           {
            PROFIT_BUY=PROFIT_BUY+ NormalizeDouble (OrderProfit(), 2 );
           }
        }
     }
   double Lots=InpLots;
   double ab=PROFIT_BUY;
   if (ab<- 1 && ab>=-InpLots_01)
      Lots=InpLots1;
   if (ab<-InpLots_01 && ab>=-InpLots_02)
      Lots=InpLots2;
   if (ab<-InpLots_02 && ab>=-InpLots_03)
      Lots=InpLots3;
   if (ab<-InpLots_03)
      Lots=InpLots4;
//--- return trading volume
   return (Lots);
  }
//+------------------------------------------------------------------+
//| Calculate optimal lot size                                       |
//+------------------------------------------------------------------+
double OptimizedSell( void )
  {
   double PROFIT_SELL= 0.00 ;
   for ( int i= OrdersTotal ()- 1 ; i>= 0 ; i--) // returns the number of open positions
     {
       if ( OrderSelect (i,SELECT_BY_POS) && OrderSymbol()== Symbol ())
        {
         if (OrderSymbol()== Symbol () && OrderType()==OP_SELL)
           {
            PROFIT_SELL=PROFIT_SELL+ NormalizeDouble (OrderProfit(), 2 );
           }
        }
     }
   double Lots=InpLots;
   double ab=PROFIT_SELL;
   if (ab<- 1 && ab>=-InpLots_01)
      Lots=InpLots1;
   if (ab<-InpLots_01 && ab>=-InpLots_02)
      Lots=InpLots2;
   if (ab<-InpLots_02 && ab>=-InpLots_03)
      Lots=InpLots3;
   if (ab<-InpLots_03)
      Lots=InpLots4;
//--- return trading volume
   return (Lots);
  }
//+------------------------------------------------------------------+
 
Yardımlarınız için hepinize teşekkür ederim AMA ihtiyacım olanı yapmaya yetmeyen beynim!
 
Сергей Дыбленко :
Yardımlarınız için hepinize teşekkür ederim AMA ihtiyacım olanı yapmaya yetmeyen beynim!

Neye ihtiyacın olduğunu açıklarsın.

Devam eden kaç emir var, aynı anda kaç çift işlem yapıyorsunuz, işlem başına riskler nelerdir (varsa)

peki, kendimden başka bir şey)

 
SanAlex :

bu yüzden hile yaptım - pozisyonlar kırmızıysa, lot artar

Sasha, partiyi katsayı ile artırmak için hafifçe düzeltildi

 input double factor= 1.05 ;         // коофициент умножения
//+------------------------------------------------------------------+
//| Calculate optimal lot size                                       |
//+------------------------------------------------------------------+
double OptimizedSell( void )
  {
   double Lots       = 0.00 ;
   double PROFIT_BUY = 0.00 ;
   double LOT_BUY    = 0.00 ;
   double PROFIT_SELL= 0.00 ;
   double LOT_SELL   = 0.00 ;
   for ( int i= OrdersTotal ()- 1 ; i>= 0 ; i--) // returns the number of open positions
     {
       if ( OrderSelect (i,SELECT_BY_POS,MODE_HISTORY)== true )
        {
         if (OrderSymbol()== Symbol ())
           {
             if (OrderType()==OP_BUY)
              {
               PROFIT_BUY=PROFIT_BUY+ NormalizeDouble (OrderProfit(), 2 );
               LOT_BUY   =LOT_BUY+ NormalizeDouble (OrderLots(), 2 );
              }
             if (OrderType()==OP_SELL)
              {
               PROFIT_SELL=PROFIT_SELL+ NormalizeDouble (OrderProfit(), 2 );
               LOT_SELL   =LOT_SELL+ NormalizeDouble (OrderLots(), 2 );
              }
           }
        }
     }
   if (PROFIT_BUY< 0 )
      Lots=LOT_BUY*factor;
       else Lots=LOT_BUY;
   if (PROFIT_SELL< 0 )
      Lots=LOT_SELL*factor;
       else Lots=LOT_SELL;
//--- return trading volume
   return (Lots);
  }
//+------------------------------------------------------------------+ 
Neden: