Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 61 1...545556575859606162636465666768...1965 New comment RichLux 2017.01.08 20:54 #601 if(OrderBuy<1&& rsi>Urov_70 && rsi1<Urov_70){ tiket=OrderSend(_Symbol,OP_BUY,Lot,Ask,slippage,sl,tp,NULL,MagicNumber,0,clrBlue);}if(OrderSell<1&& rsi<Urov_30 && rsi1>Urov_30){ tiket=OrderSend(_Symbol,OP_SELL,Lot,Bid,slippage,sl,tp,NULL,MagicNumber,0,clrRed);}but it needsif(OrderBuy<1&& rsi>Urov_70 && rsi1<Urov_70){ tiket=OrderSend(_Symbol,OP_BUY,Lot,Ask,slippage,slBuy,tpBuy,NULL,MagicNumber,0,clrBlue);}if(OrderSell<1&& rsi<Urov_30 && rsi1>Urov_30){ tiket=OrderSend(_Symbol,OP_SELL,Lot,Bid,slippage,slSell,tpSell,NULL,MagicNumber,0,clrRed);} How to code? Questions from Beginners MQL4 Error 133 Artyom Trishkin 2017.01.08 21:05 #602 Ibragim Dzhanaev: Didn't help (double tp,sl,OrderBuy=0,OrderSell=0;double slSell,slBuy,tpSell,tpBuy; int tiket;//+------------------------------------------------------------------+//| Expert initialization function |//+------------------------------------------------------------------+int OnInit() { return(INIT_SUCCEEDED); }//+------------------------------------------------------------------+//| Expert deinitialization function |//+------------------------------------------------------------------+void OnDeinit(const int reason) { }//+------------------------------------------------------------------+//| Expert tick function |//+------------------------------------------------------------------+void OnTick() { for(int i=0; i<OrdersTotal(); i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) if(OrderSymbol()==_Symbol && OrderMagicNumber()==MagicNumber) { if(OrderType()==OP_BUY){} if(OrderType()==OP_SELL){} } } double rsi=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,0); double rsi1=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,1);//+------------------------------------------------------------------+ double StopLossLevel; double TakeProfitLevel; if(StopLoss>0) StopLossLevel=Bid-StopLoss*Point; else StopLossLevel=0.0; if(TakeProfit>0) TakeProfitLevel=Ask+TakeProfit*Point; else TakeProfitLevel=0.0; tpBuy=NormalizeDouble(Ask+TakeProfit*_Point,_Digits); slBuy=NormalizeDouble(Bid-StopLoss*_Point,_Digits); tpSell=NormalizeDouble(Bid-TakeProfit*_Point,_Digits); slSell=NormalizeDouble(Ask+StopLoss*_Point,_Digits);///--- if(OrderBuy<1 && rsi>Urov_70 && rsi1<Urov_70) { tiket=OrderSend(_Symbol,OP_BUY,Lot,Ask,slippage,sl,tp,NULL,MagicNumber,0,clrBlue); } if(OrderSell<1 && rsi<Urov_30 && rsi1>Urov_30) { tiket=OrderSend(_Symbol,OP_SELL,Lot,Bid,slippage,sl,tp,NULL,MagicNumber,0,clrRed); } }//+------------------------------------------------------------------+What do you even want with a code like that?What, and what is it that didn't work? [Deleted] 2017.01.08 21:08 #603 RichLux: if(OrderBuy<1&& rsi>Urov_70 && rsi1<Urov_70){tiket=OrderSend(_Symbol,OP_BUY,Lot,Ask,sl,sl,tp,NULL,MagicNumber,0,clrBlue)}if(OrderSell<1&& rsi<Urov_30 && rsi1>Urov_30){tiket=OrderSend(_Symbol,OP_SELL,Lot,Bid,sl,sl,tp,NULL,MagicNumber,0,clrRed);}but need toif(OrderBuy<1&& rsi>Urov_70 && rsi1<Urov_70){tiket=OrderSend(_Symbol,OP_BUY,Lot,Ask,slippage,slBuy,tpBuy,NULL,MagicNumber,0,clrBlue);}if(OrderSell<1&& rsi<Urov_30 && rsi1>Urov_30){tiket=OrderSend(_Symbol,OP_SELL,Lot,Bid,slippage,slSell,tpSell,NULL,MagicNumber,0,clrRed);}At every tick opens (double tp,sl,OrderBuy=0,OrderSell=0;double slSell,slBuy,tpSell,tpBuy; int tiket;//+------------------------------------------------------------------+//| Expert initialization function |//+------------------------------------------------------------------+int OnInit() { return(INIT_SUCCEEDED); }//+------------------------------------------------------------------+//| Expert deinitialization function |//+------------------------------------------------------------------+void OnDeinit(const int reason) { }//+------------------------------------------------------------------+//| Expert tick function |//+------------------------------------------------------------------+void OnTick() { for(int i=0; i<OrdersTotal(); i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) if(OrderSymbol()==_Symbol && OrderMagicNumber()==MagicNumber) { if(OrderType()==OP_BUY){} if(OrderType()==OP_SELL){} } } double rsi=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,0); double rsi1=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,1);//+------------------------------------------------------------------+ double StopLossLevel; double TakeProfitLevel; if(StopLoss>0) StopLossLevel=Bid-StopLoss*Point; else StopLossLevel=0.0; if(TakeProfit>0) TakeProfitLevel=Ask+TakeProfit*Point; else TakeProfitLevel=0.0; tpBuy=NormalizeDouble(Ask+TakeProfit*_Point,_Digits); slBuy=NormalizeDouble(Bid-StopLoss*_Point,_Digits); tpSell=NormalizeDouble(Bid-TakeProfit*_Point,_Digits); slSell=NormalizeDouble(Ask+StopLoss*_Point,_Digits);///--- if(OrderBuy<1 && rsi>Urov_70 && rsi1<Urov_70) { tiket=OrderSend(_Symbol,OP_BUY,Lot,Ask,slippage,slBuy,tpBuy,NULL,MagicNumber,0,clrBlue); } if(OrderSell<1 && rsi<Urov_30 && rsi1>Urov_30) { tiket=OrderSend(_Symbol,OP_SELL,Lot,Bid,slippage,slSell,tpSell,NULL,MagicNumber,0,clrRed); } }//+------------------------------------------------------------------+ Why it doesn't work [Archive!] Any rookie question, PROBLEM [Deleted] 2017.01.08 21:09 #604 Artyom Trishkin: What do you want with this code anyway?What, and what didn't work there?What's wrong with the code?You need it not to open on every tick. Artyom Trishkin 2017.01.08 21:13 #605 Ibragim Dzhanaev: What's wrong with the code ?That's not how it works. Why search the position loop if it does nothing and returns nothing as a result?Why do you check variables with zero values for less than one and expect it not to open on every tick?There's a lot of nonsense to be honest... Is MT5 strategy tester need help with coding Errors, bugs, questions Mickey Moose 2017.01.08 21:14 #606 i have the same problem, in the tester it opens on every tick though it should notI put a crutch for the minimum number of orders to work but it is a patch, nothing more Any rookie question, so Machine learning in trading: MT4 Broker - Units Artyom Trishkin 2017.01.08 21:16 #607 trader781: i have the same problem, in the tester it opens on every tick though it should notI put a crutch for the minimum number of orders to work but it is a patch, nothing more If you correctly count the number of open positions, then you don't need any crutches. [Deleted] 2017.01.08 21:18 #608 Artyom Trishkin: It's all wrong. Why search the position loop if it does nothing and returns nothing as a result?Why do you check variables with zero values for less than one and expect it not to open on every tick?And there's a lot of nonsense to be honest...Fix it the right way. If I had, I would have. Mickey Moose 2017.01.08 21:20 #609 Artyom Trishkin: If you correctly count the number of open positions, you don't need any crutches.They should not be restricted in any way at allIn short, the condition is as followsvoid OnTick() { if(OrdersTotal()==0) //+-------------если количество ордеров равно 0 { if((MathAbs(ma2-ma4)>100*_Point) && (MathAbs(Bid-ma3)>100*Point()) && (ma31>ma32>ma33)) //+-----покупка по 6+50 { ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,50,0,0,"",Magic,0,clrAzure);//+------отправка 1 ордера } if((Bid+1000*Point)>ma3 && (Bid>ma1) && (Bid>ma2))//+-------------условие продажи { ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,50,0,0,"",Magic,0,clrAzure);//+-----отправка 1 ордера } if(ticket==0) { return; } } //+---------------------------------------------------------если уже есть if(FindLastOType()==OP_BUY) { if(Ask<=FindLastOrderOpenPrice()-Step*Point())//+------------если ордер в минус { ticket=OrderSend(Symbol(),OP_BUY,(FindLastLot()*Martin),Ask,50,0,0,"",Magic,0,clrAzure); } else if(Ask>=FindLastOrderOpenPrice()+Step*Point())//+------------если ордер в плюс { ticket=OrderSend(Symbol(),OP_BUY,(FindLastLot()*Martin),Ask,50,0,0,"",Magic,0,clrAzure); } } if(FindLastOType()==OP_SELL) { if(Bid>=FindLastOrderOpenPrice()+Step*Point())//+------------если ордер в минус { ticket=OrderSend(Symbol(),OP_SELL,(FindLastLot()*Martin),Bid,50,0,0,"",Magic,0,clrLightGray); } else if(Bid<=FindLastOrderOpenPrice()-Step*Point()) //+------------если ордер в плюс { ticket=OrderSend(Symbol(),OP_SELL,(FindLastLot()*Martin),Bid,50,0,0,"",Magic,0,clrLightGray); } } Trailingall(); } I need not to ignore the open step, which is 200 five or three digits. Errors, bugs, questions Linear Weighted MA CrossOver [WARNING CLOSED!] Any newbie [Deleted] 2017.01.08 21:25 #610 Did this, now it doesn't open on every tick, but lets signals in...double tp,sl,OrderBuy=0,OrderSell=0;double slSell,slBuy,tpSell,tpBuy,TotalBiu,TotalSell; int tiket;//+------------------------------------------------------------------+//| Expert initialization function |//+------------------------------------------------------------------+int OnInit() { return(INIT_SUCCEEDED); }//+------------------------------------------------------------------+//| Expert deinitialization function |//+------------------------------------------------------------------+void OnDeinit(const int reason) { }//+------------------------------------------------------------------+//| Expert tick function |//+------------------------------------------------------------------+void OnTick() { for(int i=OrdersTotal()-1; i>=0; i--) //Цикл по всем ордерам { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) //Выбрали ордер { if(OrderType()==OP_BUY) { TotalBiu++; //Кол. покупок } if(OrderType()==OP_SELL) { TotalSell++; //Кол. продаж } } } double rsi=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,0); double rsi1=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,1);//+------------------------------------------------------------------+ double StopLossLevel; double TakeProfitLevel; if(StopLoss>0) StopLossLevel=Bid-StopLoss*Point; else StopLossLevel=0.0; if(TakeProfit>0) TakeProfitLevel=Ask+TakeProfit*Point; else TakeProfitLevel=0.0; tpBuy=NormalizeDouble(Ask+TakeProfit*_Point,_Digits); slBuy=NormalizeDouble(Bid-StopLoss*_Point,_Digits); tpSell=NormalizeDouble(Bid-TakeProfit*_Point,_Digits); slSell=NormalizeDouble(Ask+StopLoss*_Point,_Digits);///--- if(TotalBiu==0) if(OrderBuy<1 && rsi>Urov_70 && rsi1<Urov_70) { tiket=OrderSend(_Symbol,OP_BUY,Lot,Ask,slippage,slBuy,tpBuy,NULL,MagicNumber,0,clrBlue); } if(TotalSell==0) if(OrderSell<1 && rsi<Urov_30 && rsi1>Urov_30) { tiket=OrderSend(_Symbol,OP_SELL,Lot,Bid,slippage,slSell,tpSell,NULL,MagicNumber,0,clrRed); } }//+------------------------------------------------------------------+ Why it doesn't work PROBLEM Errors, bugs, questions 1...545556575859606162636465666768...1965 New comment
if(OrderBuy<1&& rsi>Urov_70 && rsi1<Urov_70)
{
tiket=OrderSend(_Symbol,OP_BUY,Lot,Ask,slippage,sl,tp,NULL,MagicNumber,0,clrBlue);
}
if(OrderSell<1&& rsi<Urov_30 && rsi1>Urov_30)
{
tiket=OrderSend(_Symbol,OP_SELL,Lot,Bid,slippage,sl,tp,NULL,MagicNumber,0,clrRed);
}
but it needs
if(OrderBuy<1&& rsi>Urov_70 && rsi1<Urov_70)
{
tiket=OrderSend(_Symbol,OP_BUY,Lot,Ask,slippage,slBuy,tpBuy,NULL,MagicNumber,0,clrBlue);
}
if(OrderSell<1&& rsi<Urov_30 && rsi1>Urov_30)
{
tiket=OrderSend(_Symbol,OP_SELL,Lot,Bid,slippage,slSell,tpSell,NULL,MagicNumber,0,clrRed);
}
Didn't help (
double slSell,slBuy,tpSell,tpBuy;
int tiket;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
for(int i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
if(OrderSymbol()==_Symbol && OrderMagicNumber()==MagicNumber)
{
if(OrderType()==OP_BUY){}
if(OrderType()==OP_SELL){}
}
}
double rsi=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,0);
double rsi1=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,1);
//+------------------------------------------------------------------+
double StopLossLevel;
double TakeProfitLevel;
if(StopLoss>0) StopLossLevel=Bid-StopLoss*Point; else StopLossLevel=0.0;
if(TakeProfit>0) TakeProfitLevel=Ask+TakeProfit*Point; else TakeProfitLevel=0.0;
tpBuy=NormalizeDouble(Ask+TakeProfit*_Point,_Digits);
slBuy=NormalizeDouble(Bid-StopLoss*_Point,_Digits);
tpSell=NormalizeDouble(Bid-TakeProfit*_Point,_Digits);
slSell=NormalizeDouble(Ask+StopLoss*_Point,_Digits);
///---
if(OrderBuy<1 && rsi>Urov_70 && rsi1<Urov_70)
{
tiket=OrderSend(_Symbol,OP_BUY,Lot,Ask,slippage,sl,tp,NULL,MagicNumber,0,clrBlue);
}
if(OrderSell<1 && rsi<Urov_30 && rsi1>Urov_30)
{
tiket=OrderSend(_Symbol,OP_SELL,Lot,Bid,slippage,sl,tp,NULL,MagicNumber,0,clrRed);
}
}
//+------------------------------------------------------------------+
What do you even want with a code like that?
What, and what is it that didn't work?
if(OrderBuy<1&& rsi>Urov_70 && rsi1<Urov_70)
{
tiket=OrderSend(_Symbol,OP_BUY,Lot,Ask,sl,sl,tp,NULL,MagicNumber,0,clrBlue)
}
if(OrderSell<1&& rsi<Urov_30 && rsi1>Urov_30)
{
tiket=OrderSend(_Symbol,OP_SELL,Lot,Bid,sl,sl,tp,NULL,MagicNumber,0,clrRed);
}
but need to
if(OrderBuy<1&& rsi>Urov_70 && rsi1<Urov_70)
{
tiket=OrderSend(_Symbol,OP_BUY,Lot,Ask,slippage,slBuy,tpBuy,NULL,MagicNumber,0,clrBlue);
}
if(OrderSell<1&& rsi<Urov_30 && rsi1>Urov_30)
{
tiket=OrderSend(_Symbol,OP_SELL,Lot,Bid,slippage,slSell,tpSell,NULL,MagicNumber,0,clrRed);
}
At every tick opens (
double slSell,slBuy,tpSell,tpBuy;
int tiket;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
for(int i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
if(OrderSymbol()==_Symbol && OrderMagicNumber()==MagicNumber)
{
if(OrderType()==OP_BUY){}
if(OrderType()==OP_SELL){}
}
}
double rsi=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,0);
double rsi1=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,1);
//+------------------------------------------------------------------+
double StopLossLevel;
double TakeProfitLevel;
if(StopLoss>0) StopLossLevel=Bid-StopLoss*Point; else StopLossLevel=0.0;
if(TakeProfit>0) TakeProfitLevel=Ask+TakeProfit*Point; else TakeProfitLevel=0.0;
tpBuy=NormalizeDouble(Ask+TakeProfit*_Point,_Digits);
slBuy=NormalizeDouble(Bid-StopLoss*_Point,_Digits);
tpSell=NormalizeDouble(Bid-TakeProfit*_Point,_Digits);
slSell=NormalizeDouble(Ask+StopLoss*_Point,_Digits);
///---
if(OrderBuy<1 && rsi>Urov_70 && rsi1<Urov_70)
{
tiket=OrderSend(_Symbol,OP_BUY,Lot,Ask,slippage,slBuy,tpBuy,NULL,MagicNumber,0,clrBlue);
}
if(OrderSell<1 && rsi<Urov_30 && rsi1>Urov_30)
{
tiket=OrderSend(_Symbol,OP_SELL,Lot,Bid,slippage,slSell,tpSell,NULL,MagicNumber,0,clrRed);
}
}
//+------------------------------------------------------------------+
What do you want with this code anyway?
What, and what didn't work there?
What's wrong with the code?
You need it not to open on every tick.
What's wrong with the code ?
That's not how it works.
Why search the position loop if it does nothing and returns nothing as a result?
Why do you check variables with zero values for less than one and expect it not to open on every tick?
There's a lot of nonsense to be honest...
i have the same problem, in the tester it opens on every tick though it should not
I put a crutch for the minimum number of orders to work but it is a patch, nothing more
i have the same problem, in the tester it opens on every tick though it should not
I put a crutch for the minimum number of orders to work but it is a patch, nothing more
It's all wrong.
Why search the position loop if it does nothing and returns nothing as a result?
Why do you check variables with zero values for less than one and expect it not to open on every tick?
And there's a lot of nonsense to be honest...
Fix it the right way.
If I had, I would have.
If you correctly count the number of open positions, you don't need any crutches.
They should not be restricted in any way at all
In short, the condition is as follows
void OnTick()
{
if(OrdersTotal()==0) //+-------------если количество ордеров равно 0{
if((MathAbs(ma2-ma4)>100*_Point)
&& (MathAbs(Bid-ma3)>100*Point())
&& (ma31>ma32>ma33)) //+-----покупка по 6+50
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,50,0,0,"",Magic,0,clrAzure);//+------отправка 1 ордера
}
if((Bid+1000*Point)>ma3 && (Bid>ma1) && (Bid>ma2))//+-------------условие продажи
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,50,0,0,"",Magic,0,clrAzure);//+-----отправка 1 ордера
}
if(ticket==0)
{
return;
}
}
//+---------------------------------------------------------если уже есть
if(FindLastOType()==OP_BUY)
{
if(Ask<=FindLastOrderOpenPrice()-Step*Point())//+------------если ордер в минус
{
ticket=OrderSend(Symbol(),OP_BUY,(FindLastLot()*Martin),Ask,50,0,0,"",Magic,0,clrAzure);
}
else
if(Ask>=FindLastOrderOpenPrice()+Step*Point())//+------------если ордер в плюс
{
ticket=OrderSend(Symbol(),OP_BUY,(FindLastLot()*Martin),Ask,50,0,0,"",Magic,0,clrAzure);
}
}
if(FindLastOType()==OP_SELL)
{
if(Bid>=FindLastOrderOpenPrice()+Step*Point())//+------------если ордер в минус
{
ticket=OrderSend(Symbol(),OP_SELL,(FindLastLot()*Martin),Bid,50,0,0,"",Magic,0,clrLightGray);
}
else
if(Bid<=FindLastOrderOpenPrice()-Step*Point()) //+------------если ордер в плюс
{
ticket=OrderSend(Symbol(),OP_SELL,(FindLastLot()*Martin),Bid,50,0,0,"",Magic,0,clrLightGray);
}
}
Trailingall();
}
Did this, now it doesn't open on every tick, but lets signals in...
double slSell,slBuy,tpSell,tpBuy,TotalBiu,TotalSell;
int tiket;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
for(int i=OrdersTotal()-1; i>=0; i--) //Цикл по всем ордерам
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) //Выбрали ордер
{
if(OrderType()==OP_BUY)
{
TotalBiu++; //Кол. покупок
}
if(OrderType()==OP_SELL)
{
TotalSell++; //Кол. продаж
}
}
}
double rsi=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,0);
double rsi1=iRSI(_Symbol,0,RSIperiod,PRICE_CLOSE,1);
//+------------------------------------------------------------------+
double StopLossLevel;
double TakeProfitLevel;
if(StopLoss>0) StopLossLevel=Bid-StopLoss*Point; else StopLossLevel=0.0;
if(TakeProfit>0) TakeProfitLevel=Ask+TakeProfit*Point; else TakeProfitLevel=0.0;
tpBuy=NormalizeDouble(Ask+TakeProfit*_Point,_Digits);
slBuy=NormalizeDouble(Bid-StopLoss*_Point,_Digits);
tpSell=NormalizeDouble(Bid-TakeProfit*_Point,_Digits);
slSell=NormalizeDouble(Ask+StopLoss*_Point,_Digits);
///---
if(TotalBiu==0)
if(OrderBuy<1 && rsi>Urov_70 && rsi1<Urov_70)
{
tiket=OrderSend(_Symbol,OP_BUY,Lot,Ask,slippage,slBuy,tpBuy,NULL,MagicNumber,0,clrBlue);
}
if(TotalSell==0)
if(OrderSell<1 && rsi<Urov_30 && rsi1>Urov_30)
{
tiket=OrderSend(_Symbol,OP_SELL,Lot,Bid,slippage,slSell,tpSell,NULL,MagicNumber,0,clrRed);
}
}
//+------------------------------------------------------------------+