|
|||||||
| Register in Forex TSD! | |
|
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time). Click here to register and get more information |
|
![]() |
|
|
LinkBack (1) | Thread Tools | Display Modes |
|
||||
|
not referenced
Hello!
I have added a date-check code found in forum but i get message that the section datestart i excluded from exp-file, what's wrong? /jorgeng //+------------------------------------------------------------------+ //| Moving Average.mq4 | //| Copyright © 2005, MetaQuotes Software Corp. | //| Forex Trading Software: Forex Trading Platform MetaTrader 4 | //+------------------------------------------------------------------+ #define MAGICMA 20050610 extern double Lots = 0.1; extern double MaximumRisk = 0.02; extern double DecreaseFactor = 3; extern double MovingPeriod = 12; extern double MovingShift = 6; int datestart() { string expire_date = "2004.31.06"; //<-- hard coded datetime datetime e_d = StrToTime(expire_date); if (CurTime() >= e_d) { Alert ("The trial version has been expired!"); return(0); } // your normal code! return(0); } //+------------------------------------------------------------------+ //| Calculate open positions | //+------------------------------------------------------------------+ int CalculateCurrentOrders(string symbol) { int buys=0,sells=0; //---- for(int i=0;i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false ) break; if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA) { if(OrderType()==OP_BUY) buys++; if(OrderType()==OP_SELL) sells++; } } //---- return orders volume if(buys>0) return(buys); else return(-sells); } //+------------------------------------------------------------------+ //| Calculate optimal lot size | //+------------------------------------------------------------------+ double LotsOptimized() { double lot=Lots; int orders=HistoryTotal(); // history orders total int losses=0; // number of losses orders without a break //---- select lot size lot=NormalizeDouble(AccountFreeMargin()*MaximumRis k/1000.0,1); //---- calcuulate number of losses orders without a break if(DecreaseFactor>0) { for(int i=orders-1;i>=0;i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==fals e) { Print("Error in history!"); break; } if(OrderSymbol()!=Symbol() || OrderType()>OP_SELL) continue; //---- if(OrderProfit()>0) break; if(OrderProfit()<0) losses++; } if(losses>1) lot=NormalizeDouble(lot-lot*losses/DecreaseFactor,1); } //---- return lot size if(lot<0.1) lot=0.1; return(lot); } //+------------------------------------------------------------------+ //| Check for open order conditions | //+------------------------------------------------------------------+ void CheckForOpen() { double ma; int res; //---- go trading only for first tiks of new bar if(Volume[0]>1) return; //---- get Moving Average ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PR ICE_CLOSE,0); //---- sell conditions if(Open[1]>ma && Close[1]<ma) { res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid ,3,0,0,"",MAGICMA,0,Red); return; } //---- buy conditions if(Open[1]<ma && Close[1]>ma) { res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask, 3,0,0,"",MAGICMA,0,Blue); return; } //---- } //+------------------------------------------------------------------+ //| Check for close order conditions | //+------------------------------------------------------------------+ void CheckForClose() { double ma; //---- go trading only for first tiks of new bar if(Volume[0]>1) return; //---- get Moving Average ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PR ICE_CLOSE,0); //---- for(int i=0;i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false ) break; if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue; //---- check order type if(OrderType()==OP_BUY) { if(Open[1]>ma && Close[1]<ma) OrderClose(OrderTicket(),OrderLots(),Bid,3,White); break; } if(OrderType()==OP_SELL) { if(Open[1]<ma && Close[1]>ma) OrderClose(OrderTicket(),OrderLots(),Ask,3,White); break; } } //---- } //+------------------------------------------------------------------+ //| Start function | //+------------------------------------------------------------------+ void start() { //---- check for history and trading if(Bars<100 || IsTradeAllowed()==false) return; //---- calculate open orders by current symbol if(CalculateCurrentOrders(Symbol())==0) CheckForOpen(); else CheckForClose(); //---- } //+------------------------------------------------------------------+ |
|
||||
|
for instance modify the start function, but instead of calling date_start I would rather include the code in it, because I guess that you want that the EA is not executed if the date has passed the limit and this function date start() returns 0 in both cases.
Furthermore the function CurTime() is not used anymore So remove datestart completely and modify the start function //+------------------------------------------------------------------+ //| Start function | //+------------------------------------------------------------------+ void start() { string expire_date = "2004.31.06"; //<-- hard coded datetime datetime e_d = StrToTime(expire_date); if (TimeCurrent() >= e_d) { Alert ("The trial version has been expired!"); return(0); } //---- check for history and trading if(Bars<100 || IsTradeAllowed()==false) return; //---- calculate open orders by current symbol if(CalculateCurrentOrders(Symbol())==0) CheckForOpen(); else CheckForClose(); //---- } |
|
||||
|
I tried to put this date-code in another ea which has
int init int deinit int start If i put datecheck-code in int init I got the alert-box with trial version expired, but the ea still put in the orders. How do i do to get the ea to stop executing? And how would the code be if placed in int start section? //+------------------------------------------------------------------+ //| Start function | //+------------------------------------------------------------------+ void start() { string expire_date = "2004.31.06"; //<-- hard coded datetime datetime e_d = StrToTime(expire_date); if (TimeCurrent() >= e_d) { Alert ("The trial version has been expired!"); return(0); } |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
LinkBacks (?)
LinkBack to this Thread: http://www.forex-tsd.com/metatrader-programming/9618-not-referenced.html
|
|||
| Posted By | For | Type | Date |
| not referenced - Personal Finance | This thread | Pingback | 09-14-2007 01:41 PM |
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Function not referenced warning ? | matrixebiz | Expert Advisors - Metatrader 4 | 9 | 08-02-2007 08:08 PM |