[Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2. - page 227

 
drknn:

Increase the slippage. The trades must have been opened in a fast market. It happens sometimes after important news that the Eurobucks is so fast in 1-2 ticks that it's a nightmare. And while the server is processing the EA's order the price changes very abruptly.


I am afraid that if Slippage is always large, DT may start abusing it on systematic basis. It would be desirable to "move" it dynamically - only if the price on the server was better than that at which the order was sent. It would be similar to manual bidding - if the requested price is no longer available, then a new one will be offered which can be accepted by pressing OK or rejected - if it is the same situation, of course.

 

Hi all! Please help me combine the following things. The result should be: two lines following the price, one lower than Ask by 20 pips..,

the other one is higher. Besides, I get a beep if price changes by 20 points per 1 tick.

All works fine separately. Thanks in advance!

1) The line below the Ask by 20 pips.

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int start()
{
ObjectCreate("MyPriceLine", OBJ_HLINE, 0, 0, Ask-20*Point) ;
ObjectSet("MyPriceLine", OBJPROP_PRICE1, Ask-20*Point);
return(0);
}

//+------------------------------------------------------------------+

2) The line is 20 pips above the Ask.

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int start()
{
ObjectCreate("MyPriceLine", OBJ_HLINE, 0, 0, Ask+20*Point) ;
ObjectSet("MyPriceLine", OBJPROP_PRICE1, Ask+20*Point);
return(0);
}

//+------------------------------------------------------------------+

3) Rate of price change over time.

#property show_inputs

extern int pips=2; //изменение аск
extern double Time_=0.1; //c. ~ tick
extern bool все_из_обзора_рынка=true; // только текущий символ - false

int i, l, p, количество_символов;
string val[], на_экран;
int Ask_save[];

//+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
void start(){
количество_символов=SymbolsList(val, true);//запись в массив val инструменты и их количество вызов функции SymbolsList
ArrayResize(Ask_save,количество_символов);
if(количество_символов == -1){ Alert("Ошибка открытия файла в SymbolsList(string &Symbols[], bool Selected)"); return;}
if(!все_из_обзора_рынка){
количество_символов=1;
ArrayResize(Ask_save,количество_символов);
ArrayResize(val,количество_символов);
val[0]=Symbol();
}

while(true&&!IsStopped()){ //если разрешить и не отанавливать скрипт продолжим

Alert("пересчитаем через "+Time_+" сек.");

for(i=0;i<количество_символов;i++){//посчитаем стоимость спреда для инструментов из обзора рынка
if((Ask_save[i]-MarketInfo(val[i],MODE_ASK)/MarketInfo(val[i],MODE_POINT))>=pips){
Alert(val[i]+","+Period()+" изменился вниз на "+DoubleToStr((Ask_save[i]-MarketInfo(val[i],MODE_ASK)/MarketInfo(val[i],MODE_POINT)),0)+" pips");
PlaySound("timeout.wav");
}
if((MarketInfo(val[i],MODE_ASK)/MarketInfo(val[i],MODE_POINT)-Ask_save[i])>=pips){
Alert(val[i]+","+Period()+" изменился вверх на "+DoubleToStr((MarketInfo(val[i],MODE_ASK)/MarketInfo(val[i],MODE_POINT)-Ask_save[i]),0)+" pips");
PlaySound("email.wav");
}
Ask_save[i]=MarketInfo(val[i],MODE_ASK)/MarketInfo(val[i],MODE_POINT);
}
Sleep(Time_*1000);//пауза сек.
}

/*
количество_символов=SymbolsList(val, true);//запись в массив val инструменты и их количество вызов функции SymbolsList
if(количество_символов == -1){ Alert("Ошибка открытия файла в SymbolsList(string &Symbols[], bool Selected)"); return;}

while(true&&!IsStopped()){ //если разрешить и не отанавливать скрипт продолжим
на_экран="\r\n"; //отступ
for(i=0;i<количество_символов;i++)//посчитаем стоимость спреда для инструментов из обзора рынка
на_экран=на_экран+val[i]+" стоимость спреда = " + DoubleToStr(MarketInfo(val[i],MODE_SPREAD)*MarketInfo(val[i],MODE_TICKVALUE),0)+"\r\n";
Comment(на_экран);//выведем на экран
Alert("Пересчитаем");//сигнал
Sleep(3000);//пауза 3 сек.
}
*/
}
void deinit(){Comment("");}
//+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=


//+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
// функция читает из обзора рынка все фин.инстр.
//+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
int SymbolsList(string &Symbols[], bool Selected){
int Offset, SymbolsNumber; string SymbolsFileName;
if(Selected) SymbolsFileName = "symbols.sel"; else SymbolsFileName = "symbols.raw";
int hFile = FileOpenHistory(SymbolsFileName, FILE_BIN|FILE_READ);
if(hFile < 0) return(-1); if(Selected) { SymbolsNumber = (FileSize(hFile) - 4) / 128; Offset = 116; }
else { SymbolsNumber = FileSize(hFile) / 1936; Offset = 1924; }
ArrayResize(Symbols, SymbolsNumber);
if(Selected) FileSeek(hFile, 4, SEEK_SET);
for(int i = 0; i < SymbolsNumber; i++){Symbols[i] = FileReadString(hFile, 12); FileSeek(hFile, Offset, SEEK_CUR);}
FileClose(hFile);
return(SymbolsNumber);
}
 
Vovo4ka:

Like, a clever petrosian wants to make a joke...))

I'm sorry about that, the money is yours. The more of you, the better off we are.
 
ScioMe:

MetaEditor has a standard iMA indicator. Feel free to use it :)
Please tell me where to get it and where to put it, I'm still a complete dummie...
 
Vovo4ka:
People! I'm trying to make, that would trade a lot depending on the risk.... what does not come out....writes

Please advise where the error is....

Do you have only one order of the right type in your trading history?

if(OrderProfit()>0) break;

If there is an order which closed in profit - we drop out of the loop and don't check the rest of the history...

int    orders=HistoryTotal();     // history orders tota l

This is your own function? Or OrdersHistoryTotal()?

I'm confused by searching for the number of losing orders. If you need the last closed order, where is the check for the last order?

Here is the homework for your own analysis:

int losses=0;
for (int i=0; i<OrdersHistoryTotal(); i++) {                // Цикл по истории терминала
   if (OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) {         // Если ордер выбран ...
      if (OrderSymbol()!=Symbol())     continue;            // Если символ ордера не наш -  к следующему ордеру
      if (OrderType()>OP_SELL)         continue;            // Если тип ордера не наш -     к следующему ордеру
      if (OrderMagicNumber()!=Magic)   continue;            // Если магик ордера не наш -   к следующему ордеру
      if (OrderProfit()>=0)            continue;            // Если профит ордера в плюсе - к следующему ордеру
      if (OrderProfit()<0)                                  // Ордер закрыт в минусе ...
         losses++;                                          // Увеличиваем счётчик убыточных ордеров      
      }
   else if (!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) {   // Если не удалось выбрать ордер ...
      Print("Error in history! ", GetLastError());          // Сообщим об ошибке и посмотрим её код
      break;                                                // Прерываем цикл перебора ордеров
      }
   }

And here's one more thing:

if(ldlot<0.1) ldlot=0.1;

Can all the same it is better to make check for less than minimally-admissible?

double MinLot=MarketInfo(Symbol(),MODE_MINLOT);
if (ldlot<MinLot) ldlot=MinLot;

And at the same time, is it larger than the maximum (when passing the lot size to the function)?

double MaxLot=MarketInfo(Symbol(),MODE_MAXLOT);
if (ldlot>MaxLot) ldlot=MaxLot;
 
doon:

Thanks, but you'll still have to put a slip in there.

I don't get it, why do you need it there? It seems simple to me.
 
ZZZEROXXX:


I fear that if Slippage is always high, the DC might start abusing it on a systematic basis.

If the DC starts abusing it, nothing will help. Here's another thing that might work. If your brokerage company has floating spreads, then it is better to use the function with auto-determination of the spread size and slippage should be set to three spreads. Then the slippage will be dynamically changing.
 
Tell me, if I work with orders by ticket, how to write a variable (int Ticket), as static local or as usual global or in general, as usual local? I am confused. Thank you.
 
Fam:
Please advise, if we work with orders by ticket, how to correctly write the variable (int Ticket), as a static local one or as a regular global one, or generally as a regular local one? I am confused. Thank you.

It all depends on whether this variable will be available to all EA functions (well... not all, but some for sure). Then the variable is global.

If it is used only in one function, then it is local.

The question is like "which water to put the flowers in, plain or sweetened water" ... while you were guessing, the flowers became a broom, in the bath... :))

 
ZZZEROXXX:


I fear that if Slippage is always high, the DC may abuse it on a systematic basis. I would like to "slippage" it dynamically - only if the price on the server is better than the price at which the order was sent. It would be similar to manual bidding - if the requested price is no longer available, then a new one will be offered which can be accepted by pressing OK or rejected - if it is the same situation, of course.

Try to make the slippage dependent on volatility first. In a calm market it will be minimal, in a fast market it will spread wider.