Toute question de débutant, afin de ne pas encombrer le forum. Professionnels, ne passez pas à côté. Nulle part sans toi - 6. - page 937

 
silachara:

J'ai commencé à apprendre à travailler avec des fichiers. Je suis tombé sur le terme "poignée". La question s'est posée après avoir écrit le code :

Après avoir ouvert le premier fichier news.csv, le programme a donné la valeur 1 à la variable filehandle. Ensuite, le programme ouvre le deuxième fichier news150901.csv et définit la variable filehandle sur 2. Il s'avère que le programme ne dispose plus que d'une valeur de poignée provenant de l'ouverture du deuxième fichier. En d'autres termes, j'ai tué la valeur du handle pour le premier fichier ouvert. C'est-à-dire que je peux seulement accéder aux données/contenu et fermer le deuxième fichier ? L'utilisation d'une variable pour stocker l'identifiant du fichier ouvert est-elle une erreur ? Est-il nécessaire de créer une variable pour le handle de chaque fichier à ouvrir ?

Lorsque vous ouvrez un fichier, vous obtenez un "code d'accès" à celui-ci - un "handle". Tant que vous ne l'avez pas fermé, vous pouvez travailler avec le fichier par le biais de sa poignée, que les autres fichiers soient ouverts ou non.

P.S. N'oubliez pas de fermer les fichiers (ils ne sont pas fermés dans l'exemple).

 

Besoin d'un script pour une recherche Excel.
Description.
Pendant 30 jours de 8.00 à 12.00 tous les jours pour imprimer dans un fichier csv le prix d'ouverture et de fermeture des chandeliers dans cet intervalle de temps.Période - sur laquelle l'indicateur mis mais pas plus d'une heure.Indicateur lui-même ne doit pas afficher quoi que ce soit et enregistrer dans les tampons.

Comment faire les cycles correctement ?

extern int   DayMax     =30;     //количество дней для печати
extern int   DayStart   =1;      //начинаем с первого бара
extern int   HourStart  =10;     //время старта внутри дня
extern int   HourEnd    =12;     //время конца внутри дня
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   int per=Period();  
   if(per>60)return;  //если период больше часа , прекращаем работу скрипта
   double c_o=0,ABS_o_c=0;

  
      for(int d=DayStart;d<=DayMax;d++)//перебираем дни от DayStart до DayMax, т.е с вчерашнего до 30
      {
          for(int h=0;h<60/per*24;h++) //перебираем бары с нолевого до последнего в сутках учитывая ТФ
          {
            if(Time[h]>HourStart && Time[h]<HourEnd)//проверка промежутка времени
            {
               //данные для печати и печать
               c_o=(Close[h]-Open[h])*Point;
               ABS_o_c=MathAbs(c_o);
               
               f_PrintToFile(DayOfWeek(),TimeToString(TimeCurrent(),TIME_DATE|TIME_MINUTES),Open[h],Close[h],c_o,ABS_o_c);
               Print(DayOfWeek(),TimeToString(TimeCurrent(),TIME_DATE|TIME_MINUTES),Open[h],Close[h],c_o,ABS_o_c);
            }
          }
      }      
  }
//+------------------------------------------------------------------+
// 1.  В файл                           
//+------------------------------------------------------------------+
 void f_PrintToFile(int   f_DayOfWeek=0,
                          string f_TimeCurrent="", 
                          double f_Open=0,
                          double f_Close=0,
                          double f_c_o=0,
                          double f_ABS_o_c=0)
{
   string fileName=StringConcatenate(Symbol()," M",Period()," Tyrimas");
   string FileType=".csv";
   int handle;
   handle=FileOpen(fileName+FileType,FILE_WRITE|FILE_READ,";");
   if(handle!=INVALID_HANDLE)
   {
      FileSeek(handle,0,SEEK_END);
      FileWrite(handle,f_DayOfWeek,f_TimeCurrent,f_Open,f_Close,f_c_o,f_ABS_o_c);
      FileClose(handle);
   }
}

J'ai des doutes sur la ligne car probablement la boucle ne comprend pas le début de la journée, et fonctionne avec juste une barre de zéro.

for(int h=0;h<60/per*24;h++)

Aidez-moi.

 
Pouvez-vous me dire comment supprimer un objet d'un graphique de prix à partir d'un indicateur installé dans une fenêtre de graphique ?
 
Leo59:
Pouvez-vous me dire comment supprimer un objet d'un graphique de prix à partir d'un indicateur installé dans une fenêtre de graphique ?

La fenêtre graphique a toujours un index de 0.

bool  ObjectDelete(
   long     chart_id,     // идентификатор графика
   string   object_name   // имя объекта
   );
 
rvc:


Je m'excuse d'avoir encombré la page entière.

Il est difficile d'attacher le code correctement. Il existe un bouton spécial SRC dans l'éditeur.
 
Vinin:
Il est difficile d'attacher le code correctement. Il existe un bouton spécial SRC dans l'éditeur.
Je n'ai pas pu le trouver ((
 
rvc:
Je n'ai pas pu le trouver ((

Devant la caméra vidéo SRC pour insérer le code!

 
вот получилось ))) так как можно ли исправить? вообщем нужно чтобы вместо stop loss выставлялся отложенник либо новая ставка увеличенного лота.
extern double       Lots =0.1;  //стартовый лот
extern double     Factor =2.0;  //множитель лота
extern int         Limit =5;    //ограничение количества умножений лота
extern int      StopLoss =100;  //уровень ограничения убытков
extern int    TakeProfit =100;  //уровень фиксации прибыли
extern int     StartType =0;    //тип стартового ордера, 0-BUY, 1-SELL
extern int         Magic =1000; //индивидуальный номер эксперта
//----
double lots_step;
//----
int ticket_buy;
int ticket_sell;
int lots_digits;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
   ticket_buy=-1;
   ticket_sell=-1;
//----
   lots_step=MarketInfo(Symbol(),MODE_LOTSTEP);
//----
   if(lots_step==0.01)
      lots_digits=2;
//----
   if(lots_step==0.1)
      lots_digits=1;
//----
   if(lots_step==1.0)
      lots_digits=0;
//----
   for(int pos=OrdersTotal()-1;pos>=0;pos--)
      if(OrderSelect(pos,SELECT_BY_POS)==true)
         if(OrderMagicNumber()==Magic)
            if(OrderSymbol()==Symbol())
              {
               if(OrderType()==OP_BUY)
                 {
                  ticket_buy=OrderTicket();
                  break;
                 }
               //----
               if(OrderType()==OP_SELL)
                 {
                  ticket_sell=OrderTicket();
                  break;
                 }
              }
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {return(0);}
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
   double price;
   double lots;
   double lots_test;
//----
   int slip;
   int ticket;
   int pos;
//----
//----открыть стартовый ордер BUY
   if(StartType==0)
      if(ticket_buy<0)
         if(ticket_sell<0)
           {
            ticket=OpenBuy(Lots);
            //----
            if(ticket>0)
               ticket_buy=ticket;
           }
//----
//----открыть следующий ордер BUY при положительном профите ордера BUY
   if(ticket_buy>0)
      if(ticket_sell<0)
         if(OrderSelect(ticket_buy,SELECT_BY_TICKET)==true)
            if(OrderCloseTime()>0)
               if(OrderProfit()>0.0)
                 {
                  ticket=OpenBuy(Lots);
                  //----
                  if(ticket>0)
                     ticket_buy=ticket;
                 }
//----
//----открыть следующий ордер SELL при отрицательном профите ордера BUY
   if(ticket_buy>0)
      if(ticket_sell<0)
         if(OrderSelect(ticket_buy,SELECT_BY_TICKET)==true)
            if(OrderCloseTime()>0)
               if(OrderProfit()<0.0)
                 {
                  lots=NormalizeDouble(MathCeil((OrderLots()*Factor)/lots_step)*lots_step,lots_digits);
                  lots_test=Lots;
                  //----
                  for(pos=0;pos<Limit;pos++)
                     lots_test=NormalizeDouble(MathCeil((lots_test*Factor)/lots_step)*lots_step,lots_digits);
                  //----
                  if(lots_test<lots)
                     lots=Lots;
                  //----
                  ticket=OpenSell(lots);
                  //----
                  if(ticket>0)
                    {
                     ticket_sell=ticket;
                     ticket_buy=-1;
                    }
                 }
//----
//----обслуживание виртуальных стопов ордера BUY
   if(ticket_buy>0)
      if(OrderSelect(ticket_buy,SELECT_BY_TICKET)==true)
         if(OrderCloseTime()==0)
            if(OrderOpenPrice()+TakeProfit*Point<=MarketInfo(Symbol(),MODE_BID))
              {
               price=MarketInfo(Symbol(),MODE_BID);
               slip=MarketInfo(Symbol(),MODE_SPREAD)*2;
               return(OrderClose(ticket_buy,OrderLots(),price,slip,Blue));
              }
//----
   if(ticket_buy>0)
      if(OrderSelect(ticket_buy,SELECT_BY_TICKET)==true)
         if(OrderOpenPrice()-StopLoss*Point>=MarketInfo(Symbol(),MODE_BID))
            if(OrderCloseTime()==0)
              {
               price=MarketInfo(Symbol(),MODE_BID);
               slip=MarketInfo(Symbol(),MODE_SPREAD)*2;
               return(OrderClose(ticket_buy,OrderLots(),price,slip,Blue));
              }
//----
//----открыть стартовый ордер SELL
   if(StartType==1)
      if(ticket_buy<0)
         if(ticket_sell<0)
           {
            ticket=OpenSell(Lots);
            //----
            if(ticket>0)
               ticket_sell=ticket;
           }
//----
//----открыть следующий ордер SELL при положительном профите ордера SELL
   if(ticket_buy<0)
      if(ticket_sell>0)
         if(OrderSelect(ticket_sell,SELECT_BY_TICKET)==true)
            if(OrderCloseTime()>0)
               if(OrderProfit()>0.0)
                 {
                  ticket=OpenSell(Lots);
                  //----
                  if(ticket>0)
                     ticket_sell=ticket;
                 }
//----
//----открыть следующий ордер BUY при отрицательном профите ордера SELL
   if(ticket_buy<0)
      if(ticket_sell>0)
         if(OrderSelect(ticket_sell,SELECT_BY_TICKET)==true)
            if(OrderCloseTime()>0)
               if(OrderProfit()<0.0)
                 {
                  lots=NormalizeDouble(MathCeil((OrderLots()*Factor)/lots_step)*lots_step,lots_digits);
                  lots_test=Lots;
                  //----
                  for(pos=0;pos<Limit;pos++)
                     lots_test=NormalizeDouble(MathCeil((lots_test*Factor)/lots_step)*lots_step,lots_digits);
                  //----
                  if(lots_test<lots)
                     lots=Lots;
                  //----
                  ticket=OpenBuy(lots);
                  //----
                  if(ticket>0)
                    {
                     ticket_buy=ticket;
                     ticket_sell=-1;
                    }
                 }
//----
//----обслуживание виртуальных стопов ордера SELL
   if(ticket_sell>0)
      if(OrderSelect(ticket_sell,SELECT_BY_TICKET)==true)
         if(OrderCloseTime()==0)
            if(OrderOpenPrice()-TakeProfit*Point>=MarketInfo(Symbol(),MODE_ASK))
              {
               price=MarketInfo(Symbol(),MODE_ASK);
               slip=MarketInfo(Symbol(),MODE_SPREAD)*2;
               return(OrderClose(ticket_sell,OrderLots(),price,slip,Red));
              }
//----
   if(ticket_sell>0)
      if(OrderSelect(ticket_sell,SELECT_BY_TICKET)==true)
         if(OrderCloseTime()==0)
            if(OrderOpenPrice()+StopLoss*Point<=MarketInfo(Symbol(),MODE_ASK))
              {
               price=MarketInfo(Symbol(),MODE_ASK);
               slip=MarketInfo(Symbol(),MODE_SPREAD)*2;
               return(OrderClose(ticket_sell,OrderLots(),price,slip,Red));
              }
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| открыть ордер BUY                                                |
//+------------------------------------------------------------------+
int OpenBuy(double lots)
  {
   double price;
//----
   int slip;
//----
   price=MarketInfo(Symbol(),MODE_ASK);
   slip=MarketInfo(Symbol(),MODE_SPREAD)*2;
//----
   return(OrderSend(Symbol(),OP_BUY,lots,price,slip,0.0,0.0,"",Magic,0,Blue));
  }
//+------------------------------------------------------------------+
//| открыть ордер SELL                                               |
//+------------------------------------------------------------------+
int OpenSell(double lots)
  {
   double price;
//----
   int slip;
//----
   price=MarketInfo(Symbol(),MODE_BID);
   slip=MarketInfo(Symbol(),MODE_SPREAD)*2;
//----
   return(OrderSend(Symbol(),OP_SELL,lots,price,slip,0.0,0.0,"",Magic,0,Red));
  }
//+------------------------------------------------------------------+
 
Les gens vous aident de toutes les manières possibles !!!! ou est-ce irréaliste ?
 
Aidez un programmeur novice à écrire un script pour supprimer les ordres en attente. Tous les ordres d'achat en attente doivent être supprimés lorsqu'il n'y a pas de positions sur le marché ni d'ordres de vente en attente.
Raison: