How to code? - page 24

 

thank you

thank you. you're a life savor

 
BC Brett:
Wish I had the answer.

I just finished writing my first EA and tried testing it in Strategy Tester.

I was getting errors showing in the ST journal so I tried using the Print function in my EA to debug the problems. I've worked out a few bugs so far this way, but it's a slow process.

in the metaeditor under edit menu exist "toggle breakpoint" ... as to use breakpoint?

 

Just for information:

- thread about email function (how to code) https://www.mql5.com/en/forum/174336

- good article with some tool https://www.mql5.com/en/forum/176053

 

Code for Invisible TP and SL from Brokers

Hello Everyone,

With the paranoia of brokers hunting for SLs and widening spreads to avoid TPs, I'm looking for info on how to hide TP and SL from brokers.

I know that by submitting a TP and SL to the broker, in the event you're disconnected your order is "safe". While holding the info remotely, there is a danger of huge losses in the event the connection is lost.

Does anyone have an EA or example of code on how to keep TP and SL hidden from the broker?

Thanks!

Mike

 

This EA has it

Hi MikeP

I think this EA contains what you are looking for. Please PM me if this is what you are looking for, I have another idea with this.

Files:
jlpigrid.mq4  8 kb
 

Help for simplify a piece of code

Hi there!

I am not a pro coder (see below!). This code work fine but is it possible to simplify it? With a while/for cycle for example? I wish the lightest code! This one is very "heavy" and I get the "internal stack overflow-simplify the program, please" error!!!

It's an indicator in a separate window.

In the example code, it displays the up or down for MA for multi TF.

Thanks for your help.

int start()

{

string MAfast_Trend_1, MAfast_Trend_5, MAfast_Trend_15;

double x;

color color_indic;

// period M1

double FastMA_1_1 = iMA(NULL,PERIOD_M1,FastMAPeriod,0,MAMethod,MAPrice,MAShift);

double FastMA_2_1 = iMA(NULL,PERIOD_M1,FastMAPeriod,0,MAMethod,MAPrice,MAShift+1);

if ((FastMA_1_1 > FastMA_2_1)) { MAfast_Trend_1 = "UP"; x = 256; color_indic = Lime; }

if ((FastMA_1_1 < FastMA_2_1)) { MAfast_Trend_1 = "DOWN"; x = 246; color_indic = Red; }

ObjectCreate("Trend_MAfast_1", OBJ_LABEL, WindowFind("xxxxxxx"), 0, 0);

ObjectSetText("Trend_MAfast_1",MAfast_Trend_1,7, "Verdana", color_indic);

ObjectSet("Trend_MAfast_1", OBJPROP_CORNER, 0);

ObjectSet("Trend_MAfast_1", OBJPROP_XDISTANCE, x);

ObjectSet("Trend_MAfast_1", OBJPROP_YDISTANCE, 22);

// period M5

double FastMA_1_5 = iMA(NULL,PERIOD_M5,FastMAPeriod,0,MAMethod,MAPrice,MAShift);

double FastMA_2_5 = iMA(NULL,PERIOD_M5,FastMAPeriod,0,MAMethod,MAPrice,MAShift+1);

if ((FastMA_1_5 > FastMA_2_5)) { MAfast_Trend_5 = "UP"; x = 256; color_indic = Lime; }

if ((FastMA_1_5 < FastMA_2_5)) { MAfast_Trend_5 = "DOWN"; x = 246; color_indic = Red; }

ObjectCreate("Trend_MAfast_5", OBJ_LABEL, WindowFind("xxxxxxx"), 0, 0);

ObjectSetText("Trend_MAfast_5",MAfast_Trend_5,7, "Verdana", color_indic);

ObjectSet("Trend_MAfast_5", OBJPROP_CORNER, 0);

ObjectSet("Trend_MAfast_5", OBJPROP_XDISTANCE, x);

ObjectSet("Trend_MAfast_5", OBJPROP_YDISTANCE, 37);

// period M15

double FastMA_1_15 = iMA(NULL,PERIOD_M15,FastMAPeriod,0,MAMethod,MAPrice,MAShift);

double FastMA_2_15 = iMA(NULL,PERIOD_M15,FastMAPeriod,0,MAMethod,MAPrice,MAShift+1);

if ((FastMA_1_15 > FastMA_2_15)) { MAfast_Trend_15 = "UP"; x = 256; color_indic = Lime; }

if ((FastMA_1_15 < FastMA_2_15)) { MAfast_Trend_15 = "DOWN"; x = 246; color_indic = Red; }

ObjectCreate("Trend_MAfast_15", OBJ_LABEL, WindowFind("xxxxxxx"), 0, 0);

ObjectSetText("Trend_MAfast_15",MAfast_Trend_15,7, "Verdana", color_indic);

ObjectSet("Trend_MAfast_15", OBJPROP_CORNER, 0);

ObjectSet("Trend_MAfast_15", OBJPROP_XDISTANCE, x);

ObjectSet("Trend_MAfast_15", OBJPROP_YDISTANCE, 52);

etc ...............

return(0);

}
 

Code Help? One Trade Only per Candle

I am trying to restrict my ea to taking one trade only per candle. I am finding that in price spikes against the trend I am getting multiple losing trades as the indicators are lagging.

I have seen the code before but I cant find it. If anyone could point me to an ea which has the correct code or show me how it is done.

It is done in the UniversalMa ea but it is not that clear to me there.

Any help would be appreciated.

 

It is here https://www.mql5.com/en/forum/173026

I am collecting all the functions on this thread https://www.mql5.com/en/forum/174329

 

Thanks Again

Hi NewDigital, as always thanks for your prompt reply.

cheers

 

Here's a few ways to simplify your code:

REPLACE INDIVIDUAL INDICATOR VALUES WITH FUNCTION

double FastMA_1_5 = iMA(NULL,PERIOD_M5,FastMAPeriod,0,MAMethod,MAPrice,MAShift);

double FastMA_1_15 = iMA(NULL,PERIOD_M15,FastMAPeriod,0,MAMethod,MAPrice,MAShift);

.... turn into this with an added function

maVal(5,1);

maVal(15,1);

THE FUNCTION THEY ARE CALLING IS BELOW:

double maVal(int tf, int shift)

{

return ( iMA(NULL,tf,FastMAPeriod,0,MAMethod,MAPrice,shift) );

}

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

Also replace other individual variables that you have like the string variables with a string array. Arrays will work very nicely in loops and will simplify your code because you have fewer declarations to make.

string MAfast_Trend_1, MAfast_Trend_5, MAfast_Trend_15;

.... becomes this.....

string MAfast_Trend [3];

Reason: