| New signals service! | |
|
|||||||
| Register in Forex TSD! | |
|
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time). Click here to register and get more information |
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
hi
![]() i'm new in MQL programming . does any body have this book ? Sergey Kovalyov's book named Programming in Algorithmic Language MQL4 published and supported by MetaQuotes Software Corp. when i download it from this link http://www.mql4.com/files/mql4bookenglish.chm it has nothing . thanks |
|
|||
|
Look at this thread: Sergey Kovalyov’s Book Is Now Downloadable!
__________________
My blog on TSD |
|
|||
|
Quote:
really thanks , for file opening instruction and download link ![]() |
|
|||
|
hello
i`m beginner with mt4 programming and now often i try to found a solution for commit variables from a void function to the mainprogram "start()" below you can see a sample and the question is , how can i commit value from variable "CountOpenSell", "CountOpenBuy","ProfitSell " and "ProfitBuy" to the start() - mainprogram......... i have added my suggestion (return`s in BOLD letters) but i do`nt know whether is it correct and how is the right code for the "start()" mainprogram??? sorry for my bad english and all of help thanks a lot regards forex2006 void CallBuySellProfit() { ProfitBuy=0; ProfitSell=0; CountOpenSell=0; CountOpenBuy=0; for (i=OrdersTotal()-1;i>=0;i--) {if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) { if (OrderType()==OP_SELL) {ProfitSell = ProfitSell + OrderProfit();CountOpenSell++;} if (OrderType()==OP_BUY) {ProfitBuy = ProfitBuy + OrderProfit();CountOpenBuy++;} } else Print( "Error when order select ", GetLastError()); } return(CountOpenSell); return(CountOpenBuy); return(ProfitSell); return(ProfitBuy); } |
|
|||
|
forex2006 programming help - return operator
Hi forex2006,
If really want to learn mql, I suggested you try codersguru tutorials, that's where I started. As for your question, an void function cannot return a value, if you want to get values out of void functions, you have to use global variables. The best way for you to get the values out is use an function that returns an value used with parameters to indicate which values you want. It's an simple example below. Try to avoid using global variables in functions as this could make it difficult for you later on. I hope it helps int start() { double ProfitBuy = CallBuySellProfit(OP_BUY,false); double ProfitSell = CallBuySellProfit(OP_SELL,false); int CountOpenBuy = CallBuySellProfit(OP_BUY,true); int CountOpenSell = CallBuySellProfit(OP_SELL,true); Comment( "ProfitBuy: "+DoubleToStr(ProfitBuy,2) +"\n"+ "ProfitSell: "+DoubleToStr(ProfitSell,2) +"\n"+ "CountOpenBuy: "+DoubleToStr(CountOpenBuy,2)+"\n"+ "CountOpenSell: "+DoubleToStr(CountOpenSell,2)+"\n"+ ""); return; } double CallBuySellProfit(int iOrderType, bool bCount) { double dProfit = 0; int iCount = 0; for (int i=OrdersTotal()-1;i>=0;i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) { if(OrderType()==iOrderType) { dProfit = dProfit + OrderProfit(); iCount++; } } else { Print( "Error when order select ", GetLastError()); } }//end for if(bCount)return(iCount); else return(dProfit); }//end CallBuySellProfit |
|
|||
|
matrixebiz, have you considered the possibility of a trade opening and closing in the same candle before the candle has closed? you should probably check the history list as well.
I've always port this little function I wrote to all my EAs, perhaps you may find it useful too. Code:
bool DecideToOpenTrade()
{
int total = OrdersTotal();
if (total > 0)
{
for(int cnt=0;cnt<total;cnt++)
{
if(OrderSelect(cnt,SELECT_BY_POS))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber() == EA_MAGIC_NUM)
{
return (false);
}
}
}
}
// in case trades has already opened and closed within the candle
int histotal = OrdersHistoryTotal();
if (histotal > 0)
{
for(cnt=0;cnt<histotal;cnt++)
{
if(OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber() == EA_MAGIC_NUM)
{
if (Time[0] <= OrderOpenTime()) // don't open a new position if we're still on the same candle
{
return (false);
}
}
}
}
}
return (true);
}
int start()
{
// some time check codes first.. blah blah
// ...
// ...
// ...
// check signals
if (Should_Buy())
{
if (DecideToOpenTrade())
{
//... trade opening codes here
}
}
if (Should_Sell())
{
if (DecideToOpenTrade())
{
//... trade opening codes here
}
}
}
Should_Buy() and Should_Sell() are functions I create in all my EAs to determine if a buy or sell signal has occurred. hope this helps. PM me if you need further clarifications. regards, Zen |
|
||||
|
Quote:
I think this will do me fine just probably need to make a few changes because my EA is a multi currency trading EA so that is why I wasn't able to check for a specific currency not knowing which currency pair the EA had traded with, hence the reason why the code I have to change to look for a specific OrderComment() instead of what you have OrderSymbol(). I was using this code below to check if trades already existed currently but was having trouble with checking if trades were already closed on the the same bar.for(int i=totalorders-1;i>=0;i--) { OrderSelect(i, SELECT_BY_POS); if (OrderComment() == EA_Name + MagicNumber) GoOrders = false; } if (GoOrders){orders();} Last edited by matrixebiz; 11-11-2008 at 07:37 PM. |
![]() |
| Bookmarks |
| Tags |
| forex, trendenvelopes_v3 |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| MT4 (Basic) Questions | stepwise | Metatrader 4 | 6 | 09-22-2008 03:22 AM |
| Basic Indicator Question | waaustin | Metatrader Programming | 8 | 04-02-2008 03:54 PM |
| Need Help Understanding Basic MQL logic | Emerald King | Expert Advisors - Metatrader 4 | 7 | 02-27-2007 10:59 AM |
| Very basic coding help needed | camisa | Questions | 1 | 05-08-2006 06:36 PM |