An advisor that would follow the rate on a five-minute chart with conditions after launch: - page 13
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Again a mishap.
I'm trying to make the above code work. An error appears in the log with the text:
18:38:23 '153085': order sell 1.00 GBPUSD opening at 2.0006 sl: 2.0019 tp: 2.0003 failed [Invalid S/L or T/P]
What is the meaning of this?
1) And what MT4 do you use?
2) What is the allowed stoploss and takeprofit distance in this brokerage house?
Before that, yesterday with these parameters t/r and s/l all worked :(((
I would do this...
Contract specifications
(for mini *100)
for micro
(for mini *100)
levels
buy
sale
//+------------------------------------------------------------------+ //| Expert-000001.mq4 | //| Copyright © 2008, salesman*** | //| http://www.forexgrand.ru | //+------------------------------------------------------------------+ #property copyright "Copyright © 2008, salesman***" #property link "http://www.forexgrand.ru" //---- extern string _Parameters_b_Lots = "Параметры модуля расчёта лота"; extern int LotsWayChoice = 0; // Способ выбора рабочего лота // 0-фиксированный, // 1-процент от депозита, // 2-фракционно-пропорциональный, // 3-фракционно-фиксированный, //extern int LotsPercent = 40; // Процент от депозита extern double StopLoss=13; // Stop Loss extern double TakeProfit=3; // Take Profit //extern int Percent=70; extern double Lots=1; // Объем сделки в % extern double Slippage =4; // Максимальное отклонение от запрошенной цены extern int MagicNumber=0; // Order ID extern int Delta=15; // Сигнал приказа в пунктах //extern int TimeForSleep = 0; // Время для отдыха после сделки extern int ticket; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } int start() { int total=OrdersTotal(); if(total<1) {// если нет открытых позиций if (NumberOfBarOpenLastPos("", 0, -1, MagicNumber)>0){ //--- if (Ask - iOpen(NULL,0,0)>=Delta*Point) //Цена выросла больше Delta пунктов - продаем!!! { ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"Продал"); if(ticket<0){Print("Ошибка открытия ордера SELL #",GetLastError());return(0);} } //------------------------------------------------------------------------- if (iOpen(NULL,0,0)-Bid >=Delta*Point) //цена упала больше Delta пунктов - покупаем!!! { ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid-StopLoss*Point,Ask+TakeProfit*Point,"Купил"); if(ticket<0){Print("Ошибка открытия ордера BUY #",GetLastError());return(0);} } //---- } //if (NumberOfBarOpenLastPos }//if(OrdersTotal return(0); } //------------------------------ //+----------------------------------------------------------------------------+ //| Возвращает номер бара открытия последней позиции или -1. | //| Параметры: | //| sym - наименование инструмента ("" - текущий символ) | //| tf - таймфрейм ( 0 - текущий таймфрейм) | //| op - операция (-1 - любая позиция) | //| mn - MagicNumber (-1 - любой магик) | //+----------------------------------------------------------------------------+ int NumberOfBarOpenLastPos(string sym="", int tf=0, int op=-1, int mn=-1) { datetime oot; int i, k=OrdersTotal(); if (sym=="") sym=Symbol(); for (i=0; i<k; i++) { if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol()==sym) { if (OrderType()==OP_BUY || OrderType()==OP_SELL) { if (op<0 || OrderType()==op) { if (mn<0 || OrderMagicNumber()==mn) { if (oot<OrderOpenTime()) oot=OrderOpenTime(); } } } } } } return(iBarShift(sym, tf, oot, True)); }There seems to be something wrong with the line
Without this condition, the Expert Advisor works...
Why did you put some parameters there to calculate the lot? You don't need it...
'Lots' - variable already defined C:\Program Files\MetaTrader - E-Global TFG\experts\expert-001.mq4 (21, 15)
Here is the code:
//+------------------------------------------------------------------+ //| Expert-001.mq4 | //| Copyright © 2008, salesman*** | //| http://www.forexgrand.ru | //+------------------------------------------------------------------+ #property copyright "Copyright © 2008, salesman***" #property link "http://www.forexgrand.ru" #include <b-Lots.mqh> #include <stdlib.mqh> //---- //extern string _Parameters_b_Lots = "Параметры модуля расчёта лота"; //extern int LotsWayChoice = 0; // Способ выбора рабочего лота // 0-фиксированный, // 1-процент от депозита, // 2-фракционно-пропорциональный, // 3-фракционно-фиксированный, //extern int LotsPercent = 40; // Процент от депозита extern double StopLoss=13; // Stop Loss extern double TakeProfit=3; // Take Profit //extern int Percent=70; extern double Lots=0.9; // Объем сделки в % extern double Slippage =4; // Максимальное отклонение от запрошенной цены extern int MagicNumber=0; // Order ID extern int Delta=15; // Сигнал приказа в пунктах //extern int TimeForSleep = 0; // Время для отдыха после сделки extern int ticket; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } int start() { int total=OrdersTotal(); if(total<1) {// если нет открытых позиций if (NumberOfBarOpenLastPos("", 0, -1, MagicNumber)>0){ //--- if (Ask - iOpen(NULL,0,0)>=Delta*Point) //Цена выросла больше Delta пунктов - продаем!!! { Lots=GetSizeLot(); ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"Продал"); if(ticket<0){Print("Ошибка открытия ордера SELL #",GetLastError());return(0);} } //------------------------------------------------------------------------- if (iOpen(NULL,0,0)-Bid >=Delta*Point) //цена упала больше Delta пунктов - покупаем!!! { Lots=GetSizeLot(); ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid-StopLoss*Point,Ask+TakeProfit*Point,"Купил"); if(ticket<0){Print("Ошибка открытия ордера BUY #",GetLastError());return(0);} } //---- } //if (NumberOfBarOpenLastPos }//if(OrdersTotal return(0); } //------------------------------ //+----------------------------------------------------------------------------+ //| Возвращает номер бара открытия последней позиции или -1. | //| Параметры: | //| sym - наименование инструмента ("" - текущий символ) | //| tf - таймфрейм ( 0 - текущий таймфрейм) | //| op - операция (-1 - любая позиция) | //| mn - MagicNumber (-1 - любой магик) | //+----------------------------------------------------------------------------+ int NumberOfBarOpenLastPos(string sym="", int tf=0, int op=-1, int mn=-1) { datetime oot; int i, k=OrdersTotal(); if (sym=="") sym=Symbol(); for (i=0; i<k; i++) { if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol()==sym) { if (OrderType()==OP_BUY || OrderType()==OP_SELL) { if (op<0 || OrderType()==op) { if (mn<0 || OrderMagicNumber()==mn) { if (oot<OrderOpenTime()) oot=OrderOpenTime(); } } } } } } return(iBarShift(sym, tf, oot, True)); }I told you to leave it in external parameters. The lot calculation parameters will then be set to PROPERTIES (from the library).
Check it out. Does it work or not? I ran it once - it works...
And it works too. I still need to understand the function
NumberOfBarOpenLastPos(string sym="", int tf=0, int op=-1, int mn=-1)A warning pops up:
Start function not found and cannot be run.
What does it mean?