How to code? - page 314

 

Offline Chart Expert Advisor

Hello,

i created an Expert Advisor for an offline chart that looks like the following code:

int init()

{

start();

return(0);

}

int start()

{

while (!IsStopped())

{

RefreshRates();

//execution code

Sleep(1000);

//print each 5 mins a message "i am alive"

}

}

After some minutes the message "i am alive" was stopped.

Is there is something i can do about it or as i read in some other topics, it is a problem of every offline chart EA?

Thank you very much

 

how to add a new bar sound?

I need a simple customization of an ea i have.

This EA is RangeBars EA and i need insert just an option, the opportunity of play a sound when a new bar is plotted on chart.

Also i need the chance of enable/disable this feature and choose the filename of the sound.

Please somebody can tell me how to do that?

rangebars.zip

Files:
rangebars.zip  11 kb
 

Use information from M15 to enter or exit trade on M5

I want to calculate MA or other technical indicator on higher time frame to make decision to enter or exit trade in lower time frame. I do not want to specify period in indicator. I try to use PERIOD_M15 or other but the value not correct when compare to the real one.

 

...

If you use it like this :

iMA(NULL,PERIOD_M15,CalculatingPeriod,0,CalculatingMethod,CalculationPrice,Shift);

[/PHP]

it has to return the correct value. Here is an example of a 15 minute 14 period EMA of close of the first closed bar

iMA(NULL,PERIOD_M15,14,0,MODE_EMA,PRICE_CLOSE,1);

If you want to use that from back-tests then you have to add one thing :

[PHP] y = iBarShift(NULL,PERIOD_M15,Time[shift]);

iMA(NULL,PERIOD_M15,14,0,MODE_EMA,PRICE_CLOSE,y+1);

where shift is the number of the bar of the time frame you are testing

Premeus:
I want to calculate MA or other technical indicator on higher time frame to make decision to enter or exit trade in lower time frame. I do not want to specify period in indicator. I try to use PERIOD_M15 or other but the value not correct when compare to the real one.
 

Thank you mladen, I am not sure it's must get the correct value or not.

 

Buy_Script / How to code

Hi coders

whats to do, when I will have more tickets ?

where I must insert ticket_2; ticket_3 and ...

how to code ?

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

//| script program start function |

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

int start()

{

int ticket_1;

if(Digits < 4)

{

PointValue = 0.01;

iDigits = 2;

}

else

{

PointValue = 0.0001;

iDigits = 4;

}

Thanks for help

 

How to prevent EA from working during MT4 startup

Hi Mladen,

A few days ago after rebooting my VPS, I restarted MT4. However, an EA on the platform accidentally closed some trades that should not have been closed, due to unstable data during MT4 start up. Can you please suggest some codes that I can insert in my EA to prevent this from happening ?

Thanks in advance

pooh

 

...

pooh123

First that comes into mind is to prevent it from working on a first tick it receives

That could be done if you place something like this at the beginning of the start

static bool firstTime=true; if (firstTime) { firstTime = false; return(0); }

But I am not 100% sure that it will prevent all errors like the one you had (when it starts to download data for example that can get lengthy - what to do then). If I come up with a better idea will post it here

pooh123:
Hi Mladen,

A few days ago after rebooting my VPS, I restarted MT4. However, an EA on the platform accidentally closed some trades that should not have been closed, due to unstable data during MT4 start up. Can you please suggest some codes that I can insert in my EA to prevent this from happening ?

Thanks in advance

pooh
 
mladen:
pooh123

First that comes into mind is to prevent it from working on a first tick it receives

That could be done if you place something like this at the beginning of the start

static bool firstTime=true; if (firstTime) { firstTime = false; return(0); }
But I am not 100% sure that it will prevent all errors like the one you had (when it starts to download data for example that can get lengthy - what to do then). If I come up with a better idea will post it here

Thank you Mladen for the prompt reply. This is helpful.

pooh

 

Hi.

There is a function that allow me to calculate this operation?

x^0,5 (x= know value)

And another question.

I have 5 digit broker. It is possible to get only the firt 4 decimal of know value? Thank you

Thank you

Reason: