Hello All..

 

Hello all.. My name is kevin and I'm very new to programing... infact, I have no experience it writing code and eager to learn the process and the language. I'm looking for help in creating a good e.a. Any takers?

 
of course, here we go
 

Begin to learn how a simple program works

book https://book.mql4.com// and code base for example https://www.mql5.com/en/code/9817

//+------------------------------------------------------------------+
//| Easiest ever - daytrade robot                                    |
//+------------------------------------------------------------------+

extern double lot = 1;
extern double marketclosehour = 20; // on friday

int start()
  {
     double c1 = iClose(NULL,1440,1);
     double o1 = iOpen(NULL,1440,1);
     {
     if (c1>o1 && OrdersTotal()<1 && Hour()<1)
     OrderSend(Symbol(),OP_BUY,lot,Ask,0,0,0,"Easiest ever",0,0);

     if (c1<o1 && OrdersTotal()<1 && Hour()<1)
     OrderSend(Symbol(),OP_SELL,lot,Bid,0,0,0,"Easiest ever",0,0);
       {
          for (int i=0; i<OrdersTotal(); i++)
         {                                               
            if (OrderSelect(i,SELECT_BY_POS,MODE_TIME)==true)
             if (OrderType()==OP_BUY && Hour()>(marketclosehour-1))
             OrderClose(OrderTicket(),OrderLots(),Bid,0,CLR_NONE);
        
            if (OrderType()==OP_SELL && Hour()>(marketclosehour-1))
            OrderClose(OrderTicket(),OrderLots(),Ask,0,CLR_NONE);
         }   
       }
     }
   return(0);

and trie if you can improve it.....

Learning is something you do yourself the best....

 
deVries:

Learning is something you do yourself the best....

That code was formatted horribly. I have re-formatted it for good luck.

//+------------------------------------------------------------------+
//| Easiest ever - daytrade robot                                    |
//+------------------------------------------------------------------+

extern double lot = 0.1;
extern double marketclosehour = 20; // on friday

int start(){
   double c1 = iClose(NULL,1440,1);
   double o1 = iOpen(NULL,1440,1);

   if( c1>o1 && OrdersTotal()<1 && Hour()<1 )
     OrderSend(Symbol(),OP_BUY,lot,Ask,0,0,0,"Easiest ever",0,0);

   if( c1<o1 && OrdersTotal()<1 && Hour()<1 )
     OrderSend(Symbol(),OP_SELL,lot,Bid,0,0,0,"Easiest ever",0,0);

   for( int i=0; i<OrdersTotal(); i++ ){                                               
      if( OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true ){
         if( OrderType()==OP_BUY && Hour()>(marketclosehour-1) )
            OrderClose(OrderTicket(),OrderLots(),Bid,0,CLR_NONE);

         if( OrderType()==OP_SELL && Hour()>(marketclosehour-1) )
            OrderClose(OrderTicket(),OrderLots(),Ask,0,CLR_NONE);
      }   
   }
   
   return(0);
}

In the process I spotted the dodgy parameter in the OrderSelect() function. There is no such parameter as MODE_TIME for that function!

This code simulates as 0.91 PF on EURUSD for 2011 (ie it is a loser).

 
dabbler:

That code was formatted horribly. I have re-formatted it for good luck.

In the process I spotted the dodgy parameter in the OrderSelect() function. There is no such parameter as MODE_TIME for that function!

This code simulates as 0.91 PF on EURUSD for 2011 (ie it is a loser).



I gave this just as an example, there are more things you can improve on such coding.....

On a live account I wouldn't use it....

no magicnumber....

not selecting on symbol

no kind of moneymanagementsystem

If you read the lines and trie to figure out what happens if you have it on a chart you begin to understand some basics about coding

I see this as something you have to understand if you go programming......

Reason: