How to code? - page 41

 

More EA's

Can only upload 5 ea.s at a time.

Files:
kehedge.mq4  12 kb
 

How write "If last trade was winnig"

In an EA how write "If last trade was winning" (for this pair) then ...

Thx for help.

Jo

 

about MarketInfo()

hello to everyone!

//

double A = MarketInfo("EURUSD",MODE_BID);

doube B = MarketInfo("USDJPY",MODE_BID);

double C = MarketInfo("EURJPY",MODE_BID);

init()

{

A = MarketInfo("EURUSD",MODE_BID);

B = MarketInfo("USDJPY",MODE_BID);

C = MarketInfo("EURJPY",MODE_BID);

}

int start()

{

...

}

//

why does those codes not works? when complies,that comes to so many errors:

'MarketInfo' - initialization expected

'A' - variable not defined ...

.....and so on

 

This worked for me

Jovager:
In an EA how write "If last trade was winning" (for this pair) then ...

Thx for help.

Jo

double LotsOptimised()

{

double lots = InitialLots;//default lots 0.1 - there will be no error if lots will not be set by the other part of the code

// int total = OrdersHistoryTotal();

for(int i=0;i<OrdersHistoryTotal();i++) // scan all closed / cancelled transactions

{

OrderSelect(i, SELECT_BY_POS, MODE_HISTORY );

if(OrderSymbol() == Symbol()&& OrderMagicNumber()==MagicNumber)

{

if(OrderProfit()<0)

{

lots = NormalizeDouble(OrderLots() * LotsFactor,2);

}

else

{

lots=InitialLots;

}

}

}

return(lots);

}

I used this to check if the last closed trade was a winner or not. If not I martingaled the lots. Hope it helps.

 
Sendra:
Hi, everyone

I tried to create an EA, and I got the following error message:

'\end_of_program' - ending bracket '}' expected C:\...\My_First_EA.mq4(96,1)

I double-clicked it, get to the line, then check it with opening-ending brackets prior to it, and still don't know where I made mistake.

This is the second EA I tried, with the same error message, based on the same indicator.

Thank you.

Sendra, send the program to my email address as an attachment and I will look at it and try to fix it. Normally the problem is a bracket missing after a statement. Unfortunately, this is a low level language and because it is a basic language, it cannot tell you exactly where the error is many times, so it defaults to the error it is showing you. Only experience in coding will help in troubleshooting this type of error.

Dave

<<<

ddiebold7@aol.com

 

Ralph, HELP with some Daily Close logic

Hello Ralph.

Perhaps, if you wouldn't mind a bit of guidance. This has been a bit of a challenge for me to figure out!! I want to define some conditions for the EA to look at to determine whether or not to close an open trade. Let's just use a buy order as an example (I know Sell order would be the opposite logic). So, I have an Buy order opened on a Monday. I want the EA to look at the Daily Close over the next X # of days. If the Daily Close on each of the next X number of days (let's say 5 days for example) is lower than the Order Open price of the trade, then I want the EA to execute an OrderClose to closeout the trade. I was also thinking another possible part of this condition I might want the EA to look at is if the Daily close over each of the next X number of days was lower than the previous days close. Also too, My EA runs on the one hour time frame.

I hope I explained what I want to accomplish clearly enough for you to understand.

Thanks in advance for your help.

 

Coding Help Please

I'm not asking for the coding of an EA, just a little help with one problem.

What I would like to code is this, if I have an open long order I want to be able to call the Highest quoted price that the order has seen since that specific long order opened. Obviously, when the order first opens, the open price would be returned. If the order increases by 20 pips, the price of OrderOpenPrice() + 20 pips would be returned. If the price then decreases by 10 pips, the price OrderOpenPrice() + 20 would still be the returned value. I know this can be done within a specific bar by using OrderOpenPrice() + High[0], but when a new bar is formed, High[0] becomes High[1]. I will also use the same logic in reverse to return the lowest value a specific short order has seen. When the order closes, the returned values will re-set to zero.

I'm having trouble figuring this one out, can anyone help?

Thank You!

 

Save the current bar's highest quoted value to a variable. Every time you get another quote, compare it with the value of the variable. If the new value is higher, save it to the variable. If the new value is lower, keep the variable the same.

if(variable < newquote)

variable = newquote;

Hope that helps!

 
jimven:
Save the current bar's highest quoted value to a variable. Every time you get another quote, compare it with the value of the variable. If the new value is higher, save it to the variable. If the new value is lower, keep the variable the same.

if(variable < newquote)

variable = newquote;

Hope that helps!

Thank you for the help, I have one question though. What happens when the current bar is no longer the bar that the order opened in? What if the order opened in the bar 5 bars ago? Now I want the highest quoted value of 5 bars, the highest quoted price since the order opened. Will this still work?

Thanks

Reason: