How to code? - page 274

 

Unfortunately there is no way to change comment once you opened an order. Then it becomes a sole privilege of broker (and they change it in cases of partial closes) It seems that metatrader was able to provide partial close backtracking to some brokers only through comment field and then they decided to close it from changes to us (mere mortals) completely

JohnCrawdford:
hello,

Is there any way to change the OrderComment, after the order has being created?

I have an EA that creates pending orders in key points that are likely to be reached, however sometimes those orders have to be cancelled/deleted due to undesirable fast movements on the charts, therefore it is no possible to use the ticket number to identify each order, because each key point order can be open and cancelled/deleted several times, so instead the EA uses a unique OrderComment to identify each order, but every once in a while the computer that runs the EA fails or the internet connection fails, and that messes up the key point order identification and therefore it would become useful to change the OrderComment to avoid errors caused by the mess that is created after the EA restarts without first finishing the previous execution.

Very confusing, right?

P.S. the magic number is being used to identify the orders created by the EA, so I cannot used that number to identify each order individually.

If anyone could tell me if there is any way to change the OrderComments I would appreciate,

Thank you in advance.
 

How to have a dynamic compilation on an EA?

Hello world!

I want to know how to create an EA with dynamic compilation (F5) for example every 20 seconds.

I saw that the F5 function was defined by VK_F5 (Thanks Coders Guru!). But how to run?

this is my EA

**********************************

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

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

#property copyright "Copyright © 2008, Systematic-Forex"

#property link "http://www.systematic-forex.com"

#property indicator_chart_window

#property indicator_buffers 1

#property indicator_color1 LightGray // Yellow

extern int TimeFrame = 5;

/*

extern string help_magic_number = "set it if you'll use closing option 3 - closing by magic number";

extern int magic_number = 0; // set it if you'll use closing option 3 - closing by magic number

extern string help_comment_text = "set it if you'll use closing option 4 - closing by comment";

extern string comment_text = "";

extern bool HotKeyOn = true;

extern bool CtrlOn = true;

extern bool ShiftOn = false;

extern bool AltOn = false;

extern string HotKey = "A";

*/

#import "user32.dll"

bool GetAsyncKeyState(int nVirtKey);

#import

#include //for MessageBoxA

//---- MessageBox() Flags

#define MB_OK 0x00000000

#define MB_OKCANCEL 0x00000001

#define MB_ABORTRETRYIGNORE 0x00000002

#define MB_YESNOCANCEL 0x00000003

#define MB_YESNO 0x00000004

#define MB_RETRYCANCEL 0x00000005

#define MB_ICONHAND 0x00000010

#define MB_ICONQUESTION 0x00000020

#define MB_ICONEXCLAMATION 0x00000030

#define MB_ICONASTERISK 0x00000040

#define MB_USERICON 0x00000080

#define MB_ICONWARNING MB_ICONEXCLAMATION

#define MB_ICONERROR MB_ICONHAND

#define MB_ICONINFORMATION MB_ICONASTERISK

#define MB_ICONSTOP MB_ICONHAND

#define MB_DEFBUTTON1 0x00000000

#define MB_DEFBUTTON2 0x00000100

#define MB_DEFBUTTON3 0x00000200

#define MB_DEFBUTTON4 0x00000300

#define MB_APPLMODAL 0x00000000

#define MB_SYSTEMMODAL 0x00001000

#define MB_TASKMODAL 0x00002000

#define MB_HELP 0x00004000 // Help Button

#define MB_NOFOCUS 0x00008000

#define MB_SETFOREGROUND 0x00010000

#define MB_DEFAULT_DESKTOP_ONLY 0x00020000

#define MB_TOPMOST 0x00040000

#define MB_RIGHT 0x00080000

#define MB_RTLREADING 0x00100000

#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

//---- buffers

double Buffer[];

int i,j;

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

//| Custom indicator initialization function |

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

int init()

{

//---- indicators

SetIndexStyle(0,DRAW_LINE);

//SetIndexStyle(0,DRAW_SECTION);

//SetIndexStyle(0,DRAW_ARROW);

//SetIndexStyle(0,DRAW_HISTOGRAM);

//SetIndexStyle(0,DRAW_ZIGZAG);

//SetIndexStyle(0,DRAW_NONE);

SetIndexBuffer(0,Buffer);

SetIndexEmptyValue(0,EMPTY_VALUE);

Comment("\n"+"test_A_sar");

//----

return(0);

}

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

//| Custor indicator deinitialization function |

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

int deinit()

{

Comment("");

return(0);

}

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

//| Custom indicator iteration function |

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

int start()

{

int limit;

int counted_bars=IndicatorCounted();

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

for(int i=0; i<limit; i++)

{

datetime i_Time = iTime(NULL, 0, i);

int j = iBarShift(NULL, TimeFrame, i_Time, bool false);

double sar_m5 = iSAR(NULL, PERIOD_M5 , 0.02, 0.2, j + 0);

double var_indicateur = sar_m5 ;

/*

//

if(Seconds()== 20)

{

Compiled or VK_F5

}

if(Seconds()== 40)

{

Compiled or VK_F5

}

*/

Buffer= sar_m5;

}

return(0);

}

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

**********************************

Best regards test_a_sar_m5.mq4test_a_sar_m5.mq4

Files:
 

Help

i am facing one problem because of stop loss, if anyone can give me answer regarding it. problem is in some metatrader chart the price bars value shows in five digit(1.4545) but in my metatrader it show six digit value(1.45456). so, when it try to put stop loss according to your system, stop loss value become 200 pips to 400 pips. i don't know how to fix it. i am exposing myself a lot. i blown my account twice due to this issue.

Thanks in advance.

 

kelly strategy in martingale money management

Anyone can edit this to kelly strategy or divided by 10.

my lot size is 0.10 when starting equity is $250 this should change to 0.11 when equity growth to $500

-------------------------------------------------------------------

if(Money_management)

{

switch(AccountType)

{

case 0: lotsi=NormalizeDouble(MathCeil((risk*AccountEquity())/10000)/10,1); break;

case 1: lotsi=NormalizeDouble((risk*AccountEquity())/100000,2); break;

case 2: lotsi=NormalizeDouble((risk*AccountEquity())/1000,2); break;

default: lotsi=NormalizeDouble(MathCeil((risk*AccountEquity())/10000)/10,1); break;

}

-------------------------------------------------------------------

Thanks

 

icustom question

I know I did post on icustom thread but...

as according to code guru code

double clr = iCustom(NULL,0,"LSMA in Color",14,1500,5,0);

string sclr;

if(clr==1) sclr="Red";

if(clr==2) sclr="Green";

if(clr==3) sclr="Yellow";

how am I able to get another time frame with same buffer?

note same clr would hold different value for 2 different time frame.

how to work around it?

 
khatrisushil:
i am facing one problem because of stop loss, if anyone can give me answer regarding it. problem is in some metatrader chart the price bars value shows in five digit(1.4545) but in my metatrader it show six digit value(1.45456). so, when it try to put stop loss according to your system, stop loss value become 200 pips to 400 pips. i don't know how to fix it. i am exposing myself a lot. i blown my account twice due to this issue. Thanks in advance.

fist need to detect the broker what digit

in the code you should able to detect the type of digit, there is enough example on digit ea coding.

therefore you may want to study on some EA that able to handle both 4 or 5 digit broker

 

Help me modify my EA on Market execution broker !

Hi everybody, i am a new in EA, i wirted an EA with tragery Signal :

double Buy1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);

double Buy1_2 = iMA(NULL, 0, 200, 0, MODE_EMA, PRICE_CLOSE, Current + 1);

double Buy2_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Buy2_2 = iMA(NULL, 0, 200, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Buy3_1 = iSAR(NULL, 0, 0.005, 0.05, Current + 1);

double Buy3_2 = iSAR(NULL, 0, 0.005, 0.05, Current + 0);

double Buy4_1 = iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, Current + 1);

double Buy4_2 = iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, Current + 0);

double Sell1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);

double Sell1_2 = iMA(NULL, 0, 200, 0, MODE_EMA, PRICE_CLOSE, Current + 1);

double Sell2_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Sell2_2 = iMA(NULL, 0, 200, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Sell3_1 = iSAR(NULL, 0, 0.005, 0.05, Current + 1);

double Sell3_2 = iSAR(NULL, 0, 0.005, 0.05, Current + 0);

double Sell4_1 = iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, Current + 1);

double Sell4_2 = iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, Current + 0);

if (Buy1_1 = Buy2_2 && Buy3_1 < Buy3_2 && Buy4_1 < Buy4_2) Order = SIGNAL_BUY;

if (Sell1_1 > Sell1_2 && Sell2_1 Sell3_2 && Sell4_1 > Sell4_2) Order = SIGNAL_SELL;

But I don't understand why my EA can work fine on Instant Execution (I think so) but on market execution it do nothing, I am trader in easy-forex, Their demo account is Instant execution my EA work fine, but on live account with Market execution my EA do nothing, i mean it can not analyze chart on that MT4, not error, do nothing.

I am contact easy-forex support and they tell me because by different Instant execution and Market execution. So i find someone who have expirence about EA and trading. Please ! help me modify my EA.

Thank you so much !

 
alvintran:
Hi everybody, i am a new in EA, i wirted an EA with tragery Signal :

double Buy1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);

double Buy1_2 = iMA(NULL, 0, 200, 0, MODE_EMA, PRICE_CLOSE, Current + 1);

double Buy2_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Buy2_2 = iMA(NULL, 0, 200, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Buy3_1 = iSAR(NULL, 0, 0.005, 0.05, Current + 1);

double Buy3_2 = iSAR(NULL, 0, 0.005, 0.05, Current + 0);

double Buy4_1 = iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, Current + 1);

double Buy4_2 = iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, Current + 0);

double Sell1_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 1);

double Sell1_2 = iMA(NULL, 0, 200, 0, MODE_EMA, PRICE_CLOSE, Current + 1);

double Sell2_1 = iMA(NULL, 0, 55, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Sell2_2 = iMA(NULL, 0, 200, 0, MODE_EMA, PRICE_CLOSE, Current + 0);

double Sell3_1 = iSAR(NULL, 0, 0.005, 0.05, Current + 1);

double Sell3_2 = iSAR(NULL, 0, 0.005, 0.05, Current + 0);

double Sell4_1 = iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, Current + 1);

double Sell4_2 = iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, Current + 0);

if (Buy1_1 = Buy2_2 && Buy3_1 < Buy3_2 && Buy4_1 < Buy4_2) Order = SIGNAL_BUY;

if (Sell1_1 > Sell1_2 && Sell2_1 Sell3_2 && Sell4_1 > Sell4_2) Order = SIGNAL_SELL;

But I don't understand why my EA can work fine on Instant Execution (I think so) but on market execution it do nothing, I am trader in easy-forex, Their demo account is Instant execution my EA work fine, but on live account with Market execution my EA do nothing, i mean it can not analyze chart on that MT4, not error, do nothing.

I am contact easy-forex support and they tell me because by different Instant execution and Market execution. So i find someone who have expirence about EA and trading. Please ! help me modify my EA.

Thank you so much !

[lang=pl]I think that can be problem with SL/TP. Please show me your code, or part

where you send orders.

Cheers,

Grzesiek[/lang]

 
g.pociejewski:
[lang=pl]I think that can be problem with SL/TP. Please show me your code, or part

where you send orders.

Cheers,

Grzesiek[/lang]

No no , it not problem SL/TP, i know that problem, i said it do nothing, it is mean on demo account ( instant execution or something i don't know) it work fine,but on live account it not work,not have any problem, just do nothing.

This EA by me writed, not buy, not trial version, not any limited.

Please ! help

 

Adding Time Frames and Getting Buffers

mtuppers:

double clr = iCustom(NULL,0,"LSMA in Color",14,1500,5,0);

string sclr;

if(clr==1) sclr="Red";

if(clr==2) sclr="Green";

if(clr==3) sclr="Yellow";

how am I able to get another time frame with same buffer?

note same clr would hold different value for 2 different time frame.

how to work around it?

Hi Mtuppers,

Original Current Time Frame:

double clr = iCustom(NULL,0,"LSMA in Color",14,1500,5,0);

Add the Time period you want and change the variable name to make it different (clr and clr2):

double clr2 = iCustom(NULL,Period_H1,"LSMA in Color",14,1500,5,0); // Period_H1 Time Frame

In the "LSMA in Color" indicator - There are 3 buffers for the colors, not just one, so you can use 3 iCustom statements to get them all.

Here are the buffer numbers:

SetIndexBuffer(2,ExtMapBuffer1);

SetIndexBuffer(1,ExtMapBuffer2);

SetIndexBuffer(0,ExtMapBuffer3);

SetIndexBuffer(3,sum);

SetIndexBuffer(4,wt);

SetIndexBuffer(5,clr);

* Notice in your example, you are using Buffer 0, so you are actually only getting just one color in ExtMapBuffer3. The "clr" buffer is Buffer 5.

Here are the color buffer assignments in the indicator:

ExtMapBuffer3[shift] = wt[shift]; //red

ExtMapBuffer2[shift] = wt[shift]; //green

ExtMapBuffer1[shift] = wt[shift]; //yellow

Hope this helps,

Robert

Reason: