Please fix this indicator or EA - page 35

 

Indicator calls scripts OK but EAs stutter (Keybd-event)

I put this Indicator code together from sources here and there.

When any position is closed (manually or via SL & TP) the code will initiate a Hot-key Keybd-event and any script or EA with assigned matching Hot-keys will respond.

The code calls scripts without problems but EAs stutter (flash on/off) and the Common-Input window locks.

When a position is closed the EA loads before any other indicator has had time to respond and the Common-Input window flashes on/off until other indicator (like a text on a SL line) drops off the chart (which is should do as the position has closed).

After that it stops flashing but the OK, Cancel and Reset buttons on the Common and Input tabs don't work. Focus cannot be taken off this Common-Input Window and it takes numerous clicks to close the Input window before focus can be moved.

If no other indicators are on the chart the EA behaves the same in that the Comon-Input window locks with OK, Cancel and Reset buttons not responding to mouse clicks.

I tested this on two machines and the same for both.

When scripts are called all goes successfully but the below alert always pops up.

There is no automated closing of orders - orders are closed either manually via the Easy Order script or manually via MT4 Terminal or when current price equals SL or TP. The script only deletes the lines and is called after an order has closed. I also tested this - for(int i = OrdersHistoryTotal()-1;i >=0; i--), which I believe to be counting down, and it appears to work equally well when multiple or a single order is in the history ie. it does not miss the last closed order in the order history.

I am reading the manual but have'nt got to this part yet ! Thanks in advance - any help most appreciated.

#property copyright "Copyright © 2012 file45"

#property indicator_chart_window

extern int Hot_Key1 = 162; // 162 L-Ctrl

extern int Hot_Key2 = 90; // 90 Z, 65 A

#include

//#import "user32.dll"

void keybd_event(int bVk, int bScan,int dwFlags,int dwExtrainfo);

//bool GetAsyncKeyState(int nVirtKey);

#define KEYEVENTF_EXTENDEDKEY 0x0001

#define KEYEVENTF_KEYUP 0x0002

#define VK_0 48

#define VK_1 49

#define VK_2 50

#define VK_3 51

#define VK_4 52

#define VK_5 53

#define VK_6 54

#define VK_7 55

#define VK_8 56

#define VK_9 57

#define VK_A 65

#define VK_B 66

#define VK_C 67

#define VK_D 68

#define VK_E 69

#define VK_F 70

#define VK_G 71

#define VK_H 72

#define VK_I 73

#define VK_J 74

#define VK_K 75

#define VK_L 76

#define VK_M 77

#define VK_N 78

#define VK_O 79

#define VK_P 80

#define VK_Q 81

#define VK_R 82

#define VK_S 83

#define VK_T 84

#define VK_U 85

#define VK_V 86

#define VK_W 87

#define VK_X 88

#define VK_Y 89

#define VK_Z 90

#define VK_LBUTTON 1 //Left mouse button

#define VK_RBUTTON 2 //Right mouse button

#define VK_CANCEL 3 //Control-break processing

#define VK_MBUTTON 4 //Middle mouse button (three-button mouse)

#define VK_BACK 8 //BACKSPACE key

#define VK_TAB 9 //TAB key

#define VK_CLEAR 12 //CLEAR key

#define VK_RETURN 13 //ENTER key

#define VK_SHIFT 16 //SHIFT key

#define VK_CONTROL 17 //CTRL key

#define VK_MENU 18 //ALT key

#define VK_PAUSE 19 //PAUSE key

#define VK_CAPITAL 20 //CAPS LOCK key

#define VK_ESCAPE 27 //ESC key

#define VK_SPACE 32 //SPACEBAR

#define VK_PRIOR 33 //PAGE UP key

#define VK_NEXT 34 //PAGE DOWN key

#define VK_END 35 //END key

#define VK_HOME 36 //HOME key

#define VK_LEFT 37 //LEFT ARROW key

#define VK_UP 38 //UP ARROW key

#define VK_RIGHT 39 //RIGHT ARROW key

#define VK_DOWN 40 //DOWN ARROW key

#define VK_PRINT 42 //PRINT key

#define VK_SNAPSHOT 44 //PRINT SCREEN key

#define VK_INSERT 45 //INS key

#define VK_DELETE 46 //DEL key

#define VK_HELP 47 //HELP key

#define VK_LWIN 91 //Left Windows key (Microsoft® Natural® keyboard)

#define VK_RWIN 92 //Right Windows key (Natural keyboard)

#define VK_APPS 93 //Applications key (Natural keyboard)

#define VK_SLEEP 95 //Computer Sleep key

#define VK_NUMPAD0 96 //Numeric keypad 0 key

#define VK_NUMPAD1 97 //Numeric keypad 1 key

#define VK_NUMPAD2 98 //Numeric keypad 2 key

#define VK_NUMPAD3 99 //Numeric keypad 3 key

#define VK_NUMPAD4 100 //Numeric keypad 4 key

#define VK_NUMPAD5 101 //Numeric keypad 5 key

#define VK_NUMPAD6 102 //Numeric keypad 6 key

#define VK_NUMPAD7 103 //Numeric keypad 7 key

#define VK_NUMPAD8 104 //Numeric keypad 8 key

#define VK_NUMPAD9 105 //Numeric keypad 9 key

#define VK_MULTIPLY 106 //Multiply key

#define VK_ADD 107 //Add key

#define VK_SEPARATOR 108 //Separator key

#define VK_SUBTRACT 109 //Subtract key

#define VK_DECIMAL 110 //Decimal key

#define VK_DIVIDE 111 //Divide key

#define VK_F1 112 //F1 key

#define VK_F2 113 //F2 key

#define VK_F3 114 //F3 key

#define VK_F4 115 //F4 key

#define VK_F5 116 //F5 key

#define VK_F6 117 //F6 key

#define VK_F7 118 //F7 key

#define VK_F8 119 //F8 key

#define VK_F9 120 //F9 key

#define VK_F10 121 //F10 key

#define VK_F11 122 //F11 key

#define VK_F12 123 //F12 key

#define VK_F13 124 //F13 key

#define VK_NUMLOCK 144 //NUM LOCK key

#define VK_SCROLL 145 //SCROLL LOCK key

#define VK_LSHIFT 160 //Left SHIFT key

#define VK_RSHIFT 161 //Right SHIFT key

#define VK_LCONTROL 162 //Left CONTROL key

#define VK_RCONTROL 163 //Right CONTROL key

#define VK_LMENU 164 //Left MENU key

#define VK_RMENU 165 //Right MENU key

int Orders;

//+------------------------------------------------------------------+

int start()

{

if (Orders>OrdersTotal()) Closed_Order_Detect();

Orders=OrdersTotal();

return(0);

}

//+------------------------------------------------------------------+

void Closed_Order_Detect()

{

double Order_Close;

int i,hstTotal=OrdersHistoryTotal();

for(i=0;i<hstTotal;i++)

{

if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true)

if (OrderSymbol()==Symbol())

{

Order_Close=OrderClosePrice();

if (Order_Close==OrderStopLoss() ) SendKey(VK_HOME,true);

if (Order_Close==OrderTakeProfit()) SendKey(VK_HOME,true);

if(OrderCloseTime()!=0) SendKey(VK_HOME,true);

}

}

}

//+------------------------------------------------------------------+

void SendKey(int key, bool release = false)

{

keybd_event(Hot_Key1, 0, 0, 0); // Left-Ctrl (162)

keybd_event(Hot_Key2, 0, 0, 0); // Z (90)

keybd_event(Hot_Key2, 0, KEYEVENTF_KEYUP, 0);

keybd_event(Hot_Key1, 0, KEYEVENTF_KEYUP, 0);

if(release) keybd_event(key, 0, KEYEVENTF_KEYUP, 0);

}

/*void ReleaseKey(int key)

{

keybd_event(key,0,2,0); // 2 = KEYEVENTF_KEYUP

} */

Files:
alert-img.jpg  28 kb
 

coder needed

Hi!

I have one EA based on this strategy No.1 EarnMoneyPlus

earnmoneyplus.net_sar.mq4

I want to upgrade it with martinagle system and trailling stops.

If here are some good boys to help me, please contact me!

This is my first post, please be kind!

Thanks!

 

metatrader uptick downtick indicator

I have a bar range indicator as attached, it tells me the range of a bar, high-low. i want someone to alter the code so that when the ask price goes up by atleast one pip(from 1.2550x to 1.2551x), or more. its uptick count increases by 1 or more and when the bid price goes down by one pip or more the downtick goes down by one or more. it resets on a new bar.

thanks

Files:
 

...

Take a look at this thread : https://www.mql5.com/en/forum/176348 . Maybe there is already what you are looking for.

Limiting moves to some amount of pips (and counting them then) is yet another subject and usually indicators like constant range bars (one of the threads about it here : https://www.mql5.com/en/forum/180260 are doing that

darkknight3:
I have a bar range indicator as attached, it tells me the range of a bar, high-low. i want someone to alter the code so that when the ask price goes up by atleast one pip(from 1.2550x to 1.2551x), or more. its uptick count increases by 1 or more and when the bid price goes down by one pip or more the downtick goes down by one or more. it resets on a new bar. thanks
 

How can 1000000 be formatted as 1,000,000 ?

Hi

Besides Hanover's (free) Handy Utility - NumberToStr() - is there any other way to format numbers so that thousands and millions etc are automatically separated by commas, ie. 1,000,000.

Handy Utility - NumberToStr() accomplishes said objective but poses a problems to lengthy to go into.

Thank in advance.

 

...

Try this function. It is simple and does what you are looking for (you need to specify decimal precision only) Usage would be something like formatDouble(someNumber,someRequiredPrecision)

string formatDouble(double number, int precision, string pcomma=",", string ppoint=".")

{

string snum = DoubleToStr(number,precision);

int decp = StringFind(snum,".",0);

string sright = StringSubstr(snum,decp+1,precision);

string sleft = StringSubstr(snum,0,decp);

string formated = "";

string comma = "";

while (StringLen(sleft)>3)

{

int length = StringLen(sleft);

string part = StringSubstr(sleft,length-3,0);

formated = part+comma+formated;

comma = pcomma;

sleft = StringSubstr(sleft,0,length-3);

}

if (sleft!="") formated = sleft+comma+formated;

if (precision>0) formated = formated+ppoint+sright;

return(formated);

}
file45:

Hi

Besides Hanover's (free) Handy Utility - NumberToStr() - is there any other way to format numbers so that thousands and millions etc are automatically separated by commas, ie. 1,000,000.

Handy Utility - NumberToStr() accomplishes said objective but poses a problems to lengthy to go into.

Thank in advance.

 

lovely - it has also solves the problem

Try this function. It is simple and does what you are looking for (you need to specify decimal precision only) Usage would be something like formatDouble(someNumber,someRequiredPrecision)

Lovely - it has solved the problem of 1) text dropping out when order price = 0 and 2) text not reinstating when order prices > or < than 0.

Here are two that I that have since come across - not had time to test.

DoubleToStringCommaSep

string DoubleToStrCommaSep(double v, int decimals=4){ // 34,256,454.23 if (decimals == 0) return( IntToStrCommaSep(v) ); if (v < 0) return( "-" + DoubleToStrCommaSep(-v, decimals) ); int integer = v; string fraction = StringSubstr(DoubleToStr(v - integer, decimals), 1); return( IntToStrCommaSep(integer) + fraction);}string IntToStrCommaSep(int integer){ if (integer < 0) return( "-" + IntToStrCommaSep(-integer) ); if (integer < 1000) return(integer); string left = IntToStrCommaSep(integer / 1000); return( left + "," + RJust(integer % 1000, 3) );}string RJust(string s, int size, string fill="0"){ while( StringLen(s) < size ) s = fill + s; return(s); }

[/PHP]

FormatNumber

[PHP] string FormatNumber(string numb, string delim=",",string dec="."){int pos=StringFind(numb,dec);if(pos==-1) { string nnumb=numb; string enumb=""; }else { nnumb=StringSubstr(numb,0,pos); enumb=StringSubstr(numb,pos); }int cnt=StringLen(nnumb);if (cnt<4)return(numb);int x=MathFloor(cnt/3);int y=cnt-x*3;string forma="";if(y!=0)forma=StringConcatenate(StringSubstr(nnumb,0,y),delim);for(int i=0;i<x;i++) { if(i!=x-1)forma=StringConcatenate(forma,StringSubstr(nnumb,y+i*3,3),delim); else forma=StringConcatenate(forma,StringSubstr(nnumb,y+i*3,3)); }forma=StringConcatenate(forma,enumb); return(forma);}

 

Active Boundaries Indicator not updating correctly

We have written an indicator based on Pascal Willeim's effective volume indicators. The active boundary indicator basically shows the greed and hurting percentages based upon price and volume.

The issue is that it is not updating properly. When you run the indicator and then go into properties and OK, the results change

Code is as below (which does include some greyed out code from previous indicators), but if anybody could make any suggestions as to why this is not updating properly, we would be really grateful. Indicator also provided as attachment

#property copyright "Your copyright"

#property link "Link to your website"

#property indicator_separate_window

#property indicator_buffers 1

#property indicator_color1 Blue

#property indicator_width1 2

//extern int numDays = 5;

extern int numBars = 30;

extern int avgPeriod = 10; // how many bars back to average the rolling separation volume

double prePrice, totPrePrice, totVol;

// local variables

double Buffer1[];

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

//int j;

//ObjectsDeleteAll(); // clear the chart

IndicatorShortName("Active Boundaries");

//IndicatorDigits(Digits);

IndicatorBuffers(1);

SetIndexBuffer(0, Buffer1);

SetIndexStyle(0, DRAW_LINE);

/* for(j = Bars; j > Bars - numBars; j--) {

prePrice = Close[j] * Volume[j];

totPrePrice += prePrice;

totVol += Volume[j];

}*/

return(0);

}

//+------------------------------------------------------------------+

//| Custom indicator deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

ObjectsDeleteAll();

return(0);

}

//+------------------------------------------------------------------+

//| Custom indicator start function |

//+------------------------------------------------------------------+

int start()

{

int i, j, limit;

double avgPrice, avgProfit, AB;

int counted_bars=IndicatorCounted();

// static int flag = 0;

// int numBarsInPeriod;

if(counted_bars < 0) return(-1);

if(counted_bars > 0) counted_bars--;

limit = Bars - counted_bars -2;

// pre processing - calculate the very first window of numDays at the beginning of chart

/* if (flag == 0) {

flag=1;

Print("f=",flag);

Print("lim=",limit);

for(j = limit; j > limit - numBars; j--) {

prePrice = Close[j] * Volume[j];

totPrePrice += prePrice;

totVol += Volume[j];

Print("j=",j);

}

}*/

// main loop

for(i = limit; i >= 1; i--)

{

// add latest minute info and subtract trailing minute from numDays before

prePrice = Close * Volume;

totPrePrice += prePrice;

prePrice = Close * Volume;

totPrePrice -= prePrice;

totVol += Volume - Volume;

avgPrice = totPrePrice / totVol;

avgProfit = (Close - avgPrice) / avgPrice;

AB = avgProfit * 100;

Buffer1 = AB;

}

return(0);

}

 

help with indicator and alert

hi forum,

i only work with support/resist, pivots and trendlines. therefore this indicator is a really good help. you don't have to create a metatrader alert for every price limit. it recognizes manual drawn horizontal lines and the lines which are created by a pivot indicator.

and here is a question to the coders here:

because i can see OBJ_TREND i think that trendlines should also be recognized but it doesn't work all the time. sometimes it works, sometimes not. maybe a coder could have a look at it? i hope it's just a small error.

Files:
 

...

The way it works now is the following (when you create horizontal line or trend line - the rest is ignored)

    [*=1]in case of horizontal line it reads the price of the horizontal line and if current bar high is >= that price and current bar low is = than current bar time) and if that end point time is in between current bat high and low (same condition as above) then it alerts.

In case 2 it can omit when neither end point is >= from current bar time (the whole line is in the past). It does that once per bar

Marbo:
hi forum,

i only work with support/resist, pivots and trendlines. therefore this indicator is a really good help. you don't have to create a metatrader alert for every price limit. it recognizes manual drawn horizontal lines and the lines which are created by a pivot indicator.

and here is a question to the coders here:

because i can see OBJ_TREND i think that trendlines should also be recognized but it doesn't work all the time. sometimes it works, sometimes not. maybe a coder could have a look at it? i hope it's just a small error.