Forex
Google
New signals service!

Go Back   Forex Trading > Metatrader Training > Metatrader 4 mql 4 - Development course > Questions


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

Reply
 
LinkBack Thread Tools Display Modes
  #71 (permalink)  
Old 10-08-2008, 05:46 PM
Junior Member
 
Join Date: Mar 2006
Posts: 26
macd&rsi is on a distinguished road
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
Attached Images
File Type: jpg metatrader.jpg (20.2 KB, 76 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #72 (permalink)  
Old 10-08-2008, 05:58 PM
Administrator
 
Join Date: Sep 2005
Posts: 16,815
Blog Entries: 145
newdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud of
Look at this thread: Sergey Kovalyov’s Book Is Now Downloadable!
__________________
My blog on TSD
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #73 (permalink)  
Old 10-08-2008, 08:44 PM
Junior Member
 
Join Date: Mar 2006
Posts: 26
macd&rsi is on a distinguished road
Quote:
Originally Posted by newdigital View Post

really thanks , for file opening instruction and download link
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #74 (permalink)  
Old 10-21-2008, 05:31 AM
marcelcorzo's Avatar
Senior Member
 
Join Date: Oct 2007
Location: Colombia
Posts: 119
marcelcorzo is on a distinguished road
10points3

PLEAASEEE, PROGRAMMERS!

We need in 10points3 EA, that when the third trade opens, the first one closes, I'm trying but it's still closing all positions.
actually we have:

if (PreviousOpenOrders>OpenOrders)
{
for(cnt=OrdersTotal();cnt>=0;cnt--)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
mode=OrderType();
if (OrderSymbol()==Symbol() && OrderMagicNumber() == Magic)
{
if (mode==OP_BUY) { OrderClose(OrderTicket(),OrderLots(),OrderClosePri ce(),slippage,Blue); }
if (mode==OP_SELL) { OrderClose(OrderTicket(),OrderLots(),OrderClosePri ce(),slippage,Red); }
return(0);
}

I was thinking to do this:
1. change magic number for the first trade when second one opens, for example magicnumber+1
2. when third trade opens, close the first one, with the magicnumber+1 assigned.
Am I right?
or which other way I can identify the first trade opened to close it later?

If you can guide me or make the changes, better because I'm not a programmer, I'm just learning.

This change would be the start of the Holly Grail!!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #75 (permalink)  
Old 10-21-2008, 05:32 AM
marcelcorzo's Avatar
Senior Member
 
Join Date: Oct 2007
Location: Colombia
Posts: 119
marcelcorzo is on a distinguished road
10points3

Sorry, the EA.
ANd it's in this thread:
10points 3.mq4

Thanks!
Attached Files
File Type: mq4 10p3v0.03.mq4 (11.1 KB, 2 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #76 (permalink)  
Old 11-08-2008, 12:36 AM
Junior Member
 
Join Date: Jan 2006
Posts: 20
forex2006 is on a distinguished road
Angry programming help - return operator

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);

}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #77 (permalink)  
Old 11-08-2008, 08:36 AM
Junior Member
 
Join Date: Oct 2006
Posts: 2
bobfourie is on a distinguished road
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #78 (permalink)  
Old 11-11-2008, 12:16 PM
matrixebiz's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 1,174
matrixebiz is on a distinguished road
Stop EA trading on the same bar

Hello, anyway to put code so that the EA checks if trades were already placed on that bar then to not place anymore trades until a new bar?
Thank you
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #79 (permalink)  
Old 11-11-2008, 03:43 PM
Junior Member
 
Join Date: Nov 2008
Posts: 3
Zen_Leow is on a distinguished road
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
      }
   }

}
note: this function assumes you've set a unique value to EA_MAGIC_NUM. That way the check won't look at trades opened by other EAs.
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #80 (permalink)  
Old 11-11-2008, 05:43 PM
matrixebiz's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 1,174
matrixebiz is on a distinguished road
Quote:
Originally Posted by Zen_Leow View Post
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
      }
   }

}
note: this function assumes you've set a unique value to EA_MAGIC_NUM. That way the check won't look at trades opened by other EAs.
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
Thank you Zen 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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Tags
forex, trendenvelopes_v3

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

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


All times are GMT. The time now is 04:05 AM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.