MQL4 Learning - page 85

 

Multi Order at the same time~Need your help

Hi Expert,

i was trying to create a script.

Feature of the script:-

1. Open multi oder ( Buy and Sell ) at the same time for 9 Pair

2. Set takeprofit as i like

3. Put Stoploss as 0

Problem facing:-

1. It was not active for all pair

Script:-

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

#include

#include

extern double Lots = 0.10; // change this number to change the lotsize

extern double stoploss = 100; // change this number to change the stoploss

extern double takeprofit = 100; // change this number to change the takeprofit

//OrderSend("EURUSD",OP_BUY,0.1,MarketInfo("EURUSD",MODE_ASK),3,MarketInfo("EURUSD",MODE_ASK)-stoploss*Point,MarketInfo("EURUSD",MODE_ASK)+takeprofit*Point,"",1234567,0,Blue);

//OrderSend("EURUSD",OP_SELL,0.1,MarketInfo("EURUSD",MODE_BID),3,MarketInfo("EURUSD",MODE_BID)+50*Point,MarketInfo("EURUSD",MODE_BID)-50*Point,"",MAGICMAeu,0,Red)

//OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Ask+stoploss*Point,Ask-takeprofit*Point,"JMSELLER",0,0,CLR_NONE);

int start()

{

OrderSend("EURUSD",OP_BUY,Lots,MarketInfo("EURUSD",MODE_ASK),3,MarketInfo("EURUSD",MODE_ASK)-50*Point,MarketInfo("EURUSD",MODE_ASK)+12*Point,"",0,0,Blue);

OrderSend("EURUSD",OP_SELL,Lots,MarketInfo("EURUSD",MODE_BID),3,MarketInfo("EURUSD",MODE_BID)+50*Point,MarketInfo("EURUSD",MODE_BID)-12*Point,"",0,0,Red);

OrderSend("USDCHF",OP_BUY,Lots,MarketInfo("USDCHF",MODE_ASK),3,MarketInfo("USDCHF",MODE_ASK)-50*Point,MarketInfo("USDCHF",MODE_ASK)+13*Point,"",0,0,Blue);

OrderSend("USDCHF",OP_SELL,Lots,MarketInfo("USDCHF",MODE_BID),3,MarketInfo("USDCHF",MODE_BID)+50*Point,MarketInfo("USDCHF",MODE_BID)-13*Point,"",0,0,Red);

OrderSend("USDJPY",OP_BUY,Lots,MarketInfo("USDJPY",MODE_ASK),3,MarketInfo("USDJPY",MODE_ASK)-50*Point,MarketInfo("USDJPY",MODE_ASK)+12*Point,"",0,0,Blue);

OrderSend("USDJPY",OP_SELL,Lots,MarketInfo("USDJPY",MODE_BID),3,MarketInfo("USDJPY",MODE_BID)+50*Point,MarketInfo("USDJPY",MODE_BID)-12*Point,"",0,0,Red);

OrderSend("AUDUSD",OP_BUY,Lots,MarketInfo("AUDUSD",MODE_ASK),3,MarketInfo("AUDUSD",MODE_ASK)-50*Point,MarketInfo("AUDUSD",MODE_ASK)+13*Point,"",0,0,Blue);

OrderSend("AUDUSD",OP_SELL,Lots,MarketInfo("AUDUSD",MODE_BID),3,MarketInfo("AUDUSD",MODE_BID)+50*Point,MarketInfo("AUDUSD",MODE_BID)-13*Point,"",0,0,Red);

OrderSend("GBPUSD",OP_BUY,Lots,MarketInfo("GBPUSD",MODE_ASK),3,MarketInfo("GBPUSD",MODE_ASK)-50*Point,MarketInfo("GBPUSD",MODE_ASK)+13*Point,"",0,0,Blue);

OrderSend("GBPUSD",OP_SELL,Lots,MarketInfo("GBPUSD",MODE_BID),3,MarketInfo("GBPUSD",MODE_BID)+50*Point,MarketInfo("GBPUSD",MODE_BID)-13*Point,"",0,0,Red);

OrderSend("EURJPY",OP_BUY,Lots,MarketInfo("EURJPY",MODE_ASK),3,MarketInfo("EURJPY",MODE_ASK)-50*Point,MarketInfo("EURJPY",MODE_ASK)+13*Point,"",0,0,Blue);

OrderSend("EURJPY",OP_SELL,Lots,MarketInfo("EURJPY",MODE_BID),3,MarketInfo("EURJPY",MODE_BID)+50*Point,MarketInfo("EURJPY",MODE_BID)-13*Point,"",0,0,Red);

OrderSend("CHFJPY",OP_BUY,Lots,MarketInfo("CHFJPY",MODE_ASK),3,MarketInfo("CHFJPY",MODE_ASK)-50*Point,MarketInfo("CHFJPY",MODE_ASK)+14*Point,"",0,0,Blue);

OrderSend("CHFJPY",OP_SELL,Lots,MarketInfo("CHFJPY",MODE_BID),3,MarketInfo("CHFJPY",MODE_BID)+50*Point,MarketInfo("CHFJPY",MODE_BID)-14*Point,"",0,0,Red);

OrderSend("AUDJPY",OP_BUY,Lots,MarketInfo("AUDJPY",MODE_ASK),3,MarketInfo("AUDJPY",MODE_ASK)-50*Point,MarketInfo("AUDJPY",MODE_ASK)+16*Point,"",0,0,Blue);

OrderSend("AUDJPY",OP_SELL,Lots,MarketInfo("AUDJPY",MODE_BID),3,MarketInfo("AUDJPY",MODE_BID)+50*Point,MarketInfo("AUDJPY",MODE_BID)-16*Point,"",0,0,Red);

OrderSend("GBPJPY",OP_BUY,Lots,MarketInfo("GBPJPY",MODE_ASK),3,MarketInfo("GBPJPY",MODE_ASK)-50*Point,MarketInfo("GBPJPY",MODE_ASK)+17*Point,"",0,0,Blue);

OrderSend("GBPJPY",OP_SELL,Lots,MarketInfo("GBPJPY",MODE_BID),3,MarketInfo("GBPJPY",MODE_BID)+50*Point,MarketInfo("GBPJPY",MODE_BID)-17*Point,"",0,0,Red);

}

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

Expert need your help~ Please help me to modify it~

Files:
jmbuyerv2.mq4  6 kb
 
 

Newbie question: why Alert function not working?

I only add follow two lines to the "Start()" function.

Alert("hsdfsdfsdlfsdfsd");

Print("hsdfsdfsdlfsdfsd");

This is simple enough, alert didnt show up and I checked "expert" tab, log not there.

Do I need to set some options to enable alert and print function?

 

Library file problem

I have a strange problem with a library file.

I have an EA which uses the LibOrderReliable_V1_1_4

library file by Matthew Kennel.

This file and the stdlib file are in the folder

"C:\Program Files\MT4\experts\libraries".

I can open both files from this location in MetaEditor.

The first lines of the EA are -

#include

#include

#include

When I compile the EA, I get the error message -

'LibOrderReliable_v1_1_4.mqh' - cannot open the program file

Does anyone know why this is so, when there is no problem opening stdlib.mqh?

 
apres:
I have a strange problem with a library file.

I have an EA which uses the LibOrderReliable_V1_1_4

library file by Matthew Kennel.

This file and the stdlib file are in the folder

"C:\Program Files\MT4\experts\libraries".

I can open both files from this location in MetaEditor.

The first lines of the EA are -

#include

#include

#include

When I compile the EA, I get the error message -

'LibOrderReliable_v1_1_4.mqh' - cannot open the program file

Does anyone know why this is so, when there is no problem opening stdlib.mqh?

Hi Apres,

I needed that file for my EA also and I ended up finding out that I actually needed two files:

1) 'LibOrderReliable_v1_1_4.mqh' - I put the "mqh" file in the "expert\includes" folder

2) Then I needed a "mq4" file also

'LibOrderReliable_v1_1_4.mq4'

I put this file in the "experts\library" folder:

'LibOrderReliable_v1_1_4.mq4 --> compile to "exe" file

Now run your EA and it should work.

Search this TSD site or the web if you need to find the files (I only have an earlier version).

Hope this helps,

Robert

 

How to stop "not enough money"

i understand there's lack of margin to allow the ticket to be accepted.

How do i end the cycle and wait for the current trades to close and stop the "Not enough money"? break; somewhere? im using martingale to a trade limit

My order send sell then buy:

void OpenMarketOrders()

{

int cnt=0;

int err=0;

if (myOrderType==1 && ContinueOpening)

{

if ((Bid-LastPrice)>=Pips*Point || OpenOrders<1)

{

SellPrice=Bid;

LastPrice=0;

if (TakeProfit==0) { tp=0; }

else { tp=SellPrice-TakeProfit*Point; }

if (StopLoss==0) { sl=0; }

else { sl=SellPrice+StopLoss*Point; }

if (OpenOrders!=0)

{

mylotsi=lotsi;

for(cnt=0;cnt<OpenOrders;cnt++)

{

if (Lots<0.1) { mylotsi=NormalizeDouble(mylotsi*multiply,2); }

else { mylotsi=NormalizeDouble(mylotsi*multiply,1); }

}

} else { mylotsi=lotsi; }

if (mylotsi>100) { mylotsi=100; }

RefreshRates();

ticket=OrderSend(Symbol(),OP_SELL,mylotsi,SellPrice,slippage,0,0,Comments,MagicNumber,0,ArrowsColor);

if(ticket>0)

{

OrderSelect(ticket,SELECT_BY_TICKET);

OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,ArrowsColor);

err=GetLastError();

if(err==0 || err==4 || err==136 || err==137 || err==138 || err==146) //Busy errors

{

Sleep(5000);

}

else

{

Print("OrderSend failed with error #",GetLastError());

}

}

return(0);

}

}

if (myOrderType==2 && ContinueOpening)

{

if ((LastPrice-Ask)>=Pips*Point || OpenOrders<1)

{

BuyPrice=Ask;

LastPrice=0;

if (TakeProfit==0) { tp=0; }

else { tp=BuyPrice+TakeProfit*Point; }

if (StopLoss==0) { sl=0; }

else { sl=BuyPrice-StopLoss*Point; }

if (OpenOrders!=0) {

mylotsi=lotsi;

for(cnt=0;cnt<OpenOrders;cnt++)

{

if (Lots<0.1) { mylotsi=NormalizeDouble(mylotsi*multiply,2); }

else { mylotsi=NormalizeDouble(mylotsi*multiply,1); }

}

} else { mylotsi=lotsi; }

if (mylotsi>100) { mylotsi=100; }

RefreshRates();

ticket=OrderSend(Symbol(),OP_BUY,mylotsi,SellPrice,slippage,0,0,Comments,MagicNumber,0,ArrowsColor);

if(ticket>0)

{

OrderSelect(ticket,SELECT_BY_TICKET);

OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,ArrowsColor);

err=GetLastError();

if(err==0 || err==4 || err==136 || err==137 || err==138 || err==146) //Busy errors

{

Sleep(5000);

}

else

{

Print("OrderSend failed with error #",GetLastError());

}

}

return(0);

}

}

}

 

Why not just check the margin at the beginning of the fucntion and if it's less than the required amount return.

Lux

 

isnt that a harder way to go about it being theres multi trades open?

or whats the code for testing FreeMargin to place (noob)

what about...

if(err==0 || err==4 || err==136 || err==137 || err==138 || err==146) //Busy errors

{

Sleep(5000);

}

else

{

Break; //--where do i put the While loop()?

}

}

return(0);

}

}

}

 

There's a few functions regarding free margin such as AccountMargin( ) . Take a look in the help file and see which one best fits your needs.

Lux

 

A little help

I am new to programming, i've spent a lot of time trying to figure out how to make this work. Can anyone code an ex.4 so that the moving averages on the file I have attached will show up on one graph for different TF's?

Any help would be greatly appreciated.

Files:
jbird_mas.mq4  3 kb