Download MetaTrader 5

Open terminal.exe with settings.ini via Windows Scheduling

To add comments, please log in or register
David Francis
86
David Francis  

We want to run a script overnight and I have got the terminal.exe to run via a schedule to open the relevant chart and then run the script.  This script collates the require variables, but cannot place the orders.  It reports an Uninit 0 error. If I run the script manually, it works normally.  And one of ten scheduled start has run the script and opened orders.

 

What am I missing here? 

 

This is the settings files with user details amended:

; common settings
Profile=test 3
MarketWatch=set2.set
Login=9999999
Password=xxxxxx
Server=FXCM-GBPDemo01
AutoConfiguration=false
EnableDDE=true
EnableNews=false
Proxy Server Settings

; open chart and run expert and/or script
Symbol=USDJPY
Period=M30
Script=Dev/Gabi_Range_Trader_London_Session 

 

This is a sample test script it tries to run:

 

void OnStart()
  {
//---


//---Display Values of candles


//--- Candle Ranges 7 candles hourly
   double Low_Range = Low[iLowest(NULL,PERIOD_M30,MODE_LOW,8,1)];
   double High_Range = High[iHighest(NULL,PERIOD_M30,MODE_HIGH,8,1)];

   Print ("Lowest value from previous 8 candles : ",Low_Range);
   Print ("Highest value from previous 8 candles : ",High_Range); 
  
   double TakeProfitBuy = High_Range + ((High_Range - Low_Range)*1.5);
   double TakeProfitSell = Low_Range - ((High_Range - Low_Range)*1.5);

//--- Place Buy Trade
  int ticket_buy = OrderSend(Symbol(),OP_BUYSTOP,1,High_Range,3,Low_Range,TakeProfitBuy,"SAS-RANGE BOJ");
 
  int ticket_buy2 = OrderSend(Symbol(),OP_BUYLIMIT,1,High_Range,3,Low_Range,TakeProfitBuy,"SAS-RANGE BOJ");
 
  
//--- Place Sell Trade

   int ticket_sell = OrderSend(Symbol(),OP_SELLSTOP,1,Low_Range,3,High_Range,TakeProfitSell,"SAS-RANGE BOJ");

   int ticket_sell2 = OrderSend(Symbol(),OP_SELLLIMIT,1,Low_Range,3,High_Range,TakeProfitSell,"SAS-RANGE BOJ");
  
   } 

peter.MT4Web
157
peter.MT4Web  

I think the script will be started before the terminal itself has finished all its initialisation.

You have to wait a bit, before accessing price data.

And check your return-codes.

To add comments, please log in or register