how to run script

 

I know, im not a coder. But i need a help still.

The code shows I want to add script wich is able to close all trades at specific time, but I'v got

this message:

'start' - function already defined and has a body


thanks a lot

#property copyright "Copyright © 2012, ."
#property show_inputs

#include <stdlib.mqh>
#include <WinUser32.mqh>
#include "scripts\Close all by time.mq4"

extern double Lots=1;

extern double Elevation    = 300;
extern double stoploss     = 300;
extern double takeprofit   = 1200;

extern string TradeSettings="hours 0-23, minutes 0-59, seconds 0-59";
extern int  TradeHour=     0;
extern int  TradeMinutes=  0;
extern int  TradeSeconds=  0;

int start()
  {
  if ((TradeHour==Hour())&&(TradeMinutes==Minute())&&(TradeSeconds==Seconds()))  Executor();
  
}

 int Executor()
 {

  //Set1
  OrderSend(Symbol(),OP_BUY,Lots,Ask,50,Bid-stoploss*Point,Bid+takeprofit*Point,"SEMI-AUTO",0,0,CLR_NONE);
    
}
 
FilipZ:

I know, im not a coder. But i need a help still.

The code shows I want to add script wich is able to close all trades at specific time, but I'v got

this message:

'start' - function already defined and has a body

You included this . . .

#include "scripts\Close all by time.mq4"

. . . does it have it's own start() function ? and why have you Included it ?

 
RaptorUK:

You included this . . .

. . . does it have it's own start() function ? and why have you Included it ?


Yes, there is strart function

I did include this because I want close all function at specific time without change of EA, just as a simple add.

How wrong I have been :-)

My mind was combine scripts and EAs like modules is more easy way to get final result for me. Coz im coding learn resistible.



 
................   
return(0);
   {
  if ((TradeHour==Hour())&&(TradeMinutes==Minute())&&(TradeSeconds==Seconds()))  Executor();
  
}

 int Executor()
 {

  //Set1
  OrderSend(Symbol(),OP_BUY,Lots,Ask,50,Bid-stoploss*Point,Bid+takeprofit*Point,"SEMI-AUTO",0,0,CLR_NONE);

  
    
  }
//+------------------------------------------------------------------+

I did try to combine them, I have add trade function in to "close all" EA at the end.

return (0); is end of original code than continue with trade function

returns: '(' - function definition unexpected (in red line)

 
FilipZ:

I did try to combine them, I have add trade function in to "close all" EA at the end.

return (0); is end of original code than continue with trade function

returns: '(' - function definition unexpected (in red line)


What function does this code belong to ?

{
  if ((TradeHour==Hour())&&(TradeMinutes==Minute())&&(TradeSeconds==Seconds()))  Executor();
  
}
 
RaptorUK:

What function does this code belong to ?


it enables to open trade at specific time

I have defined variables (or something like that) on beginning

it works fine in stand alone EA

extern string TradeSettings="hours 0-23, minutes 0-59, seconds 0-59";
extern int  TradeHour=     0;
extern int  TradeMinutes=  0;
extern int  TradeSeconds=  0;
 

nice :-)

sry, I have found that all does not work

function is executed on each tick, m'I right?

so if I have

#property copyright "FilipZ"
#property link      ""

#include <stdlib.mqh>
#include <WinUser32.mqh>

extern double Lots=1;

extern double Elevation    = 600;
extern double stoploss     = 600;
extern double takeprofit   = 1300;

extern string TradeSettings="Mt4 time(min-max): hours 0-23, minutes 0-59, seconds 0-59";
extern int  TradeHour=     0;
extern int  TradeMinutes=  0;
extern int  TradeSeconds=  0;

int start()
  {
  if ((TradeHour==Hour())&&(TradeMinutes==Minute())&&(TradeSeconds==Seconds()))  Executor();
  
}

 int Executor()
 {

  OrderSend(Symbol(),OP_BUY,Lots,Ask,50,Bid-Elevation*Point,Bid+Elevation*Point,"SEMI-AUTO",0,0,CLR_NONE);

return(0);
}

it opens somtimes more than one trade at a same time, reason should be that function does not know when to stop or if all is done do not run again

I have no idea, it worked fine with more than 5 orders, but single does not work

oh God, I'm back on start

 
FilipZ:

nice :-)

sry, I have found that all does not work

1. function is executed on each tick, m'I right?

so if I have

it opens somtimes more than one trade at a same time, reason should be that function does not know when to stop or if all is done do not run again

I have no idea, it worked fine with more than 5 orders, but single does not work

oh God, I'm back on start

1. in an EA the start() function is called for each new tick received, yes. For a script start() is executed only once . . .
 

I have lil bit upgraded my EA, but I think Im still on beginning or where

I have nice working EA combined from parts I have found here in others codes. Now its ok, but I need to step forward, so my tasks are:

1. add sleep for 17 sec. between each trade

I have found that function sleep is not here to sleep EA (so why is there)

but i think its ok for me, see examle

if=done than
tick 1
execution order
than sleep 17 sec
than execution order on next upcoming tick
than sleep 17 sec
than execution order on next upcoming tick
than sleep 17 sec
than execution order on next upcoming tick


i wish it should works like this

2. solve CloseAllTrades script use


... maybe next century


#property copyright "Copyright Me voe"
#property link      ""

#include <stdlib.mqh>
#include <WinUser32.mqh>
//#include "scripts\CloseAllTrades.mq4"

#define MAGIC  777
#define IDENT  "SHG"

extern double  lots           = 1;
extern double  stop_loss      = 400;
extern double  take_profit    = 900;

extern string TradeHours="Set a time to 0-23 hours, 0-59 minutes";
extern int  TradeHour=10;
extern int  TradeMinutes=0;


extern string CloseHours="Set a time to 0-23 hours, 0-59 minutes";
extern int  TradeHour2=18;
extern int  TradeMinutes2=0;
 
int            last_bar       = 0;
 
int start()

{
   if (last_bar == Bars) return(0);
   last_bar = Bars;
   
   
   if (OrdersTotal() == 0)
   
   if ((TradeHour==Hour())&&(TradeMinutes==Minute()))
   
        {
        OrderSend(Symbol(), OP_BUY, lots ,Ask, 3, Ask - stop_loss * Point, Ask + take_profit * Point, IDENT, MAGIC, 0, Blue);
        Sleep (17000);
        
        OrderSend(Symbol(), OP_BUY, lots ,Ask, 3, Ask - stop_loss * Point, Ask + take_profit * Point, IDENT, MAGIC, 0, Blue);
        Sleep (17000);
        
        OrderSend(Symbol(), OP_BUY, lots ,Ask, 3, Ask - stop_loss * Point, Ask + take_profit * Point, IDENT, MAGIC, 0, Blue);
        Sleep (17000);
        
        OrderSend(Symbol(), OP_BUY, lots ,Ask, 3, Ask - stop_loss * Point, Ask + take_profit * Point, IDENT, MAGIC, 0, Blue);
        } 

   return(0);

//close all trades at specified time

// problem - start function already defined and has a body

}
 
FilipZ:

I have lil bit upgraded my EA, but I think Im still on beginning or where

I have nice working EA combined from parts I have found here in others codes. Now its ok, but I need to step forward, so my tasks are:

Do yourself a big favour,  read some recent posts and read this:  What are Function return values ? How do I use them ?

After you have waited 17 seconds your Ask price will probably be out of date so your OrderSend() may fail.  Also doing this will not be correctly simulated in the Strategy Tester,  don't use Sleep()  check TimeCurrent() instead. 

Reason: