A little help? - page 2

 
WHRoeder:
  1. Of course not. RTFM. You only get a new tick when you return from start.
  2. RTFM & Tester limitations you can NOT sleep in the tester
  3. What are Function return values ? How do I use them ? - MQL4 forum


thank you for your help, I have removed the while loop and break to the start function on each order execution, removed the IsTesting function (for now) and my OrderSend appears to be working.


Running it now no matter where I have a Print() function nothing is appearing in the journal (or the log book) the initial order opens fine and then nothing - even if i have my print order as the next line in the code?

 
j.w.msb:

thank you for your help, I have removed the while loop and break to the start function on each order execution, removed the IsTesting function (for now) and my OrderSend appears to be working.


Running it now no matter where I have a Print() function nothing is appearing in the journal (or the log book) the initial order opens fine and then nothing - even if i have my print order as the next line in the code?


how does your code look now ??
 
Sorry to be a nightmare at this! I tried finding info on errors in the strategy tester but googles not being helpful :s
//+------------------------------------------------------------------+
//|                                                   SMA scripy.mq4 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
extern int z=1234;
int total;
//---
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int init()
  {
//---- 
   int i;
   total=0;
   if (OrdersTotal()!=0)
      {
      for (i=OrdersTotal()-1; i>=0; i--)                                                     
         {
         if (OrderSelect(i,SELECT_BY_POS))
            {
            if ((OrderSymbol()==Symbol())&&(OrderMagicNumber()==z))
               {
               if ((OrderType()==OP_BUY)&&(iMA(Symbol(),0,6,0,MODE_SMA,PRICE_CLOSE,0)<iMA(Symbol(),0,21,0,MODE_SMA,PRICE_CLOSE,0)))
                  { 
                  OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,Green);                  
               }
               if ((OrderType()==OP_SELL)&&(iMA(Symbol(),0,6,0,MODE_SMA,PRICE_CLOSE,0)>iMA(Symbol(),0,21,0,MODE_SMA,PRICE_CLOSE,0)))
                  {
                  OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,Green);                  
               }
               else 
                  {
                  total++;                                                                 
               }
            }
         }
      }
   }
//----
   return;
}
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
//----
   return(0);
}
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int start()
   {
//----
   int i,L;
   if (AccountBalance()>50)                                                                                     
   {
//-----
double SMA6=iMA(Symbol(),0,6,0,MODE_SMA,PRICE_CLOSE,0);
double SMA21=iMA(Symbol(),0,21,0,MODE_SMA,PRICE_CLOSE,0);
double RSI70=iRSI(Symbol(),PERIOD_D1,14,PRICE_CLOSE,0)<70;
double RSI30=iRSI(Symbol(),PERIOD_D1,14,PRICE_CLOSE,0)>30;                                                                                                            
//----
   if (total==0)
      {
      if ((RSI70)&&(SMA6>SMA21))
         {                                                                                                                       
         OrderSend(Symbol(),OP_BUY,0.1,Ask,0,0,0,"",z,0,Red); 
         Print("WE ARE HERE");
         total+=1;                                                       
      }
      if ((RSI30)&&(SMA6<SMA21))
         {
         OrderSend(Symbol(),OP_SELL,0.1,Bid,0,0,0,"",z,0,Blue);
         total+=1;
      }  
   }
//---
   if (total!=0)
      {
      L=0;
      for (i=OrdersTotal()-1; i>=0; i--)                                                    
         {
         if (OrderSelect(i,SELECT_BY_POS))
            {
            if ((OrderSymbol()==Symbol())&&(OrderMagicNumber()==z))
               {
               if ((OrderType()==OP_BUY)&&(SMA6<SMA21))
                  { 
                  OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,Green);
                     total+=-1;
                     break;
               }
               if ((OrderType()==OP_SELL)&&(SMA6>SMA21))
                  {
                  OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,Green);                 
                     total+=-1;
                     break;
               }
               else 
                  {
                  L++;                                                                  
               }
            }
            total=L;
         }
      }
   }
//----
}
//----
return;
}
//-------------------------------------------
 

double, int, string, bool, datetime, color, ........ what do i have to use ???....

//-----
double SMA6=iMA(Symbol(),0,6,0,MODE_SMA,PRICE_CLOSE,0);
Print("SMA6=  ",SMA6);
double SMA21=iMA(Symbol(),0,21,0,MODE_SMA,PRICE_CLOSE,0);
Print("SMA21=  ",SMA21);
double RSI70=iRSI(Symbol(),PERIOD_D1,14,PRICE_CLOSE,0)<70;
Print("RSI70=  ",RSI70);
double RSI30=iRSI(Symbol(),PERIOD_D1,14,PRICE_CLOSE,0)>30;
Print("RSI30=  ",RSI30);                                                                                                            
//----

Are they double ???

         OrderSend(Symbol(),OP_BUY,0.1,Ask,0,0,0,"",z,0,Red); 
         Print("WE ARE HERE");

SEEEEEE What are Function return values ? How do I use them ? - MQL4 forum

big explanation

Where a function returns an int, such as OrderSend(), we can use code such as this to check that the function worked and report an error to the logs if it did not work . . .

int TicketNumber;

TicketNumber = OrderSend( . . . . . . . . );

**(*******************)
   {
   Print(******************);
   }
else
   {
   Print(************************);
   }

. See the link you have given by WHRoeder and you find what i have hidden here with stars ......

use it also checking closing the trades

Make something like that inside your code.... in that way when ordersend fails you know what kind and where the error is coming from

.

what happens if orderclose fails.......?????

 

Both RSI and MA's are doubles so the variables need to be as well no?

https://docs.mql4.com/indicators/iRSI && https://docs.mql4.com/indicators/iMA

I coded in the print errors, but nothing is being printed to the journal so I cant work off which errors are occuring? Am I still missing something obvious? Now I am back to opening a sell and then not being able to close...

//+------------------------------------------------------------------+
//|                                                   SMA scripy.mq4 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
extern int z=1234;
int total;
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int init()
  {
//---- 
   int i;
   total=0;
   if (OrdersTotal()!=0)
      {
      for (i=OrdersTotal()-1; i>=0; i--)                                                     
         {
         if (OrderSelect(i,SELECT_BY_POS))
            {
            if ((OrderSymbol()==Symbol())&&(OrderMagicNumber()==z))
               {
               if ((OrderType()==OP_BUY)&&(iMA(Symbol(),0,6,-3,MODE_SMA,PRICE_CLOSE,0)<iMA(Symbol(),0,21,0,MODE_SMA,PRICE_CLOSE,0)))
                  { 
                  OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,Green);                  
               }
               if ((OrderType()==OP_SELL)&&(iMA(Symbol(),0,6,-3,MODE_SMA,PRICE_CLOSE,0)>iMA(Symbol(),0,21,0,MODE_SMA,PRICE_CLOSE,0)))
                  {
                  OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,Green);                  
               }
               else 
                  {
                  total++;                                                                 
               }
            }
         }
      }
   }
//----
   return;
}
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int start()
   {
//----
   int ticket,i,L;
   bool x;
   if (AccountBalance()>50)                                                                                     
   {
//-----
double SMA6=iMA(Symbol(),0,6,-3,MODE_SMA,PRICE_CLOSE,0);
Print("SMA6 is ",SMA6);
double SMA21=iMA(Symbol(),0,21,0,MODE_SMA,PRICE_CLOSE,0);
Print("SMA21 is ",SMA21);
double RSI70=iRSI(Symbol(),PERIOD_D1,14,PRICE_CLOSE,0)<70;
Print("RSI70 is ",RSI70);
double RSI30=iRSI(Symbol(),PERIOD_D1,14,PRICE_CLOSE,0)>30; 
Print("RSI30 is ",RSI30);                                                                                                           
//----
   if (total==0)
      {
      if ((RSI70)&&(SMA6>SMA21))
         {                                                                                                                       
         ticket=OrderSend(Symbol(),OP_BUY,v(AccountBalance()),Ask,0,0,0,"",z,0,Red); 
         total+=1;                                                       
         if (ticket<0)
            {
            Print("OrderSend Failed", GetLastError());
         }
      }
      if ((RSI30)&&(SMA6<SMA21))
         {
         ticket=OrderSend(Symbol(),OP_SELL,v(AccountBalance()),Bid,0,0,0,"",z,0,Blue);
         total+=1;
         if (ticket<0)
            {
            Print("OrderSend Failed", GetLastError());
         }
      }  
   }
//---
   if (total!=0)
      {
      L=0;
      for (i=OrdersTotal()-1; i>=0; i--)                                                    
         {
         if (OrderSelect(i,SELECT_BY_POS))
            {
            if ((OrderSymbol()==Symbol())&&(OrderMagicNumber()==z))
               {
               if ((OrderType()==OP_BUY)&&(SMA6<SMA21))
                  { 
                  x=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,Green);
                     if (x==false)
                        {
                        Print("Error is ", GetLastError());
                     }
                     else total+=-1;
                     break;
               }
               if ((OrderType()==OP_SELL)&&(SMA6>SMA21))
                  {
                  x=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,Green);   
                     if (x==false)
                        {
                        Print("Error is ", GetLastError());
                     }
                     else 
                        {
                        total+=-1;
                     }
                     break;
               }
               else 
                  {
                  L++;                                                                  
               }
            }
            total=L;
         }
      }
   }
//----
}
//----
return;
}
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
//----
   return(0);
}
//-------------------------------------------------------------------+
double v(double k)
{
   double v=((k*0.015)/1000);
   if (v<MarketInfo(Symbol(),MODE_MINLOT))
      {
      v=MarketInfo(Symbol(),MODE_MINLOT);
      return(v);
   }
   else
      {
      return(v);
   }
}
//-------------------------------------------------------------------+
 

duuuhhhh iRSI is double but the comparison outputs 1 - so I replaced RSI30 and RSI70 with just RSI and had a comparison and all works HOORAY! EXCEPT when I change the SMA6 to shift it outputs SMA6=0 always? why?

Thank you all for the help! I hope not to annoy so much next time!

 
j.w.msb:

Both RSI and MA's are doubles so the variables need to be as well no?

https://docs.mql4.com/indicators/iRSI && https://docs.mql4.com/indicators/iMA

I coded in the print errors, but nothing is being printed to the journal so I cant work off which errors are occuring? Am I still missing something obvious? Now I am back to opening a sell and then not being able to close...

place the EA on a chart of a demo account

don't look only in terminal journal ...
look also in terminal experts .....

what do you see there printed

 
deVries:

place the EA on a chart of a demo account

don't look only in terminal journal ...
look also in terminal experts .....

what do you see there printed


Printing and executing now :) thank you for your help - i was wrong definining iRSI<70 as a double (since it was a comparison) and was causing issues. It prints now and works as expected, except, if I change the SMA shift its prints SMA=0?
 
j.w.msb:

Printing and executing now :) thank you for your help - i was wrong definining iRSI<70 as a double (since it was a comparison) and was causing issues. It prints now and works as expected, except, if I change the SMA shift its prints SMA=0?

Place a SMA with same settings to the chart of your EA and see what you have done ...
 
   if (total==0)
      {
      if ((RSI70)&&(SMA6>SMA21))
         {                                                                                                                       
         ticket=OrderSend(Symbol(),OP_BUY,v(AccountBalance()),Ask,0,0,0,"",z,0,Red); 
         total+=1;                                                       
         if (ticket<0)
            {
            Print("OrderSend Failed", GetLastError());
         }
      }

Why do you total += 1;

at this moment i don't know if ordersend succeed

and if it fails i don't see what ordertype it tried to open it could be also a sell trade you tried to open

Reason: