[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 479

 
Svinozavr >>:

Да, кажется, все проще - время сделки-то известно. Если так, то время по тайм-фрейму будет таково:


Time[iBarShift(NULL,tf,DealTime)]

где
tf - нужный тайм-фрейм,
DealTime - время (с датой) сделки


Thanks, but what about if there is no deal yet and DealTime is the known time of the planned deal?

 
MoneyJinn >>:


Спасибо, а как быть если сделки еще не было и DealTime - известное время планируемой сделки?

Why?))) ok. It's even simpler: tf*60*MathFloor(DealTime/60/tf) // the meaning of variables is the same

You can check the script:

#property show_inputs
extern int tf=1440;
extern datetime DealTime;

void start() {Alert(TimeToStr(tf*60*MathFloor(DealTime/60/tf)));}
===
Corrected. Forgot to convert seconds to minutes.)))
 
I have about 200 MA in my EA and when I test them, when I press "open chart" they all show up.
can I remove them to hide them?
thanks
 
snowman647 >>:
у меня в советнике около 200 MA, при тестировани, когда жмешь "открыть график" они все рисуються.
можно их както убрать, чтоб не видно было?
спасибо

void HideTestIndicators( bool hide)
The function sets flag to hide indicators called by the Expert Advisor. When the chart is opened after the test, the indicators marked with the hide flag will not be displayed in the test chart. Indicators will be flagged with the current hiding flag before each call.
It should be noted that only those indicators that are directly called from the Expert Advisor under test can be shown in the testing chart.

 
I am trying to master the MQL language and as practice I decided to add Martingale function to my EA!
I wanted to open an order with the SL by lot multiplied by the coefficient and in case of TP I would start with the original lot!
I do not know how to put a condition on TP and SL!
Please, advise me how to use the right code!
//--------------------------------------------------------------------
extern int  stoploss    = 50,
            takeprofit  = 50;
extern double  mult=2;
extern double      Lot=1;
int         tip;
//--------------------------------------------------------------------
int init()
{
   OrderSend(Symbol(),OP_SELL,Lot,Bid,3,NormalizeDouble(Ask + stoploss*Point,Digits),
                        NormalizeDouble(Bid - takeprofit*Point,Digits)," ",777,Blue);
}
//--------------------------------------------------------------------
int start()
{
   for (int i=0; i<OrdersTotal(); i++){   
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true){
         if (OrderSymbol()==Symbol()){
            tip = OrderType();
            Lot = OrderLots();return;}}}
   if (Lot==0) return;
   if (tip==0) OrderSend(Symbol(),OP_SELL,Lot*mult,Bid,3,NormalizeDouble(Ask + stoploss*Point,Digits),
                                    NormalizeDouble(Bid - takeprofit*Point,Digits)," ",777,Blue);
   if (tip==1) OrderSend(Symbol(),OP_BUY ,Lot*mult,Ask,3,NormalizeDouble(Bid - stoploss*Point,Digits),
                                    NormalizeDouble(Ask + takeprofit*Point,Digits)," ",777,Blue);
   return(0);
}
//-----------------------------------------------------------------
 
Kogalym >>:
Пытаюсь освоить язык MQL в качестве практики решил добавить в советник перевертыш функцию Мартингейла!
Что бы при SL открывал ордер лотом умноженным на коэффициент, а при TP начинал с первоночального лота!
Но получилось что лот увеличивается с каждым ордером, не знаю как поставить условие на TP и SL!
Подскажите пожалуйста как должен выглядеть правильный код!

There must be a function like this

double getLot()
{
   if(OrdersHistoryTotal()==0)return(0.1);
   // ищем самый последний закрытый ордер
   datetime time=0;
   int ticket=-1;
   for(i=OrdersHistoryTotal()-1;i>=0;i--)
   {
      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
      {
         if(OrderSymbol()==Symbol())
         {
            if(OrderCloseTime()>time)
            {
               time=OrderCloseTime();
               ticket=OrderTicket();
            }
         }
      }
   }
   if(OrderTicket()!=ticket)OrderSelect(ticket,SELECT_BY_TICKET);
   if(OrderProfit()<=0) return(NormalizeDouble(OrderLots()*Martin_Koef,2));
   if(OrderProfit()>0)return(0.1);
   //-----
}
 
Roger >>:

Да уже плешь проели с этим вопросом. Набираешь old tick здесь в поисковике и читаешь, читаешь, читаешь.

If you're so smart, why do you come here? You mean you don't mind writing a sassy letter, but you don't mind replying. Well, well.

 
StatBars >>:

Должна быть функция вроде этой


I don't understand what the time has to do with it.
I think only the last 3 lines are responsible for the lot increase in case of a loss
if(OrderTicket()!=ticket)OrderSelect(ticket,SELECT_BY_TICKET);
   if(OrderProfit()<=0) return(NormalizeDouble(OrderLots()*Martin_Koef,2));
   if(OrderProfit()>0)return(0.1);
 
Kogalym >>:


Не понимаю причем там время???
По моему за наращивание лота при убытке отвечают только 3 последние строчки

This function finds the last closed order and calculates the lot based on its profit. If you have a closed order on Stop Loss, which is never positive in terms of profit, and a closed order on Take Profit, which is never negative in terms of profit, this function will work correctly.
If you have a trawl of some kind, the function needs to be rewritten.

 
StatBars >>:

При том что функция находит последний закрытый ордер, по его профиту расчитывается лот. Если у Вас закрытый ордер по стоплоссу никогда не будет положительным по профиту, а закрытый по тейкпрофиту ордер никогда не будет отрицателен по профиту, то функция корректно отработает.
Если же у Вас есть трал какой-нибудь то функцию нужно переделать.

I wrote an Expert Advisor which at TP opens an order in the same direction, and at SL opens an order in the opposite direction, but I cannot insert the Martingale function and return to the original

//--------------------------------------------------------------------
extern int  stoploss    = 50,
            takeprofit  = 50;
extern double  mult=2;
extern double      Lot=1;
//--------------------------------------------------------------------
int init()
{
   OrderSend(Symbol(),OP_SELL,Lot,Bid,3,NormalizeDouble(Ask + stoploss*Point,Digits),
                        NormalizeDouble(Bid - takeprofit*Point,Digits)," ",777,Blue);
}
//--------------------------------------------------------------------
int start()
{   for (int i=0; i<OrdersTotal(); i++){   
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true){
         if (OrderSymbol()==Symbol()){
         Lot = OrderLots();return;}}}
            if (Lot==0) return;
        
  if(OrderType() == OP_SELL)
     if(OrderProfit()>0) OrderSend(Symbol(),OP_SELL,Lot,Bid,3,NormalizeDouble(Ask + stoploss*Point,Digits),
                                    NormalizeDouble(Bid - takeprofit*Point,Digits)," ",777,Blue);
   else OrderSend(Symbol(),OP_BUY ,Lot,Ask,3,NormalizeDouble(Bid - stoploss*Point,Digits),
                                    NormalizeDouble(Ask + takeprofit*Point,Digits)," ",777,Blue);
                                                                        
    if(OrderType() == OP_BUY) 
    if(OrderProfit()>0) OrderSend(Symbol(),OP_BUY ,Lot,Ask,3,NormalizeDouble(Bid - stoploss*Point,Digits),
                                    NormalizeDouble(Ask + takeprofit*Point,Digits)," ",777,Blue);
    else OrderSend(Symbol(),OP_SELL,Lot,Bid,3,NormalizeDouble(Ask + stoploss*Point,Digits),
                                    NormalizeDouble(Bid - takeprofit*Point,Digits)," ",777,Blue);
                                     
       
   return(0);
}
//-----------------------------------------------------------------

I cannot insert function of Martingale, I cannot return to the original lot! Maybe you can show me where this function should be placed!

Reason: