Comment on chart (low level)
-
I'm struggling to understand where I'm going wrong.
test1 works : http://fxdreema.com/shared/Tq0HspPUb
test2 doesn't : http://fxdreema.com/shared/Aq9LaU72e
Using back testing with test2, I'm expecting to see the result from the "comment on chart" block, which would be account free margin and the current time ticking upwards. This works fine in test1.
Any advice would be greatly appreciated.
Thanks.
-
I think "Once per tick" is the problem (by the way now it's sunday, there are no ticks). Also, thic block is not to be used there. Try with "Just pass" instead.
-
Well, in backtesting (visual mode) both works for me

-
As I'm using the back test function of MT4 I do get the ticks and the comment block to work in test1, eventhough its Sunday.
I've re-done test2 as you suggested, and tried all sorts of varieties, even the one shown here http://fxdreema.com/shared/dbZiubUNc, and still the time stays still!
What could I be doing wrong?
-
Actually I've just discovered that test2 (http://fxdreema.com/shared/9Nsxhb19c) works with:
Forex (EURUSD)
CFD (AALUK)
Futures (Brent)... but not indicies:
SP500
UK100Any idea why?
-
Are there some error messages?
"Timer" event is artifical loop (not included in MQL4 itself) and it works with local time, which is the same as the server time while backtesting. It should work the same with all markets, unless there is something that I am not aware of. Are you sure the EA starts at all when it looks that it's not working? Maybe missing history data? -
Yes, I think the EA is starting OK. And no, all history is present.
However, there is an error message on the indices (SP500 & UK100) which doesn't appear on any other market:
Journal message:
2012.11.26 14:39:58 2012.10.19 13:59 test2 SP500SB,M1: zero divideJournal Log:
14:39:58 test2 inputs: MagicStart=5098;
14:39:58 2012.10.19 13:59 test2 SP500SB,M1: zero divideI don't know what this means, or why it would only appear in the indices, and nowhere else. Any thoughts?
-
The problem was terminated 8-)
-
Yes, sorry. Fair point!

But any idea what makes the indices different to everything else in this way?
-
There was a missing part of the code somewhere when it comes to 1 digit after the point or no digit after the point.
-
Ah ha!
Got it working. Thank you so much. Now "test2" works!http://fxdreema.com/shared/nugEFMIrb
Tested on:
Forex (EURUSD)
CFD (AALUK)
Futures (Brent)
Indices (SP500, UK100) -
Well... now I'm really confused! I'm sorry to be going on and on about this one, but I'm wondering if I've come across a bug or something in the desktop version. Either that or it really is me..!

I've created two identical EAs. One done using the on-line generator, and called "On-line test"; the other using the desktop generator, called "Desktop test". These I've attached to this posting.
Using Indices (SP500, UK100) the "On-line test" works, the "Desktop test" doesn't. It fails with the "2012.11.27 17:01:46 2012.11.13 14:51 desktop test UK100SB,M1: zero divide" error in the journal.
They both work on Forex (EURUSD), CFD (AALUK), Futures (Brent).
Help! Please tell me it isn't me! I'm going round and round and round here...!

Actually, I don't seem to be able to upload any files for some reason. Is it disabled? What format can I upload in?
-
OK. Here's "On-line test"
//+------------------------------------------------------------------------------+//
//) ____ _ _ ____ ____ ____ ____ __ __ __ ___ _____ __ __ (//
//) ( )( / )( _ ( _ ( )( )( / ) /\ / )( _ )( / ) (//
//) )) ) ( )() )) / )) )) ) ( /()\ ( (__ )()( ) ( (//
//) (__) (/_)(/()_)()(_)(//_)()()()_)(___)(//_) (//
//) 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=1177; // 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()); } } 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);} 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]="2,3";
}
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=1; int digits=MarketInfo(Symbol(),MODE_DIGITS); if (digits==1) {pip_value=(POINT_FORMAT/0.00001);} else if ((digits==2 || digits==4)) {pip_value=(POINT_FORMAT/0.0001);} else if ((digits==3 || digits==5)) {pip_value=(POINT_FORMAT/0.00001);} else 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/ |
//+------------------------------------------------------------------+/<fxdreema:eNrVVltv2zYUfs+vEPgUA9mmm+NafmouHTIk9VY7AwYMEGiJUrhQokBSdt3C/32HImVLjrygGTpgTxLO5eO5n4OjSfRVRu8iJIlStMwlmuHI9zTR8yNUCf4XSVRc4oKgmaHNyx8YLYmjiFQtLeEpYbjMa5w3cmGEHn67Dxu2F6EUKxIngsAHzWjkBePQDcbuNOjyC57SbNvhB97U8guc0ySWCgtl0T1vMmnRV4wnz1LrGxsj5DZfN0IkKeOV4M9EoNkqcoHqAzUlSjtlGHFKc6pky/cmEcoFrp5iLigpFVaUl+1LS14t+RVXihcN6TJCOFF0Dc5xEIWoCGvfkibP+hdCidZU0hUjMaMrgcU2zgWvK80EdbmVihiwIEKKFmCQJICWSh2JS9cGmJckrmgVS/qFWFX3R9d1PWRtriWJ11SoGjMIFK9k83qESt5ITI0EAfyclMn2hMwRPxaE9UI6IILTtCcCP2QNgTskJNSOmXA0AIabbBOISUUE5WmTdM0GUUmLmul60DqyC61j2efGBRbPRNmA3D5+elzcoNlOQlWjDS1TvmnqOdTlvCd5mjS1ZW9IdzcaoishQQKBf/Msk/oBsC90bVExkqkDPZy4RvpUCQDLZt48A6/eZXOREiGt4bp+SRNFQLcqFCJUS1tolgyaKZUYaintlmuFBbSnAjwoQy5SuVfpRsJ/1W1/yG1/POy2P/1Gt8eQoKJS2//S5+BVn4NBny+HfR6H/wOfw1d9Dod8DqYnytv9Rp/hmWteFNDj393rnTH4IHGi2ZsdB+N1sM9h/m3uB/pS0z+2Y+cuc5TAKfmJa75DPlOpZIt1feyJVv1VPzxu9ijoG9hFwqtmIoItmLF2XBrmz+1WsCCas9gWK84G1CCsiz8erub3RwpX9VbOxYIwJm2aVlw9NQWi2ZsF0cFS3IQq0OaBsdKzY7YNiPSPCcGBYIttAauxNueChhnrHcWzrDuww2az417C+vNofCIzfi8z3TbapwWq6BcIvFNh+SITdtW3aXCjr7sXY+HU08F3fbrpzssTT4e9p/uNdCjHd3u6w0sneYKjyDlnfOMw2Kxs9HpVerZDOuievj7O0Psk4TXgZoIQB3ZrTkuHSgdd3PAa+nLJF0qcW6EPIPPQiJyPLvzRBfqzRBdn6LoWQpumTxmju4Q/o6n/LP98NDo7+3e1ZGsa5lIJ1xxcaYf21xepu69wgMsoYamNzM3th/eP98v2AOO1SMjLsQAsODdzc1x063Jn4L1BeNC6+/j77ae3oQd7dP/Nxvun4cM9fPBm+OCf4U0+yWcYxuUhn/1prFviuCNsm5g1A3d+qeRBFKhrLKjeDHvq7m+VhPR+
:fxdreema>/ -
...and "Desktop test"...
//+------------------------------------------------------------------------------+//
//) ____ _ _ ____ ____ ____ ____ __ __ __ ___ _____ __ __ (//
//) ( )( / )( _ ( _ ( )( )( / ) /\ / )( _ )( / ) (//
//) )) ) ( )() )) / )) )) ) ( /()\ ( (__ )()( ) ( (//
//) (__) (/_)(/()_)()(_)(//_)()()()_)(___)(//_) (//
//) 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=1063; // 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 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: 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(); } } } //-- 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 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)) { ArrayResize(memory_ti,tn+1); ArrayResize(memory_sl,tn+1); ArrayResize(memory_tp,tn+1); ArrayResize(memory_vl,tn+1); memory_ti[tn]=OrderTicket(); memory_sl[tn]=attrStopLoss(); memory_tp[tn]=attrTakeProfit(); memory_vl[tn]=attrLots(); tn++; } } } tn=0; 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; size=ArraySize(memory_ti); if (size>0){for (i=0; i<size; i++) {if (memory_ti*==OrderTicket()) {ti=OrderTicket(); break;}}} if (ti<0) { ArrayResize(memory_ti,size+1); memory_ti*=attrTicket(); ArrayResize(memory_sl,size+1); memory_sl*=attrStopLoss(); ArrayResize(memory_tp,size+1); memory_tp*=attrTakeProfit(); ArrayResize(memory_vl,size+1); memory_vl*=attrLots(); //if (OrderOpenTime()>=start_time) { UpdateEventValues("Trade","new",""); EventTrade(); //} } // 2. Check for SL or TP modification else if (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 (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); 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 /////// } /* 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()); } } 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); }/////////////////////////////////////////////////////////////////////////////
//+-----------------------------------------------------------------------+//
//| 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 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); } 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); } 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);} 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 toPips(double digits,string symbol="") { if (symbol=="") {symbol=GetSymbol();} return(digits/(PipValue()*MarketInfo(symbol,MODE_POINT))); } double SymbolBid(string symbol="") { if (symbol=="") {symbol=GetSymbol();} return(MarketInfo(symbol,MODE_BID)); } string GetSymbol(string symbol="") { static string memory=""; if (memory=="") {memory=Symbol();} if (symbol=="") {return(memory);} if (symbol!="") {memory=symbol; return(memory);} return(Symbol()); } 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); }/////////////////////////////////////////////////////////////////////////////
//+-----------------------------------------------------------------------+//
//| PERMANENT FUNCTIONS |//
//+-----------------------------------------------------------------------+//
/////////////////////////////////////////////////////////////////////////////string ListOfIDsConnectedToMe(string src) {
static bool passed=false;
static string ids[3];
static string lst[3];
if (passed==false) {passed=true;
ids[0]="2";lst[0]="1";
ids[1]="3";lst[1]="1";
ids[2]="4";lst[2]="2,3";
}
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/ |
//+------------------------------------------------------------------+ -
Would be very grateful for your ideas on this. I am running the most up to date desktop version, Build 023.
I can't understand why two identical EAs but composed on different flavours of the platform should behave differently.
Thanks.
-
Because I uploaded 023 before correcting this problem.
Ok, now I just uploaded 023 again, with only this problem corrected, you can try it.Because you are using markets with point .0 or probably full number prices, are you ok with how big pip size is? Because I'm not really sure what it should be and I'm a little bit confused.
(the problem was about pips size for markets with .0) -
Hi
Thanks for uploading the updated build 023. And yes, I'm OK with the pips. They are just the ones each market seems to offer.
I've run some tests, and here are the results:
In order to run the tests, I deleted both test EAs, "on-line test" and "desktop test" from fxDreema (on-line and desktop) and MT4. I then re-created them, and compiled them in MT4. In both cases the compiler said; "Function "toDigits" is not referenced and will be removed from exp-file", which appeared to be associated with the very first line of script, which is a comment line above the "#property copyright "" " line.
For the EA created on line I ran the following:
Forex (EURUSD)
CFD (AALUK)
Futures (Brent)
Indices (SP500, UK100)In no case did the "comment on chart (Low level)" display anything.
In no case did an error appear in the Journal.Then, for the EA created in the desktop flavour of the platform I ran the same markets, but achieved slightly different results:
Forex (EURUSD) -- no comment displayed, no error in Journal
CFD (AALUK) -- no comment displayed, no error in Journal
Futures (Brent) -- no comment displayed, no error in Journal
Indices (SP500, UK100) -- no comment displayed, BUT one error in JournalSP500 Journal error: 2012.11.28 11:28:43 2012.10.19 13:59 desktop test SP500SB,M1: zero divide
UK100 Journal error: 2012.11.28 11:28:26 2012.11.13 14:51 desktop test UK100SB,M1: zero divideSo now, although the online composed EA doesn't produce any errors, neither does it seem to work any more!

The EAs are very simple, and, apart from the "If trade/order exists" block, are simply fxDreema defaults. The image attached shows the minor change in the "If trade/order exists" block:

For the sake of completeness, I also attach the following screen shot:

This shows the output from a more complex EA, running and showing a load of comments printed on the chart, all running and updating every tick. I created this EA yesterday on the online platform. The EA created on the desktop flavour yesterday failed in the same way my basic tests are now.
Thanks again for your help and attention. I'm looking forward to progressing with your wonderful system as I've much EA developing and testing to do!

......
tests.jpg
sp500chart.jpg -
The problem was in the spread meter shown on the lower left angle. But now it should be ok, at least I can't get the "zero divide" error anymore. Are you sure you are running new EA's? The problem was in this row:
double pip_value=0;so I replaced it with:
double pip_value=1; -
Hi there,
So, to make sure I wasn't the weakest link
I created 2 new EAs, "on-line test 2" and "desktop test 2", created on-line and on the desktop variants respectively. Their code was as before, simple and identical.I then compiled and ran them, and this screenshot shows the result:

Seems odd that although I deleted the old EAs "on-line test" and "desktop test", and then re-created them this didn't seem to work.
Anyway, as the screenshot shows, "on-line test 2" seems to work, and "desktop test 2" still doesn't.
Would you like me to send the code of these two again?
......
tests 2.jpg