How to code? - page 200

 

how is it possible in a simple calculation to round up to a result ?

 
dr.house7:
how is it possible in a simple calculation to round up to a result ?

Depends on what you want to do:

double MathRound( double value)

Returns value rounded to the nearest integer of the specified numeric value.

double MathFloor( double x)

The MathFloor function returns a numeric value representing the largest integer that is less than or equal to x.

double MathCeil( double x)

The MathCeil function returns a numeric value representing the smallest integer that exceeds or equals to x.

double NormalizeDouble( double value, int digits)

Rounds the floating point value to the given precision. Returns normalized value of the double type.

 

Hi,

I would like some help programming an additional input to this ea.

It is a basic grid/mart sys that places pending orders above and below the starting price at equal increments where the tp for buy orders is the same value as sl for sell orders and viceversa.

From what i can work out It currently calculates the tp/sl as (4 * pip increment) from the price at which you start the ea.

I would like an input which would allow me to adjust tp/sl by X number of pips.

ie (4 x pip increment) + X,

thanks for your help.

Files:
mgrid_ea.mq4  10 kb
 

Help wanted wait x-Bars

Hi all,

how you can program the following :

if close latest Order, wait x-Bars to open new Order ?

Thanks !

Regards

derumuro

 

Counting bars

I'm trying to get my EA to count the number of bars within a given period (i.e.; last 20 bars) that closed bullish and bearish. I came up with this while statement but it doesn't work, it always prints Bull Bars:0 Bear Bars:20. Any thoughts on what I am doing wrong?

// Count bull and bear bars

double open, close;

int bull_bars=0, bear_bars=0;

int bar_count=20; // Bars to count

if(Volume[0] == 1){ // Only check on open of new bar

int bars=0;

while(bars < bar_count){

open=iOpen(NULL,0,bars);

close=iOpen(NULL,0,bars);

if(open<close){bull_bars++;} else {bear_bars++;}

bars++;

}

Print("Bull Bars: ", bull_bars, " Bear Bars: ", bear_bars);

}

 

err, I figured it out. I changed my while to this and it works

while(bar_count > i){

open=iOpen(NULL,0,i);

close=iClose(NULL,0,i);

if(open<close){bull_bars++;}

if(open>close){bear_bars++;}

i++;

}

 

Need help in writing ea - Time factor to close order

if order took place, take profit=100pips & stop lost=100pips is written in the ea,

i would like to write additonal time factor(control) to close order as below:-

says the order is a buy order

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

1) if in 1st hour, a sudden price up of 80 pips happen in 10 minutes within this hour, close order;

2) if in 2nd hour, a sudden price up of 70 pips happen in 10 minutes within this hour, close order;

3) if in 3rd hour, a sudden price up of 60 pips happen in 10 minutes within this hour, close order;

4) if in 4th hour, profit at 50 pips, close order;

5) if in 1st hour, a sudden price down of 60 pips happen in 10 minutes within this hour, close order;

6) if in 2nd hour, a sudden price down of 70 pips happen in 10 minutes within this hour, close order;

7) if in 3rd hour, a sudden price down of 80 pips happen in 10 minutes within this hour, close order;

8) if in 4th hour, loses at 50 pips, close order;

Can somebody kindly help me to write this? I am having problem in writing time factor in closing order.

Thanks

Rgds,

 

Hi Guys,

I've a question for you....do you know what's the code to put in an Expert Advisor to close all open trades at certain time?...for example I've 5 open trades and at 16 GMT the EA should close all open trades and shouldn't open new trades until the next day.

Thanks for your help!

 

Hi mauro269,

if(Hour() = 16) close Order ( GMT = 16 +/- Servertime, example 16 +1 = 17) or see https://www.mql5.com/en/code/8075

and

if(Hour() = 8) open new Order

Here is more info: MQL4 Documentation

Regards

derumuro

 

On touch rather than on close

BBands_stop_v2 and ###Gann_HiLo_Activator_v2### - can someone enhance them please ?

There are few indicators that change their plot on touch - but rather most wait for the price to close past their current plot.

Exceptions are -

Parabolic SAR is one.

Bat ATR v2 is one on right setting (using CloseBase=false).

To me this means most indicators are less reliable.

The bigger the time frame the greater the risk. If you wait for a clear signal it is often at the other end of a breakout. If you take it - it is often the worst entry.

Can someone tweak BBands_stop_v2 and ###Gann_HiLo_Activator_v2### to have an extra settings like Bats_v2 does (using CloseBase=false), so they will change plot on touch, please?

The above two changes would be a good start - but the list of indicators that I think do not have this ability is huge

All_Bands_Stop

PriceChannel_Stop_v6.

All_Trendenvelopes.

TrendEnvelopes_v2.

MT4-LevelStop-Reverse-vB0-4.

#MTF_BBands_Stop_v1

ATRStops_v1.1_MTF

ATRStops_v1.1

mtfatrstops

BrainTrend1stopline

BrainTrend2Stopline

ChandelierStops V1

VolitilityPivot

VoltyChannel_Stop_v2

delta-stop

hi-lo_mod

MTF_BrainTrend1

NRTRATRStops

VoltiChannels

etc

etc.....