Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 937

 

Need a script for Excel research.
Description.
For 30 days from 8.00 to 12.00 every day to print in csv file print opening and closing price of candlesticks in this time interval.Period - on which the indicator put but not more than one hour.Indicator itself should not display anything and save in buffers.

How to make the cycles correct?

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

I have doubts about the line because probably the loop does not understand the start of the day, and works with just a zero bar.

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

Help to understand.

 
Can you please tell me how to delete an object from a price chart from an indicator installed in a chart window?
 
Leo59:
Can you please tell me how to delete an object from the price chart from an indicator installed in a chart window?

The chart window always has an index of 0.

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


I apologise for cluttering up the whole page.

It's hard to attach the code correctly. There is a special SRC button in the editor
 
Vinin:
It's hard to attach the code correctly. There is a special SRC button in the editor
couldn't find it ((
 
rvc:
couldn't find it ((

In front of the video camera SRC to insert 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));
  }
//+------------------------------------------------------------------+
 
People help in any way you can!!!! or is it unrealistic?
 
Help a novice programmer write a script to delete pending orders. All pending buy orders need to be deleted when there are no market positions and no pending sell orders.
 

Hello, I can't understand one thing.

I need to calculate the amount of possible losses on an order in the currency of the deposit. The task seems trivial. I have made a construction like this:

OrderSelect(vID, SELECT_BY_TICKET);   
vDepoLoss = (OrderStopLoss() - OrderOpenPrice()) / MarketInfo(OrderSymbol(), MODE_TICKSIZE) * MarketInfo(OrderSymbol(), MODE_TICKVALUE) * OrderLots();

In most cases it calculates correctly. But I've found a symbol by which the calculation is wrong - HSI. Stubbornly counts not in deposit currency, but in something else (probably in yuan)