[Qualsiasi domanda da principiante, per non ingombrare il forum. Professionisti, non passate. Non posso andare da nessuna parte senza di te. - pagina 284

 
 
waitra >> :

int NumeroOfPos_HISTORIA

Ho provato, conta solo il numero di posizioni correnti aperte, non conta la storia, restituisce un valore zero quando si chiude un ordine, forse bisogna cambiare qualcos'altro?

Qui l'ho fatto. Ho preso un'altra funzione di I.Kim e l'ho cambiata un po'.

Funziona come un orologio:

La funzione START può essere usata per il controllo.

Comment ("ордера на истории= ",NumberOfPos_HISTORY_2(NULL,-1,Magic));

Ed ecco la funzione stessa:

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru            |
//+----------------------------------------------------------------------------+
//|  Версия   : 19.02.2008                                                  |
//|  Описание : Возвращает кол-во ордеровиз из  истории счета  |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                           |
//|    sy - наименование инструмента   (""   - любой символ, |
//|                                     NULL - текущий символ)        |
//|    op - операция                   (-1   - любая позиция)       |
//|    mn - MagicNumber                (-1   - любой магик)             |
//+----------------------------------------------------------------------------+
int NumberOfPos_HISTORY_2 (string sy="", int op=-1, int mn=-1) {
     int      i, k=OrdersHistoryTotal(), kp=0;
  if ( sy=="0") sy=Symbol();
  for ( i=0; i< k; i++) {
    if (OrderSelect( i, SELECT_BY_POS, MODE_HISTORY)) {
      if (OrderSymbol()== sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if ( op<0 || OrderType()== op) {
            if ( mn<0 || OrderMagicNumber()== mn) {               
                if (OrderProfit()<0 || OrderProfit()>=0) kp++;           
            }  } } } }  }  return( kp);}


 

Ciao a tutti!!!

//+------------------------------------------------------------------+
//|                                                   SimpleMA22.mq4 |
//|                      Copyright © 2009, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

//---- input parameters
extern int       MAFP=21;
extern int       MASP=55;
extern double    Lots=0.1;
extern int       StopLoss=60;
extern int       TakeProfit=30;
extern int       MagicNumber=123456;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
  
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
   
bool CheckOrders(int Type)
{
 bool Result= True;
 for(int i=0; i<OrdersTotal(); i++)
  if(OrderSelect( i, SELECT_BY_POS))
   if(OrderMagicNumber()== MagicNumber && OrderSymbol() == Symbol())
      if(OrderType()== Type)
        {
         if( Type==OP_BUY)
           if(!OrderClose(OrderTicket(),OrderLots(),Bid,0))
             Result= False;
         if( Type==OP_SELL)
           if(!OrderClose(OrderTicket(),OrderLots(),Ask,0))
             Result= False;
         } 
        else Result= False;
 return( Result); 
}
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
    // Узнаем уровень стопов и спрэд
    int Spread = MarketInfo(Symbol(), MODE_SPREAD);
    int StopLevel = MarketInfo(Symbol(), MODE_STOPLEVEL);

    // Рассчитываем значения средних на 0-ом и 1-ом барах
    double MAF_0 = iMA(NULL, 0, MAFP, 0, 1, 1, 0);
    double MAF_1 = iMA(NULL, 0, MAFP, 0, 1, 1, 1);
    double MAS_0 = iMA(NULL, 0, MASP, 0, 1, 1, 0);
    double MAS_1 = iMA(NULL, 0, MASP, 0, 1, 1, 1);
    
    // открытие позиции Buy покупка
    if( MAF_1 < MAS_1 && MAF_0 > MAS_0)
     if( CheckOrders(OP_SELL))
      {
       if( StopLoss <= StopLevel+ Spread)
         double SL = 0;
        else
         SL = Ask - StopLoss*Point;
       if( TakeProfit <= StopLevel- Spread)
         double TP = 0;
        else
         TP = Ask + TakeProfit*Point;
       if(!OrderSend(Symbol(), OP_BUY, Lots, Ask, 5, SL, TP, NULL, MagicNumber))
         Print("Не открыт ордер Buy. Ошибка №", GetLastError()); 
       }
    
    // Открытие позиции Sell продажа  
    if( MAF_1 > MAS_1 && MAF_0 < MAS_0)
     if( CheckOrders(OP_BUY))
      {
       if( StopLoss <= StopLevel+ Spread)
         SL = 0;
        else
         SL = Bid + StopLoss*Point;
       if( TakeProfit <= StopLevel- Spread)
         TP = 0;
        else
         TP = Bid - TakeProfit*Point;
       if(!OrderSend(Symbol(), OP_SELL, Lots, Bid, 5, SL, TP, NULL, MagicNumber))
         Print("Не открыт ордер Sell. Ошибка №", GetLastError()); 
       }
//----
   return(0);
  }//+------------------------------------------------------------------+


Cervelli al vapore, al vapore e spenti.....

Probabilmente è più facile capire come far scavare una trincea agli ubriachi o organizzare la raccolta dei rifiuti da parte dei barboni che ..........

In questo thread, da qualche parte all'inizio, è stato sollevato un problema simile al mio. Leggere, leggere.... Ancora non capisco, e la conversazione riguardava le bandiere...

L'idea è semplice. SimpleMA, ma è un po' modificato, ma non importa.

Chi fi dovrebbe essere aggiunto se un consigliere (per comprare) comprerebbe, un ordine sarebbe innescato da TP e l'ordine successivo sarebbe messo a condizione di vendere, cioè attraversando MAs per vendere?

Indipendentemente dal fatto che ci sia un'ulteriore condizione o meno.

 

Forse la funzione https://www.mql5.com/ru/forum/107476/page21 può aiutare.

Funzione isCloseLastPosByTake().
Questa funzione restituisce una bandiera per chiudere l'ultima posizione di Take.

Flag up - True - TakeProfit è stato attivato.

Flag abbassato - Falso - la posizione è stata chiusa per un altro motivo.


La funzione stessa dovrebbe essere messa alla fine del codice. Aggiungere alla condizione di vendita:

if( isCloseLastPosByTake( NULL, OP_BUY, MagicNumber) ==true) {//продаем



 
xmurik писал(а) >>
Sulla coppia EUR/USD.
//+------------------------------------------------------------------+
//|                                                       скрипт.mq4 |
//|                      Copyright © 2009, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
   int kolvo_barov = 1000;
   double start_price = iOpen(Symbol(),0, kolvo_barov);
   int handle;
   handle=FileOpen("my_data.csv", FILE_WRITE|FILE_CSV, '\t');
   if( handle>0) {
      while( kolvo_barov>1) {
         if (iHigh(Symbol(),0, kolvo_barov)> start_price + 0.01) {
            FileWrite( handle,"+100");
            start_price = start_price + 0.01;
         }      
         if (iHigh(Symbol(),0, kolvo_barov)< start_price + 0.01) {
            FileWrite( handle,"-100");
            start_price = start_price - 0.01;
         }      kolvo_barov--;
      }
      FileClose( handle);
   }
   return(0);
}
//+------------------------------------------------------------------+
Guarda qui. Solo che non l'ho controllato. Potrebbero esserci degli errori.
 

Brava gente. Non capisco (vedi foto) perché Momentum non è Momentum :).


Momentum

Può spiegare perché è sopra lo zero?
 
rid писал(а) >>

Ecco cosa ho fatto. Ho preso un'altra funzione da I. Kim e l'ho cambiata un po'.

Funziona come un orologio:

La funzione START può essere inserita per il controllo.


Ed ecco la funzione stessa:

Sì, funziona! Grazie mille ! Grazie! >> Buona fortuna a voi!

 
warlock писал(а) >>

Aiuto!!! l'esperto dovrebbe aprire i trade all'apertura di una nuova candela, ma oltre ad aprire all'inizio della candela, ne apre di "sinistri" in modo caotico...

Inoltre, dopo aver assegnato High e Low, ha smesso di comprare... ma solo di vendere...

Ed è stato difficile controllare attentamente OrderSend(). Uno fallisce per errore, l'altro fallisce.

if ( AllowBUY) 
   tick=OrderSend(Symbol(),OP_SELLSTOP, Lot, price1,3,( price1- SL*Point)* loss,( price1- TP*Point)* profit,"scriptSELLstop",CLR_NONE, expiration);
if ( AllowSELL) 
   tick=OrderSend(Symbol(),OP_SELLSTOP, Lot, price2,3,( price2+ SL*Point)* loss,( price2- TP*Point)* profit,"scriptSELLstop",CLR_NONE, expiration);
 
warlock >> :

Aiuto!!! l'esperto dovrebbe aprire i trade all'apertura di una nuova candela, ma oltre ad aprire all'inizio della candela, apre anche quelli "a sinistra" in modo caotico...

Inoltre, dopo aver assegnato High e Low, ha smesso di comprare... solo di vendere...

Grazie... seduto per un'ora... Non riuscivo a capire cosa stesse succedendo... A volte hai bisogno di qualcuno che ti apra gli occhi sugli errori...

 
Salve gente, qualcuno può aiutarmi a scrivere un consigliere per l'indicatore AC?
Motivazione: