Comment on chart (low level)
-
Send me the code of the EA with errors.
-
Here's the EA with errors, "desktop test 2" ...
//+------------------------------------------------------------------------------+//
//) ____ _ _ ____ ____ ____ ____ __ __ __ ___ _____ __ __ (//
//) ( )( / )( _ ( _ ( )( )( / ) /\ / )( _ )( / ) (//
//) )) ) ( )() )) / )) )) ) ( /()\ ( (__ )()( ) ( (//
//) (__) (/_)(/()_)()(_)(//_)()()()_)(___)(//_) (//
//) http://fxdreema.com Copyright Â
2012, fxDreema (//
//+------------------------------------------------------------------------------+//
#property copyright ""
#property link "http://fxdreema.com"///////
// Advanced system settings
#define POINT_FORMAT 0.0001 // Relative to EURUSD. 0.0001 to use 4-digits format, 0.00001 to use 5-digits format
#define USE_VIRTUAL_STOPS "no" // Use "yes" or "no"
//--
#define USE_EMERGENCY_STOPS "no" // "yes" to use emergency (hard stops) when virtual stops are in use. "always" to use EMERGENCY_STOPS_ADD as emergency stops when there is no virtual stop.
#define EMERGENCY_STOPS_REL 0 // Use 0 to disable hard stops when virtual stops are enabled. Use a value >=0 to automatically set hard stops with virtual. Example: if 2 is used, then hard stops will be 2 times bigger than virtual ones.
#define EMERGENCY_STOPS_ADD 0 // Add pips to relative size of emergency stops (hard stops)
//--
#define EVENTS_MODE "tick" // Use "period" to listen every EVENTS_CYCLE_PERIOD milliseconds or "tick" to listen only when a new tick is received
#define EVENTS_CYCLE_PERIOD 1 // Time delay in events listener while in "period" mode. The smaller period - the faster events reaction. Use "1" as minimum
#define EVENT_TIMER_PERIOD 60 // Timer event period (in seconds)
//--
#define ENABLE_EVENT_TICK 1 // "Tick" event: 1 - enable, 0 - disable
#define ENABLE_EVENT_TRADE 0 // "Trade" event: 1 - enable, 0 - disable
#define ENABLE_EVENT_TIMER 0 // "Timer" event: 1 - enable, 0 - disable
//--
#define SIMULATE_TICKS 0 // Use this for offline charts - feed the EA with ticks coming from a certain market (SIMULATE_TICKS_MARKET). Options: 1 - enable, 0 - disable
#define SIMULATE_TICKS_MARKET "EURUSD" // When SIMULATE_TICKS is enabled, feed the EA with ticks coming from the chosen market
///////#define detect_broker_digits 0
// Standard global variables
extern string inpstd="-= System =-";
extern int MagicStart=1421; // Magic Start (MagicNumber=MagicStart+Group#)// On-Off switches for blocks
bool tick1=true; // If trade/order exists
bool tick2=true; // Just pass
bool tick3=true; // Just pass
bool tick4=true; // Comment on chart (low level)/////////////////////////////////////////////////////////////////////////////
//+-----------------------------------------------------------------------+//
//| EXPERT INITIALIZATION SECTOR |//
//| Runs only once when expert loads |//
//+-----------------------------------------------------------------------+//
/////////////////////////////////////////////////////////////////////////////int init()
{
int logo_x=230; int logo_y=0;
string name="fxdreema_logo1";
if (ObjectFind(name)==-1) {
ObjectCreate (name, OBJ_LABEL, 0, 0, 0);
ObjectSet (name, OBJPROP_BACK, false);
ObjectSet (name, OBJPROP_XDISTANCE, logo_x-1);
ObjectSet (name, OBJPROP_YDISTANCE, logo_y+1);
ObjectSetText (name, "g", 16, "Webdings", C'0x11,0x11,0x11');
}name="fxdreema_logo2"; if (ObjectFind(name)==-1) { ObjectCreate (name, OBJ_LABEL, 0, 0, 0); ObjectSet (name, OBJPROP_BACK, false); ObjectSet (name, OBJPROP_XDISTANCE, logo_x+20); ObjectSet (name, OBJPROP_YDISTANCE, logo_y+1); ObjectSetText (name, "gggg", 16, "Webdings", White); } name="fxdreema_logo3"; if (ObjectFind(name)==-1) { ObjectCreate (name, OBJ_LABEL, 0, 0, 0); ObjectSet (name, OBJPROP_BACK, false); ObjectSet (name, OBJPROP_XDISTANCE, logo_x); ObjectSet (name, OBJPROP_YDISTANCE, logo_y); ObjectSetText (name, "fx", 18, "Arial", Magenta); } name="fxdreema_logo4"; if (ObjectFind(name)==-1) { ObjectCreate (name, OBJ_LABEL, 0, 0, 0); ObjectSet (name, OBJPROP_BACK, false); ObjectSet (name, OBJPROP_XDISTANCE, logo_x+20); ObjectSet (name, OBJPROP_YDISTANCE, logo_y); ObjectSetText (name, "dreema", 18, "Arial", DimGray); } DrawStatus("Starting..."); ListOfIDsConnectedToMe(""); // calculate only//Comment("Program "+WindowExpertName( ) +" loaded at "+TimeToStr(TimeLocal(),TIME_DATE|TIME_SECONDS));
if (SIMULATE_TICKS==1) {EventsListener(); EventsListener();}
return(0);
}/////////////////////////////////////////////////////////////////////////////
//+-----------------------------------------------------------------------+//
//| EXPERT START (TICK) SECTOR |//
//| Runs at every new tick (begins with "start()" function) |//
//+-----------------------------------------------------------------------+//
/////////////////////////////////////////////////////////////////////////////int start() {static int p=0; if (p!=Period()) {DrawStatus("Working"); p=Period();} EventsListener(); return(0);}
int EventTick()
{ TicksFromStart("update");
tick1();
// Main beginning on the graph
DrawSpreadInfo();
return(0);
}
////////////////////////////////////////////
// Define block 1 (If trade/order exists) //
void tick1(string parent="")
{if (tick1==true) {
//////
// Inputs
string OrdersScope = "all" ; // Group mode <== [group|manual|all]
int OrdersGroup = 0 ; // Group # (empty=Default)
string SymbolScope = "all" ; // Market mode <== [all|symbol]
string SYMBOL = Symbol() ; // Market (empty=Current)
string BuysOrSells = "both" ; // Filter by type <== **
// Inputs
//////LoopedStop(); bool exist=false; for (int pos=OrdersTotal()-1; pos>=0; pos--) { if (OrderSelect(pos,SELECT_BY_POS,MODE_TRADES)) { if (SymbolScope=="all" || attrSymbol()==SYMBOL) { if (OrdersScope=="all" || attrMagicNumber()==MagicStart+OrdersGroup) { if ( (BuysOrSells=="buys" && (attrType()==OP_BUY || attrType()==OP_BUYLIMIT || attrType()==OP_BUYSTOP)) || (BuysOrSells=="sells" && (attrType()==OP_SELL || attrType()==OP_SELLLIMIT || attrType()==OP_SELLSTOP)) || (BuysOrSells=="both") ) { exist=true; break; } } } } } LoopedResume(); if (exist==true) {tick2("1");} else {tick3("1");} }} //////////////////////////////// // Define block 2 (Just pass) // void tick2(string _parent_="") {if (tick2==true) { tick4("2"); }} //////////////////////////////// // Define block 3 (Just pass) // void tick3(string _parent_="") {if (tick3==true) { tick4("3"); }} /////////////////////////////////////////////////// // Define block 4 (Comment on chart (low level)) // void tick4(string _parent_="") {if (tick4==true) { Comment( "Account free margin is ",DoubleToStr(AccountFreeMargin(),2),"\n", "Current time is ",TimeToStr(TimeCurrent()) ); /* Next blocks in chain */ }}/////////////////////////////////////////////////////////////////////////////
//+-----------------------------------------------------------------------+//
//| EXPERT TARDE EVENTS SECTOR |//
//| Runs when the Trade event occurs |//
//+-----------------------------------------------------------------------+//
/////////////////////////////////////////////////////////////////////////////void EventTrade()
{}
/////////////////////////////////////////////////////////////////////////////
//+-----------------------------------------------------------------------+//
//| EXPERT TIMER EVENTS SECTOR |//
//| Runs when the Timer event occurs |//
//+-----------------------------------------------------------------------+//
/////////////////////////////////////////////////////////////////////////////void EventTimer()
{}
/////////////////////////////////////////////////////////////////////////////
//+-----------------------------------------------------------------------+//
//| EXPERT DEINITIALIZATION SECTOR |//
//| Runs only once when expert unloads |//
//+-----------------------------------------------------------------------+//
/////////////////////////////////////////////////////////////////////////////int deinit()
{
DrawStatus("Stopped");
switch(UninitializeReason())
{
case REASON_CHARTCLOSE: Print("Unitialize: Chart closed"); break;
case REASON_REMOVE: Print("Unitialize: Expert removed from chart"); break;
case REASON_RECOMPILE: Print("Unitialize: Expert recompiled"); break;
case REASON_CHARTCHANGE:Print("Unitialize: Symbol or timeframe changed on the chart"); break;
case REASON_PARAMETERS: Print("Unitialize: Inputs parameters was changed by user"); break;
case REASON_ACCOUNT: Print("Unitialize: Other account activated"); break;
}return(0);}
/////////////////////////////////////////////////////////////////////////////
//+-----------------------------------------------------------------------+//
//| FUNCTIONS, USED IN THIS EXPERT ADVISOR |//
//| Custom and System functions |//
//+-----------------------------------------------------------------------+//
/////////////////////////////////////////////////////////////////////////////bool LoopedStop(string action="set") { LoopedResume("set"); return(true); } string attrSymbol(string sel="") { if (sel=="e" || sel=="event") {return(e_attrSymbol());} return(OrderSymbol()); } int attrMagicNumber(string sel="") { if (sel=="e" || sel=="event") {return(e_attrMagicNumber());} return(OrderMagicNumber()); } double attrType(string sel="") { if (sel=="e" || sel=="event") {return(e_attrType());} return(OrderType()); } bool LoopedResume(string action="set") { static int ticket; if (action=="set") { ticket=OrderTicket(); return(true); } else { OrderSelect(ticket,SELECT_BY_TICKET); return(true); } return(false); } void EventsListener(string action="listen",string command="") { /////// // Define used variables int i=-1, j=-1, k=-1; int ti=-1; int ty=-1; int size=-1; static int start_time=-1; static double tt0=0; static double ask0=0; static double bid0=0; static bool initial_pass=false; static int history_total=0; static int history_total_checked=0; static int shorts_hist_count=0; static int longs_hist_count=0; //-- Virtual stops static string vs_memory_id[]; static double vs_memory_sl[]; static double vs_memory_tp[]; int vs_id; int pos=0; // Define used variables /////// // Event: Timer if (ENABLE_EVENT_TIMER==1) { static double t0=0; // old time if (!TimerStopped()) { double t; // will be current time double tx; static double tx0; bool milli=false; if (TimerPeriod()>=1 || (TimerPeriod()<0 && EVENT_TIMER_PERIOD>0) || IsTesting() || IsVisualMode()) {t=TimeLocal();} else {t=GetTickCount(); milli=true;} if (TimerPeriod()>=0) {tx=TimerPeriod();} else {tx=EVENT_TIMER_PERIOD;} if (milli==true) {tx=tx*1000;} if (tx!=tx0) {t0=0;} if (t>=t0+tx) {t0=t; tx0=tx; EventTimer();} } } // Endless loop (only in case of EA running on Demo or Real) bool loop_it=true; while(loop_it==true && !IsStopped() && (IsTesting() || IsVisualMode() || IsExpertEnabled())) { if (initial_pass==true && !IsTesting()) {DrawEPSMeter();} ////// // in case of testing - make it to pass once if (IsStopped() || IsTesting() || IsVisualMode() || EVENTS_MODE=="tick" || action=="register") {loop_it=false;} ////// ////// // in case of Script - pass 1st tick and start looping on 2'nd tick if (initial_pass==false) {loop_it=false; initial_pass=true;} ////// //-- Event: EventTrade() if (ENABLE_EVENT_TRADE==1) { if (start_time==-1) {start_time=TimeCurrent();} bool e=false; /////// // HISTORY TRADES /* int total=OrdersHistoryTotal(); if (total!=history_total) { history_total=total; for (pos=total-1; pos>=0; pos--) { if (OrderSelect(pos,SELECT_BY_POS,MODE_HISTORY)) { if (OrderOpenTime()>=start_time) { if (history_total>history_total_checked) { history_total_checked++; if (OrderType()==OP_BUY) {longs_hist_count++;} if (OrderType()==OP_SELL) {shorts_hist_count++;} } } else {break;} } } } */ // HISTORY TRADES /////// /////// // TRADES AND ORDERS int tickets_now[]; ArrayResize(tickets_now,0); int tn=0; static int memory_ti[]; static int memory_ty[]; static double memory_sl[]; static double memory_tp[]; static double memory_vl[]; static bool loaded=false; static int total_trades0=0; int total_trades=OrdersTotal(); // Load memory_ti with current trades if started now or EA reloaded if (loaded==false) {loaded=true; for (pos=total_trades-1; pos>=0; pos--) { if (OrderSelect(pos,SELECT_BY_POS,MODE_TRADES)) {//Alert(OrderType()); ArrayResize(memory_ti,tn+1); ArrayResize(memory_ty,tn+1); ArrayResize(memory_sl,tn+1); ArrayResize(memory_tp,tn+1); ArrayResize(memory_vl,tn+1); memory_ti[tn]=OrderTicket(); memory_ty[tn]=OrderType(); memory_sl[tn]=attrStopLoss(); memory_tp[tn]=attrTakeProfit(); memory_vl[tn]=attrLots(); tn++; } } return; } tn=0; bool pending_opens=false; for (pos=total_trades-1; pos>=0; pos--) { if (OrderSelect(pos,SELECT_BY_POS,MODE_TRADES)) { //if (OrderOpenTime()>=start_time) { ArrayResize(tickets_now,tn+1); tickets_now[tn]=OrderTicket(); tn++; // Trades and Orders // 1. Add new trade to memory, if not inside i=-1; ti=-1; ty=-1; size=ArraySize(memory_ti); if (size>0){ for (i=0; i<size; i++) { if (memory_ti*==OrderTicket()) { if (memory_ty*==OrderType()) {ty=OrderType();} else {pending_opens=true;} ti=OrderTicket(); break; } } } if (ti>0 && ty<0) { memory_ti*=attrTicket(); memory_ty*=OrderType(); memory_sl*=attrStopLoss(); memory_tp*=attrTakeProfit(); memory_vl*=attrLots(); UpdateEventValues("Trade","new",""); EventTrade(); } else if (ti<0 && ty<0) { ArrayResize(memory_ti,size+1); memory_ti*=attrTicket(); ArrayResize(memory_ty,size+1); memory_ty*=attrType(); ArrayResize(memory_sl,size+1); memory_sl*=attrStopLoss(); ArrayResize(memory_tp,size+1); memory_tp*=attrTakeProfit(); ArrayResize(memory_vl,size+1); memory_vl*=attrLots(); UpdateEventValues("Trade","new",""); EventTrade(); } // 2. Check for SL or TP modification else if (ty<0 && i>-1) { e=false; if (memory_sl*!=attrStopLoss()) {memory_sl*=attrStopLoss(); e=true; UpdateEventValues("Trade","modify","sl");} if (memory_tp*!=attrTakeProfit()) {memory_tp*=attrTakeProfit(); if (e==true) {UpdateEventValues("Trade","modify","sltp");} else {e=true; UpdateEventValues("Trade","modify","tp");}} if (e==true) {EventTrade(); e=false;} if (memory_vl*!=attrLots()) {memory_vl*=attrLots(); e=true; UpdateEventValues("Trade","modify","lots");} } //} else {break;} } } // There are closed orders/trades bool missing=true; if (pending_opens==false && ArraySize(tickets_now)<ArraySize(memory_ti)) { for(i=ArraySize(memory_ti)-1; i>=0; i--) { // for each ticket in the memory... for(j=0; j<=ArraySize(tickets_now); j++) { // check if trade exists now if (memory_ti*==tickets_now[j]) {missing=false; break;} } if (missing==true) { if (OrderSelect(memory_ti*,SELECT_BY_TICKET)) { // This can happen more than once ArrayStripKeyI(memory_ti,i); ArrayStripKeyI(memory_ty,i); ArrayStripKey(memory_sl,i); ArrayStripKey(memory_tp,i); ArrayStripKey(memory_vl,i); ObjectDelete("#"+OrderTicket()+" sl"); ObjectDelete("#"+OrderTicket()+" tp"); UpdateEventValues("Trade","closed",""); EventTrade(); e=false; } } missing=true; } //ArrayIntersectI(memory_ti,tickets_now); // Remove closed orders from memory } // TRADES AND ORDERS /////// } //-- Event: EventTick() if (ENABLE_EVENT_TICK==1) { if (action=="listen") { if (EVENTS_MODE!="tick") { string market_for_ticks=Symbol(); if (SIMULATE_TICKS==1) {market_for_ticks=SIMULATE_TICKS_MARKET;} double ask=MarketInfo(market_for_ticks,MODE_ASK); double bid=MarketInfo(market_for_ticks,MODE_BID); double tt=MarketInfo(market_for_ticks,MODE_TIME); } if ((EVENTS_MODE=="tick" || (tt!=tt0 || ask!=ask0 || bid!=bid0))) {tt0=tt; ask0=ask; bid0=bid; VirtualStopsDriver("listen"); // will work only if this is used: #define USE_VIRTUAL_STOPS "yes" EventTick(); } } } /* int obj_total=ObjectsTotal(); string name; for(i=0;i<obj_total;i++) { name=ObjectName(i); //Print(i,"Object name for object #",i," is " + name); //Print(ObjectGetValueByShift(name, 0)); } */ if (loop_it==true) {Sleep(EVENTS_CYCLE_PERIOD);} // Endless loop resolution } } void UpdateEventValues(string e_type="",string e_reason="",string e_detail="") { e_Reason(e_reason); e_ReasonDetail("set",e_detail); if (e_type=="Trade" || e_type=="EventTrade") { e_attrClosePrice ("set",attrClosePrice()); e_attrComment ("set",attrComment()); e_attrCommission ("set",attrCommission()); e_attrExpiration ("set",attrExpiration()); e_attrLots ("set",attrLots()); e_attrMagicNumber("set",attrMagicNumber()); e_attrOpenPrice ("set",attrOpenPrice()); e_attrProfit ("set",attrProfit()); e_attrStopLoss ("set",attrStopLoss()); e_attrSymbol ("set",attrSymbol()); e_attrTakeProfit ("set",attrTakeProfit()); e_attrTicket ("set",attrTicket()); e_attrType ("set",attrType()); // Not set, just execute without reason e_attrOpenTime(); e_attrSwap(); } } int TicksFromStart(string cmd="read") { static int ticks=0; if (cmd=="update") {ticks++; if (ticks<0) ticks=0;} return(ticks); } string DrawStatus(string text) { static string memory; if (text=="getCurrentStatus") {return(memory);} int strlen=StringLen(text); string rect1; for (int i=1; i<=strlen; i++) {rect1=rect1+"g";} int x=340; int y=0; string name; static bool draw_status1=true; if (draw_status1==true) {draw_status1=false; name="StatusTitle"; if (ObjectFind(name)==-1) { ObjectCreate (name, OBJ_LABEL, 0, 0, 0); ObjectSet (name, OBJPROP_BACK, false); ObjectSet (name, OBJPROP_XDISTANCE, x); ObjectSet (name, OBJPROP_YDISTANCE, y); ObjectSetText (name, "Status", 7, "Arial", Gray); } } if (text!=memory) {memory=text; name="StatusText"; if (ObjectFind(name)==-1) { ObjectCreate (name, OBJ_LABEL, 0, 0, 0); ObjectSet (name, OBJPROP_BACK, false); ObjectSet (name, OBJPROP_XDISTANCE, x+2); ObjectSet (name, OBJPROP_YDISTANCE, y+8); } ObjectSetText (name, text, 12, "Arial", LightBlue); } return(text); } int PipValue(string symbol="") { if (symbol=="") {symbol=Symbol();} int digits=MarketInfo(symbol,MODE_DIGITS); if ((digits==2 || digits==4)) {return(POINT_FORMAT/0.0001);} if ((digits==3 || digits==5)) {return(POINT_FORMAT/0.00001);} if ((digits==6)) {return(POINT_FORMAT/0.000001);} return(1); } double toDigits(double pips,string symbol="") { if (symbol=="") {symbol=GetSymbol();} return( NormalizeDouble( pips*PipValue()*MarketInfo(symbol,MODE_POINT), MarketInfo(symbol,MODE_DIGITS) ) ); } double toPips(double digits,string symbol="") { if (symbol=="") {symbol=GetSymbol();} return(digits/(PipValue()*MarketInfo(symbol,MODE_POINT))); }/////////////////////////////////////////////////////////////////////////////
//+-----------------------------------------------------------------------+//
//| FUNCTIONS, CALLED FROM FUNCTIONS |//
//+-----------------------------------------------------------------------+//
/////////////////////////////////////////////////////////////////////////////string e_attrSymbol(string cmd="", string inp="") {static string mem; if(cmd=="set"){mem=inp;} return(mem);} int e_attrMagicNumber(string cmd="", int inp=-1) {static int mem=-1; if(cmd=="set"){mem=inp;} return(mem);} int e_attrType(string cmd="", int inp=-1) {static int mem; if(cmd=="set"){mem=inp;} return(mem);} bool TimerStopped() {if (TimerStop(-1)==1) {return(true);} return(false);} double TimerPeriod(double t=-1) {static double time=-1; if (t>=0){time=t;} if (t>-1){TimerStop(0);} return(time);} void DrawEPSMeter() { static int frames=0; static int frame=0; static int eps=0; static int time0=0; static int direction=0; int tl=TimeLocal(); if (tl>time0) { time0=tl; eps=frame; frame=0; int x=0; int y=0; string name="fxdreema_eps_meter"; if (ObjectFind(name)==-1) { ObjectDelete(name); ObjectCreate(name, OBJ_LABEL, 0, 0, 0); ObjectSet (name, OBJPROP_CORNER, 3); ObjectSet (name, OBJPROP_XDISTANCE, x+1); ObjectSet (name, OBJPROP_YDISTANCE, y+1); } ObjectSetText(name, "Events per second: "+eps, 10, "Arial", DarkSeaGreen); } else { frame++; frames++; } /* if (direction==0) { if (frames==20) {Comment(fps,"fps |");} if (frames==40) {Comment(fps,"fps ||");} if (frames==60) {Comment(fps,"fps |||");} if (frames==80) {Comment(fps,"fps ||||");} if (frames==100) {Comment(fps,"fps |||||");} if (frames==120) {Comment(fps,"fps ||||||");} if (frames==140) {Comment(fps,"fps |||||||");} if (frames==160) {Comment(fps,"fps ||||||||");} if (frames==180) {Comment(fps,"fps |||||||||");} if (frames==200) {Comment(fps,"fps ||||||||||"); frames=0; direction=1;} } if (direction==1) { if (frames==20) {Comment(fps+"fps ||||||||||");} if (frames==40) {Comment(fps+"fps |||||||||");} if (frames==60) {Comment(fps+"fps ||||||||");} if (frames==80) {Comment(fps+"fps |||||||");} if (frames==100) {Comment(fps+"fps ||||||");} if (frames==120) {Comment(fps+"fps |||||");} if (frames==140) {Comment(fps+"fps ||||");} if (frames==160) {Comment(fps+"fps |||");} if (frames==180) {Comment(fps+"fps ||");} if (frames==200) {Comment(fps+"fps |"); frames=0; direction=0;} } */ } double attrStopLoss(string sel="") { if (sel=="e" || sel=="event") {return(e_attrStopLoss());} if (USE_VIRTUAL_STOPS=="yes" && sel=="") {return(VirtualStopsDriver("get sl",OrderTicket()));} return(OrderStopLoss()); } double attrTakeProfit(string sel="") { if (sel=="e" || sel=="event") {return(e_attrTakeProfit());} if (USE_VIRTUAL_STOPS=="yes" && sel=="") {return(VirtualStopsDriver("get tp",OrderTicket()));} return(OrderTakeProfit()); } double attrLots(string sel="") { if (sel=="e" || sel=="event") {return(e_attrLots());} return(OrderLots()); } int attrTicket(string sel="") { if (sel=="e" || sel=="event") {return(e_attrTicket());} return(OrderTicket()); } bool ArrayStripKeyI(int &array[], int key) { bool stripped=false; int size=ArraySize(array); if (size>0) { int i=0; int x=0; for (i=0; i<size; i++) { if (i!=key) { array[x]=array*; x++; } else { stripped=true; } } ArrayResize(array,x); } return (stripped); } bool ArrayStripKey(double &array[], double key) { bool stripped=false; int size=ArraySize(array); if (size>0) { int i=0; int x=0; for (i=0; i<size; i++) { if (i!=key) { array[x]=array*; x++; } else { stripped=true; } } ArrayResize(array,x); } return (stripped); } double VirtualStopsDriver(string command="", int ti=-1, double sl=0, double tp=0, double slp=0, double tpp=0) { int i, ii=-1, size; //static int mem_ti[]; //static double mem_sl[]; //static double mem_tp[]; //static double mem_vl[]; if (USE_VIRTUAL_STOPS!="yes") {return;} // Virtual stops are not enabled => stop here // Set SL and TP if ((command=="set" || command=="modify" || command=="clear" || command=="partial") && ti>-1) { // update record (add/modify) string name=""; name="#"+ti+" sl"; if (sl>0) { if (ObjectFind(name)==-1) { ObjectCreate(name,OBJ_HLINE,0,0,sl); ObjectSet(name,OBJPROP_WIDTH,1); ObjectSet(name,OBJPROP_COLOR,DeepPink); ObjectSet(name,OBJPROP_STYLE,STYLE_DOT); ObjectSetText(name,name+" (virtual)"); } else {ObjectSet(name,OBJPROP_PRICE1,sl);} } else {ObjectDelete(name);} name="#"+ti+" tp"; if (tp>0) { if (ObjectFind(name)==-1) { ObjectCreate(name,OBJ_HLINE,0,0,tp); ObjectSet(name,OBJPROP_WIDTH,1); ObjectSet(name,OBJPROP_COLOR,DodgerBlue); ObjectSet(name,OBJPROP_STYLE,STYLE_DOT); ObjectSetText(name,name+" (virtual)"); } else {ObjectSet(name,OBJPROP_PRICE1,tp);} } else {ObjectDelete(name);} // print message if (command=="set" || command=="modify") Print(command+" #"+ti+": virtual sl "+DoubleToStr(sl,Digits)+" tp "+DoubleToStr(tp,Digits)); return(1); } // Get SL or TP if ((command=="get sl" || command=="get tp") && ti>-1) { if (command=="get sl") return(ObjectGet("#"+ti+" sl",OBJPROP_PRICE1)); else if (command=="get tp") return(ObjectGet("#"+ti+" tp",OBJPROP_PRICE1)); return(0); } // Listen trades/orders if (command=="" || command=="listen") { for (int pos=0; pos<OrdersTotal(); pos++) { if (OrderSelect(pos,SELECT_BY_POS)) { // check SL and TP double sl_lvl=ObjectGet("#"+OrderTicket()+" sl",OBJPROP_PRICE1); double tp_lvl=ObjectGet("#"+OrderTicket()+" tp",OBJPROP_PRICE1); // close trade/order if (OrderType()==OP_BUY) { double bid=MarketInfo(OrderSymbol(),MODE_BID); if ((sl_lvl>0 && bid<=sl_lvl) || (tp_lvl>0 && bid>=tp_lvl)) { if (OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,CLR_NONE)) { ObjectDelete("#"+OrderTicket()+" sl"); ObjectDelete("#"+OrderTicket()+" tp"); } return; } } else if (OrderType()==OP_SELL) { double ask=MarketInfo(OrderSymbol(),MODE_ASK); if ((sl_lvl>0 && ask>=sl_lvl) || (tp_lvl>0 && ask<=tp_lvl)) { if (OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,CLR_NONE)) { ObjectDelete("#"+OrderTicket()+" sl"); ObjectDelete("#"+OrderTicket()+" tp"); } return; } } } } } return(1); } string e_Reason(string inp="") {static string mem; if(inp!=""){mem=inp;} return(mem);} string e_ReasonDetail(string cmd="", string inp="") {static string mem; if(cmd=="set"){mem=inp;} return(mem);} double e_attrClosePrice(string cmd="", double inp=-1) {static double mem=-1; if(cmd=="set"){mem=inp;} return(mem);} double attrClosePrice(string sel="") { if (sel=="e" || sel=="event") {return(e_attrClosePrice());} return(OrderClosePrice()); } string e_attrComment(string cmd="", string inp="") {static string mem; if(cmd=="set"){mem=inp;} return(mem);} string attrComment(string sel="") { if (sel=="e" || sel=="event") {return(e_attrComment());} return(OrderComment()); } double e_attrCommission(string cmd="", double inp=0) {static double mem=0; if(cmd=="set"){mem=inp;} return(mem);} double attrCommission(string sel="") { if (sel=="e" || sel=="event") {return(e_attrCommission());} return(OrderCommission()); } datetime e_attrExpiration(string cmd="", datetime inp=0) {static datetime mem=0; if(cmd=="set"){mem=inp;} return(mem);} datetime attrExpiration(string sel="") { if (sel=="e" || sel=="event") {return(e_attrExpiration());} return(OrderExpiration()); } double e_attrLots(string cmd="",double inp=-1) {static double mem=-1; if(cmd=="set"){mem=inp;} return(mem);} double e_attrOpenPrice(string cmd="", double inp=-1) {static double mem; if(cmd=="set"){mem=inp;} return(mem);} double attrOpenPrice(string sel="") { if (sel=="e" || sel=="event") {return(e_attrOpenPrice());} return(OrderOpenPrice()); } double e_attrProfit(string cmd="", double inp=0) {static double mem; if(cmd=="set"){mem=inp;} return(mem);} double attrProfit(string sel="") { if (sel=="e" || sel=="event") {return(e_attrProfit());} return(OrderProfit()); } double e_attrStopLoss(string cmd="", double inp=-1) {static double mem=-1; if(cmd=="set"){mem=inp;} return(mem);} double e_attrTakeProfit(string cmd="", double inp=-1) { static double mem=-1; static double pips=0; double price; if(cmd=="pipsFromHere"){ if (e_attrTakeProfit()>0) { if (e_attrType()==OP_BUY || e_attrType()==OP_BUYSTOP || e_attrType()==OP_BUYLIMIT) { price=SymbolAsk(e_attrSymbol()); pips=toPips(MathAbs(price-e_attrTakeProfit()),e_attrSymbol()); } else { price=SymbolBid(e_attrSymbol()); pips=toPips(MathAbs(price-e_attrTakeProfit()),e_attrSymbol()); } } } if(cmd=="set"){mem=inp;} return(mem); } int e_attrTicket(string cmd="", int inp=-1) {static int mem=-1; if(cmd=="set"){mem=inp;} return(mem);} datetime e_attrOpenTime(string cmd="",datetime inp=-1) {static datetime mem; if(cmd=="set"){mem=inp;} return(mem);} double e_attrSwap(string cmd="", double inp=0) {static double mem; if(cmd=="set"){mem=inp;} return(mem);} string GetSymbol(string symbol="") { static string memory=""; if (memory=="") {memory=Symbol();} if (symbol=="") {return(memory);} if (symbol!="") {memory=symbol; return(memory);} return(Symbol()); } int TimerStop(int s=1) {static int stopped=0; if (s==0 || s==1){stopped=s;} return(stopped);} double SymbolAsk(string symbol="") { if (symbol=="") {symbol=GetSymbol();} return(MarketInfo(symbol,MODE_ASK)); } double SymbolBid(string symbol="") { if (symbol=="") {symbol=GetSymbol();} return(MarketInfo(symbol,MODE_BID)); }/////////////////////////////////////////////////////////////////////////////
//+-----------------------------------------------------------------------+//
//| PERMANENT FUNCTIONS |//
//+-----------------------------------------------------------------------+//
/////////////////////////////////////////////////////////////////////////////string ListOfIDsConnectedToMe(string src) {
static bool passed=false;
static string ids[]; ArrayResize(ids,3);
static string lst[]; ArrayResize(lst,3);
if (passed==false) {passed=true;
ids[0]="2";lst[0]="1";
ids[1]="3";lst[1]="1";
ids[2]="4";lst[2]="3,2";
}
if (src!="") {
int i=0; int maxi=ArraySize(ids); for (i=0; i<maxi; i++) {if (ids*==src) {return(lst*); break;}}
}
return("");
}
void DrawSpreadInfo() {
static bool allow_draw=true;
if (allow_draw==false) {return;}
if ((IsTesting()/||IsVisualMode()/)) {if (allow_draw==true) {allow_draw=false;}} // Allowed to draw only once in testing modedouble pip_value=0; int digits=MarketInfo(Symbol(),MODE_DIGITS); if ((digits==2 || digits==4)) {pip_value=(POINT_FORMAT/0.0001);} if ((digits==3 || digits==5)) {pip_value=(POINT_FORMAT/0.00001);} if ((digits==6)) {pip_value=(POINT_FORMAT/0.000001);}static double max_spread=0;
static double min_spread=0;
static double avg_spread=0;
static double avg_add=0;
static double avg_cnt=0;
double current_spread=(MarketInfo(Symbol(),MODE_ASK)-MarketInfo(Symbol(),MODE_BID))/(pip_value*MarketInfo(Symbol(),MODE_POINT));
if (current_spread>max_spread) {max_spread=current_spread;}
if (current_spread<min_spread || min_spread==0) {min_spread=current_spread;}
avg_add=avg_add+current_spread; avg_cnt++;
avg_spread=avg_add/avg_cnt;int x=0; int y=0;
string name="current_spread";
if (ObjectFind(name)==-1) {
ObjectCreate(name, OBJ_LABEL, 0, 0, 0);
ObjectSet (name, OBJPROP_CORNER, 2);
ObjectSet (name, OBJPROP_XDISTANCE, x+1);
ObjectSet (name, OBJPROP_YDISTANCE, y+1);
}
ObjectSetText(name, "Spread: "+DoubleToStr(current_spread,2), 18, "Arial", DarkOrange);name="max_spread_label";
if (ObjectFind(name)==-1) {
ObjectCreate(name, OBJ_LABEL, 0, 0, 0);
ObjectSet (name, OBJPROP_CORNER, 2);
ObjectSet (name, OBJPROP_XDISTANCE, x+148);
ObjectSet (name, OBJPROP_YDISTANCE, x+17);
ObjectSetText(name, "max:", 7, "Arial", OrangeRed);
}
name="max_spread";
if (ObjectFind(name)==-1) {
ObjectCreate(name, OBJ_LABEL, 0, 0, 0);
ObjectSet (name, OBJPROP_CORNER, 2);
ObjectSet (name, OBJPROP_XDISTANCE, x+173);
ObjectSet (name, OBJPROP_YDISTANCE, y+17);
}
ObjectSetText(name, DoubleToStr(max_spread,2), 7, "Arial", OrangeRed);name="avg_spread_label";
if (ObjectFind(name)==-1) {
ObjectCreate(name, OBJ_LABEL, 0, 0, 0);
ObjectSet (name, OBJPROP_CORNER, 2);
ObjectSet (name, OBJPROP_XDISTANCE, x+148);
ObjectSet (name, OBJPROP_YDISTANCE, y+9);
ObjectSetText(name, "avg:", 7, "Arial", DarkOrange);
}
name="avg_spread";
if (ObjectFind(name)==-1) {
ObjectCreate(name, OBJ_LABEL, 0, 0, 0);
ObjectSet (name, OBJPROP_CORNER, 2);
ObjectSet (name, OBJPROP_XDISTANCE, x+173);
ObjectSet (name, OBJPROP_YDISTANCE, y+9);
}
ObjectSetText(name, DoubleToStr(avg_spread,2), 7, "Arial", DarkOrange);name="min_spread_label";
if (ObjectFind(name)==-1) {
ObjectCreate(name, OBJ_LABEL, 0, 0, 0);
ObjectSet (name, OBJPROP_CORNER, 2);
ObjectSet (name, OBJPROP_XDISTANCE, x+148);
ObjectSet (name, OBJPROP_YDISTANCE, y+1);
ObjectSetText(name, "min:", 7, "Arial", Gold);
}
name="min_spread";
if (ObjectFind(name)==-1) {
ObjectCreate(name, OBJ_LABEL, 0, 0, 0);
ObjectSet (name, OBJPROP_CORNER, 2);
ObjectSet (name, OBJPROP_XDISTANCE, x+173);
ObjectSet (name, OBJPROP_YDISTANCE, y+1);
}
ObjectSetText(name, DoubleToStr(min_spread,2), 7, "Arial", Gold);
}
//+------------------------------------------------------------------+
//| END |
//| Created with fxDreema EA Builder http://fxdreema.com/ |
//+------------------------------------------------------------------+ -
The on-line platform is clearly doing something a bit different as the .mq4 files it exports are bigger. The compiled .ex4 files (always compiled in MT4) are the same size.
I also tried another test:
- export the failing EA ("desktop test 2") to an .xml file from the desktop platform
- import this EA to the on-line platform
- immediately and without any other mouse actions, save this as a .mq4
- compile this in MT4
- run it
...and guess what! The EA now works! I can only surmise that the on-line platform is doing or not doing something the desktop one is or isn't!
Over to you!And thank you, again!

-
Oops
I was made the last build in the wrong way for some reason, sorry for that 
I just uploaded build 024, get it from here. It must be ok. -
Hi
Great!
Thanks. That seems to be working now! 
Thanks again.