Qualsiasi domanda da principiante, per non ingombrare il forum. Professionisti, non passate oltre. Da nessuna parte senza di te - 6. - pagina 937

 
silachara:

Ha iniziato a imparare a lavorare con i file. Mi sono imbattuto nel termine maniglia. La domanda è sorta dopo aver scritto il codice:

Dopo aver aperto il primo file news.csv, il programma imposta la variabile filehandle a 1. Successivamente, il programma ha aperto il secondo file news150901.csv e ha impostato la variabile filehandle a 2. Si scopre che il programma è ora lasciato con un valore di handle solo dall'apertura del secondo file. In altre parole, ho ucciso il valore dell'handle del primo file aperto. Cioè posso solo accedere ai dati/contenuti e chiudere il secondo file? Usare una variabile per memorizzare l'handle del file aperto è un errore? È necessario creare una variabile per l'handle per ogni file da aprire?

Quando si apre un file, si ottiene un "codice di accesso" ad esso - un handle. Finché non l'avete chiuso, potete lavorare con il file attraverso la sua maniglia, indipendentemente dal fatto che gli altri file siano aperti o meno.

P.S. Non dimenticate di chiudere i file (non sono chiusi nell'esempio).

 

Ho bisogno di uno script per una ricerca su Excel.
Descrizione.
Per 30 giorni dalle 8.00 alle 12.00 ogni giorno per stampare in file csv stampa apertura e prezzo di chiusura delle candele in questo intervallo di tempo.Periodo - su cui l'indicatore messo ma non più di un'ora.Indicatore stesso non dovrebbe visualizzare nulla e salvare in buffer.

Come rendere i cicli corretti?

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);
   }
}

Ho dei dubbi sulla linea, quindi forse il ciclo non capisce l'inizio del giorno, ma funziona da zero bar.

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

Aiutami.

 
Potete dirmi per favore come cancellare un oggetto da un grafico dei prezzi da un indicatore installato in una finestra del grafico?
 
Leo59:
Potete dirmi per favore come cancellare un oggetto da un grafico dei prezzi da un indicatore installato in una finestra del grafico?

La finestra del grafico ha sempre un indice di 0.

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


Mi scuso per aver ingombrato tutta la pagina.

È difficile allegare il codice correttamente. C'è un pulsante speciale SRC nell'editor
 
Vinin:
È difficile allegare il codice correttamente. C'è un pulsante speciale SRC nell'editor
non è riuscito a trovarlo ((
 
rvc:
non è riuscito a trovarlo ((

Davanti alla videocamera SRC per inserire il codice!

 
вот получилось ))) так как можно ли исправить? вообщем нужно чтобы вместо 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));
  }
//+------------------------------------------------------------------+
 
La gente aiuta in ogni modo possibile!!!! o non è realistico?
 
Aiuta un programmatore principiante a scrivere uno script per cancellare gli ordini in sospeso. Tutti gli ordini di acquisto pendenti devono essere cancellati quando non ci sono posizioni di mercato e nessun ordine di vendita pendente.