Ask! - page 148

 

Can anyone help me to better understand how to modify code to allow EA to execute simultaneous orders in several instances (in other words I am testing the same EA, on several pairs at once, and am using different magic numbers for each instance.)

The original code includes this:

int total=OrdersTotal();

if(total<1)

And I think this is where the problem is. If I increase the number, it merely executes several orders on the same bar (M15) for the same pair. If left if(total<1), then it will not allow for simultaneous orders on different pairs.

Can I change something about the tick or bar to allow only one order at a time per pair, but several orders for all pairs that have EA (with different magic number) attached??

Thanks to anyone who can help or offer input!

Chili

 

Confused on multiple if statements

/////////////////////START TRADING ON SUNDAY/////////////////////////

StartDay=7; StartHour=1; StartMinute=55;

{

if(TimeDayOfWeek(TimeCurrent())==StartDay)

{

if(TimeHour(TimeCurrent())==StartHour)

{

if(TimeMinute(TimeCurrent())==StartMinute)

{

}

}

}

}

I am trying to get my EA to activate when day seven roles around (Day 7), and Hour 1 roles around, and 55 minutes roles around. What am I doing wrong. Today I started up the computer and the EA started trading right away (before hour 1)!. Please assist.

Thanks!

Dave

 
JForex78:
Hi,

I want to know how do I plot a Lower Timeframe MA cross on a Higher Timeframe chart.

e.g. I want to plot an arrow on H1 chart when M15 's MA5 and MA10 cross.

Please let me know.

Thanks,

JForex.

An MA on any chart is just a higher/lower version of an MA on a higher/lower time frame. For example if you put a 60MA on a 5 min chart but want to see what it looks like on an hour chart you would just multiply 60 by 12 (5 min intervals in an hour). So a 720 MA on an hour chart is the same as a 60 MA on a 5 min chart.

Make sense?

Lux

 
1Dave7:
/////////////////////START TRADING ON SUNDAY/////////////////////////

StartDay=7; StartHour=1; StartMinute=55;

{

if(TimeDayOfWeek(TimeCurrent())==StartDay)

{

if(TimeHour(TimeCurrent())==StartHour)

{

if(TimeMinute(TimeCurrent())==StartMinute)

{

}

}

}

}

I am trying to get my EA to activate when day seven roles around (Day 7), and Hour 1 roles around, and 55 minutes roles around. What am I doing wrong. Today I started up the computer and the EA started trading right away (before hour 1)!. Please assist.

Thanks!

Dave

Take another look at the help file.

Returns the current zero-based day of the week (0-Sunday,1,2,3,4,5,6) of the last known server time.

Lux

 
Chilibowl:
Can anyone help me to better understand how to modify code to allow EA to execute simultaneous orders in several instances (in other words I am testing the same EA, on several pairs at once, and am using different magic numbers for each instance.)

The original code includes this:

int total=OrdersTotal();

if(total<1)

And I think this is where the problem is. If I increase the number, it merely executes several orders on the same bar (M15) for the same pair. If left if(total<1), then it will not allow for simultaneous orders on different pairs.

Can I change something about the tick or bar to allow only one order at a time per pair, but several orders for all pairs that have EA (with different magic number) attached??

Thanks to anyone who can help or offer input!

Chili

OrdersTotal is a built in function that doesn't consider magic number. You need to write your own function that utilizes OrdersTotal but filters by magic number and probably symbol too. There's plenty of examples around here and elsewhere.

Good luck.

Lux

 
luxinterior:
Take another look at the help file. Lux

I changed the StartDay to 0, and changed the StartHour to the current GMT hour of my broker, and changed the StartMinute to 5 minutes ahead of GMT minutes - It still does work right when the GMT time matches my start time. I looked at the help files and they do not show a multiple if statement. Multiple if statement always confuses me. What the heck am I doing wrong? I want the program to not trade until the appropriate start time on Sunday, and make a comment "Non-Trading Time" until the time = the start on Sunday time.

Highly confused!!

?????

 
luxinterior:
OrdersTotal is a built in function that doesn't consider magic number. You need to write your own function that utilizes OrdersTotal but filters by magic number and probably symbol too. There's plenty of examples around here and elsewhere.

Good luck.

Lux

Here is one I made and have used quite a bit:

int OTBM(int intMagic)//OrdersTotalByMagic

{

int intCount=0;

int intPOS=0;

bool boolTerm=false;

while(boolTerm==false)

{

if(OrderSelect(intPOS,SELECT_BY_POS))

{

if(OrderMagicNumber()==intMagic) intCount++;

intPOS++;

}

else

boolTerm=true;

}

return(intCount);

}

[/PHP]

And if you want to close only a certain order by magic number:

int CBM(int intMagic)//CloseByMagic

{

int intOffset=0;

int Count = OTBM(intMagic);

while(OTBM(intMagic)>0 && Count > 0)

{

OrderSelect(intOffset,SELECT_BY_POS);

if(OrderMagicNumber()==intMagic)

{

if(OrderType()==OP_BUY) OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),999,Red);

else if(OrderType()==OP_SELL) OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),999,Orange);

Count--;

}

else {

intOffset++;

}

}

return(0);

}

Order Profit By Magic:

[PHP]double OPBM(int intMagic)//OrderProfitByMagic

{

double dblProfit=0;

int intPOS=0;

bool boolTerm=false;

while(boolTerm==false)

{

if(OrderSelect(intPOS,SELECT_BY_POS))

{

if(OrderMagicNumber()==intMagic) dblProfit=dblProfit+OrderProfit();

intPOS++;

}

else

boolTerm=true;

}

return(dblProfit);

}

Hope that helps.

 
luxinterior:
An MA on any chart is just a higher/lower version of an MA on a higher/lower time frame. For example if you put a 60MA on a 5 min chart but want to see what it looks like on an hour chart you would just multiply 60 by 12 (5 min intervals in an hour). So a 720 MA on an hour chart is the same as a 60 MA on a 5 min chart.

Make sense?

Lux

Totally makes sense. How will you see a M5 10MA on a H1 chart?

10/12=0.84. Can you put a 0.84 MA on a H1 chart? No.

It works the other way though - H1 10MA = M5 120MA.

So my question is, how do I see a cross of 5MA on a higher Timeframe like H4.

Thanks.

 
 

for Loop on MQL4

While reading the MQL4 Course by Coders' Guru I came across this part on 'for' loop in Lesson 5 that I'm confused. It says there can be one test expression only. But the examples shown contain 2 test expressions.

int i;

int j;

for(i=0,j=0;i<15,i<;i++,j++)

Print(i);

int i;

for(i=15;i>0,i<;i--)

Print(i);

Cld someone kindly enlighten?

Thanks.

Reason: