How to code? - page 74

 

Do you mean:

if ( ( CloseSell1_1 CloseSell2_2 ) || ( CloseSell3_1 > CloseSell3_2 ) ) Order = SIGNAL_CLOSESELL;

[/PHP]or do you mean:

[PHP]if ( ( CloseSell1_1 CloseSell2_2 || CloseSell3_1 > CloseSell3_2 ) ) Order = SIGNAL_CLOSESELL;

 

Thank you.

Now that I look at it, it was obvious. That did the trick. Initial backtest not so good. Time to tweak.

 
Big Be:
I need to know how to change the Stop for HALF of my open order. My understanding is that this means opening two orders, for example .2 lots and .2 lots.

My EA bases the number of lots on a Money Management calculation.

After the stop for one order is changed (based on a price level being reached) then I would let my exit code close both orders, unless their (now different) stops are hit.

The other order retains its original stop or possibly moves it up to Break Even.

If the initial quantity of lots (from the MM function) Is odd, instead of rounding down for an odd number of lots or tenth lots, I would like to split them unevenly between the two orders.

I believe this involves Magic Numbers, and a couple lines of code here and there. Maybe there is an EA with all this that I could copy from.

Thanks for any help.

Big Be

Hi there; you asked me explicitly about this elsewhere, but there has been some replies, and I don't know which parts of your problems might remain. It'll need a round where you ask again....

 

Hi Ralph,

ralph.ronnquist:
Hi there; you asked me explicitly about this elsewhere, but there has been some replies, and I don't know which parts of your problems might remain. It'll need a round where you ask again....

Well, none of the replies actually answered any of my questions - some were about my answers of others' questions.

So all parts remain. (See previous post for Quote of the issue I posted in this thread.)

Thanks,

Big Be

 

Problem with setting up Limit Order

Hey guys and gals,

I'm trying to set up the code in my EA to enter a trade at a specific price level (a limit order). This is the code for the limit order:

ticket=OrderSend(Symbol(),OP_BUYLIMIT,lots,Ask+10*Point,3,BuyStopLoss,0,"xx Buy",16384,0,Red);

lots & BuyStopLoss are predetermined calculated values, and they work with a regular market "OP_BUY" function when I switch it to that. Ask+10*Point is just an arbitrary value I came up with above the current price, I actually normally use BuyEntry which is also predetermined.

The error I get when I try to run the code in the Strategy Tester is:

"2008.02.24 16:00:08 2004.06.17 15:15 xxEA EURUSD,M15: OrderSend error 130" (which is a stoploss-related error)

Any ideas as to what's causing this error? I think there must be a problem with the way I'm setting up the limit order, or it can't execute limit orders in strategy tester (?) because it seems to work fine with a market order. Thanks for any help.

 

Expert Advisor Builder?

Lonestar:
I am relatively new to Metatrader, not to trading though, and have created some EAs using Expert Adviser Builder. Most work fine but am having trouble when I use multiple exits. Close(buy) logics and close (sell) logics with the OR function. Multiples with AND work fine, but it won't recognize any I create with OR. Below is the exit code.

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

//| Signal Begin(Exit Sell) |

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

if (CloseSell1_1 CloseSell2_2 || CloseSell3_1 > CloseSell3_2) Order = SIGNAL_CLOSESELL;

The bold part is the signal it is ignoring. Any ideas. This is the only thing holding me up from properly backtesting. If anyone can help and it backtests fine, you can have it. By just manually filtering out the trades that should be closed, it looks promising.

Thanks.

What is Expert Advisor Builder?

 
nondisclosure007:
What is Expert Advisor Builder?

Something like Gordago or this one

 

Varying lot size.

Hi,

Can I get the code for varying lot size for an EA ?

For example , for first sell order 0.2, second sell order 0.1 .

Regards,

SIDDESH

 
Linuxser:
Something like Gordago or this one

Thanks. I like Gordago for the strategy testing (w/out having to actually write an code). I need to mess w/ the templates it uses for my EA purposes. I find myself doing some edits on what it creates to meet my own coding styles. But all in all, I'm impressed.

I thought Gordago was a commercial product? I don't see how much it costs anywhere.

 

ERR_COMMON_ERROR #2 when opening trade

Hello All,

After the wonderful help the other day with the NewBar issues I was having I have learn't a huge amount and have progressed hugely with my learning EA I am programming. (Mainly as a learning excercise and a very basic system that I want to test (will undoubtebly not be profitable, but its a good learning exercise!)

Have written some script, each new bar, it closes all previous trades on current pair, then takes the 20-period ATR value and enters a buy stop and a sell stop to enter the market when it moves half of the way to the ATR value from market Open. The Take Profit is then set at the ATR value (my reckoning is that if it has gone half the way there, then it could be likely that from the average movement of the day, it will continue to hit the Take Profit. Probably totally wrong here, but want to program it anyway to try values - on demo account rather than Strategy Tester)

I have programmed it all and eventually worked out how to remove the extra digits after the decimal place using NormalizeDouble, but now when the EA tries to open a buy stop at the start of the bar I have ERR_COMMON_ERROR or Error #2.

This is REALLY unhelpful. I have checked the values that it is defining for Open, Take Profit and Stop Loss and these all seem reasonable and I can't work out what else it could be. It has been my frustration for the evening as no more feedback from the GetLastError than this! Please help.

ATR_Value = iATR(NULL,0,ATR_Period,0); //Get current ATR Value from chart

if (ATR_Value < (ATR_Minimum*Point)) //Check current ATR_Value to ensure it is no less than the ATR_Minimum set

{

Print("Too little range for trading. ATR_Minimum ",(ATR_Minimum*Point)," ATR_Value ",ATR_Value);

return(0);

}

double buyopen,nbuyopen,buysl,nbuysl,buytp,nbuytp,sellopen,nsellopen,sellsl,nsellsl,selltp,nselltp;

buyopen=((iOpen(NULL,0,0))+(ATR_Value*Open_Multiplier)+Open_Offset);

nbuyopen=NormalizeDouble(buyopen,Digits);

buysl=((iOpen(NULL,0,0))+(ATR_Value*SL_Multiplier)+SL_Offset);

nbuysl=NormalizeDouble(buysl,Digits);

buytp=((iOpen(NULL,0,0))+(ATR_Value*TP_Multiplier)+TP_Offset);

nbuytp=NormalizeDouble(buytp,Digits);

sellopen=((iOpen(NULL,0,0))-(ATR_Value*Open_Multiplier)-Open_Offset);

nsellopen=NormalizeDouble(sellopen,Digits);

sellsl=((iOpen(NULL,0,0))-(ATR_Value*SL_Multiplier)-SL_Offset);

nsellsl=NormalizeDouble(sellsl,Digits);

selltp=((iOpen(NULL,0,0))-(ATR_Value*TP_Multiplier)-TP_Offset);

nselltp=NormalizeDouble(sellsl,Digits);

Print("Open:",nbuyopen," TP:",nbuytp," SL:",nbuysl);

int ticketbuy;

ticketbuy=OrderSend(Symbol(),OP_BUYSTOP,Lots,nbuyopen,Max_Slippage,nbuysl,nbuytp,"Buy Order",12345,(Bar_Period-Bar_Offset),Green);

if(ticketbuy<0)

{

Print("Buy Order failed with error #",GetLastError());

return(0);

}

int ticketsell;

ticketsell=OrderSend(Symbol(),OP_SELLSTOP,Lots,nsellopen,Max_Slippage,nsellsl,nselltp,"Buy Order",54321,(Bar_Period-Bar_Offset),Red);

if(ticketsell<0)

{

Print("Buy Order failed with error #",GetLastError());

return(0);

}

Thanks so much for any help, I have also attached the mt4 if anyone doesn't mind having a look. It also contains parts of scripts from other people which, sorry I havn't credited, but they have all been posted around on this site. (Will ofcourse credit if I ever release EA, I am posting this just to try to solve this issue as it has been my evenings frustration.)

Howard

Files:
atr.mq4  6 kb
Reason: