Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1770

 
MakarFX #:

But why you need this array, I still don't understand...

int TradeSignal() 
  {
   int limit, i, sig=-1;
   double Ma_curr, Ma_prev, value;
   limit=MaPeriod*3;
   for(i=limit;i>=0;i--)
     {
      Ma_curr=iMA(_Symbol,_Period,MaPeriod,0,MaMethod,MaPrice,i);
      Ma_prev=iMA(_Symbol,_Period,MaPeriod,0,MaMethod,MaPrice,i+1);
      value=Ma_curr-Ma_prev;
      if(value>0) sig=0;
      if(value<0) sig=1;
     }
   return(sig);
  }

The function will work without it.

 
Mihail Matkovskij #:

But why you need this array, I still don't understand...

The function will work without it.

And there's no need for a loop here

int TradeSignal() 
  {
   int sig=-1;
   double Ma_curr, Ma_prev, value;

   Ma_curr=iMA(_Symbol,_Period,MaPeriod,0,MaMethod,MaPrice,0);
   Ma_prev=iMA(_Symbol,_Period,MaPeriod,0,MaMethod,MaPrice,1);
   value=Ma_curr-Ma_prev;
   if(value>0) sig=0;
   if(value<0) sig=1;

   return(sig);
  }
 
Mihail Matkovskij #:

And there's no need for a loop.

I did, but I wanted to understand why the array didn't work.

and by the way

ArraySize(Buffer,limit);

didn't help (


'ArraySize' - wrong parameters count

corrected without limit

array out of range in '_exp.mq4' (267,17)

 
MakarFX #:


ArrayResize, not ArraySize.

 
Yurij Kozhevnikov #:

ArrayResize, not ArraySize.

array out of range
 
MakarFX #:

I did, but wanted to understand why the array didn't work.

and by the way

didn't help (


'ArraySize' - wrong parameters count

corrected without limit

array out of range in '_exp.mq4' (267,17)


I noticed and corrected immediately afterwards. And you must have copied the uncorrected code.

And if you want to know why the array did not work, etc., see: Operations. See: Array operations .

Любые вопросы новичков по MQL4 и MQL5, помощь и обсуждение по алгоритмам и кодам
Любые вопросы новичков по MQL4 и MQL5, помощь и обсуждение по алгоритмам и кодам
  • 2021.11.28
  • www.mql5.com
В этой ветке я хочу начать свою помощь тем, кто действительно хочет разобраться и научиться программированию на новом MQL4 и желает легко перейти н...
 
Mihail Matkovskij #:


I noticed and corrected immediately afterwards. And you must have copied the uncorrected code.
Thanks, it's working!
 
MakarFX #:
Thank you, it's working!

You're welcome! Completed the message...

 
//+------------------------------------------------------------------+
//| trial by muving.mq4 |
///+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
extern string Moving_Averages1= "Indicator parameters";
extern int MA_Period=13;
extern int MA_Shift=0;
extern int MA_Method=0;

extern int int TakeProfit= 300;
extern int StopLoss= 50;
double ma1,ma2,Lots,SL,TP;

int res;



//+------------------------------------------------------------------+
//| Expert initialisation function |
//+------------------------------------------------------------------+
int OnInit()
{
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+------------------------------------------------------------------+
//| expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(!OllCount()==0)
{
switch(OrderType())
{
case OP_BUY
ma1=iMA(NULL,0,MA_Period,MA_Shift,MA_Method,0,0);
ma2=iMA(NULL,0,MA_Period,MA_Shift,MA_Method,0,1);
if((ma1-ma2)>0)
{
return;
}else
SL=NormalizeDouble(Bid+StopLoss*Point,5);
TP=NormalizeDouble(Bid-TakeProfit*Point,5);
if(OrderClose(OrderTicket(),OrderLots(),Ask,3,Black))
if(OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,",0,0,Red))
return;
case OP_SELL
ma1=iMA(NULL,0,MA_Period,MA_Shift,MA_Method,0,0);
ma2=iMA(NULL,0,MA_Period,MA_Shift,MA_Method,0,1);
if((ma1-ma2)<0)
{
return;
}
else
SL=NormalizeDouble(Ask-StopLoss*Point,5);
TP=NormalizeDouble(Ask+TakeProfit*Point,5);
if(OrderClose(OrderTicket(),OrderLots(),Bid,3,Red))
if(OrderSend(Symbol(),OP_SELL,Lots,Ask,3,0,0,",0,0,Black))
return;
}
}
ma1=iMA(NULL,0,MA_Period,MA_Shift,MA_Method,0,0);
ma2=iMA(NULL,0,MA_Period,MA_Shift,MA_Method,0,1);
if((ma1-ma2)<0)
{
SL=NormalizeDouble(Bid+StopLoss*Point,5);
TP=NormalizeDouble(Bid-TakeProfit*Point,5);
res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,",0,0,Red);
if(res<0)
{
Print("Sell order open error");
}
}
else
SL=NormalizeDouble(Ask-StopLoss*Point,5);
TP=NormalizeDouble(Ask+TakeProfit*Point,5);
if(OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,",0,0,Blue))
return;
}
//+------------------------------------------------------------------+
int OllCount()
{
int count=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
{
count++;
}
}
return(count);
}
//+------------------------------------------------------------------+
//+---/| Copyright 2021, MetaQuotes Software Corp. |
---------------------------------------------------------------+

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

I tried to write my own MA advisor, I have followed all the examples, but it keeps returning errors.

'ma1' - some operator expected trial by muving.mq4 47 21

'=' - ':' colon sign expected mq4 muving trial 47 24

'=' - operand expected muving.mq4 47 24

'ma1' - some operator expected muving.mq4 60 15

'=' - ':' colon sign expected muving.mq4 60 18

'=' - operand expected muving.mq4 60 18


 
Sanjakotik78 #:


Your order logic is wrong from the start. Find a simple EA on MA(e.g. CodeBase) and use it. Or you can modify it to suit your own idea. Regarding your code as a whole, everything is wrong there. Pay more attention to coding. Start with a simple one. Or, like I said, find a ready-made example.

Add code snippets using the special button at the top:


Reason: