Forex
Google
New signals service!

Go Back   Forex Trading > Programming > Metatrader Programming


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 (1) Thread Tools Display Modes
  #691 (permalink)  
Old 02-13-2008, 09:25 PM
Member
 
Join Date: Sep 2007
Posts: 68
Ronald Raygun is on a distinguished road
Move Stop Once

Here is my bit of code for moving the stoploss to breakeven after a certain profit. Is there anything wrong with it?

Code:
            //MoveOnce
            if(MoveStopOnce && MoveStopWhenPrice > 0) {
               if(Bid - OrderOpenPrice() == Point * MoveStopWhenPrice) {
                  OrderModify(OrderTicket(),OrderOpenPrice(), Bid - Point * MoveStopTo, OrderTakeProfit(), 0, Red);
                     if (!EachTickMode) BarCount = Bars;
                     continue;
                  }
               }
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #692 (permalink)  
Old 02-14-2008, 10:44 AM
Junior Member
 
Join Date: Apr 2007
Posts: 17
la totona is on a distinguished road
People that can help:

The code for the previous bar is below:

//to buy
double indicatorpast = icustom(....................,1);
double indicatornow = icustom(....................,0);


if (close[1]<indicatorpast && close[0]>indicatornow) OpenBUY();
if (close[1]>indicatorpast && close[0]<indicatornow) OpenSELL();

but with this satatement, the expert opens positions not only when the price cross the indicator, it opens position above the indicator too. I want that the expert open position ONLY when it cross the indicator, so i tried that:

//to buy
double indicatorpast = icustom(....................,1);
double indicatornow = icustom(....................,0);

if (close[1]<indicatorpast && close[0]==indicatornow) OpenBUY();
if (close[1]>indicatorpast && close[0]==indicatornow) OpenSELL();

But this statement it is not performing.

Do you know what is happen? Because i think there arent errors in the statement.

The question is why is not opening at the exact point of cross when close[0]==Indicatornow? If the function would be with ==, we will prevent the open of orders above the point of crooss between the indicator and the close of the present bar but is not funtioning with this type of relationship between the variables.

Do you have experimented the same problem? Abyone knows how resolve it?
Thanks, again.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #693 (permalink)  
Old 02-14-2008, 11:07 AM
Senior Member
 
Join Date: Jan 2006
Posts: 1,119
omelette is on a distinguished road
Quote:
Originally Posted by la totona View Post
People that can help:

The code for the previous bar is below:

//to buy
double indicatorpast = icustom(....................,1);
double indicatornow = icustom(....................,0);


if (close[1]<indicatorpast && close[0]>indicatornow) OpenBUY();
if (close[1]>indicatorpast && close[0]<indicatornow) OpenSELL();

but with this satatement, the expert opens positions not only when the price cross the indicator, it opens position above the indicator too. I want that the expert open position ONLY when it cross the indicator, so i tried that:

//to buy
double indicatorpast = icustom(....................,1);
double indicatornow = icustom(....................,0);

if (close[1]<indicatorpast && close[0]==indicatornow) OpenBUY();
if (close[1]>indicatorpast && close[0]==indicatornow) OpenSELL();

But this statement it is not performing.

Do you know what is happen? Because i think there arent errors in the statement.

The question is why is not opening at the exact point of cross when close[0]==Indicatornow? If the function would be with ==, we will prevent the open of orders above the point of crooss between the indicator and the close of the present bar but is not funtioning with this type of relationship between the variables.

Do you have experimented the same problem? Abyone knows how resolve it?
Thanks, again.
Because you are looking for an exact match between a returned 8 digit floating point value and price - they will almost never be equal with resolutions like that. Just check for a greater-than or less-than condition.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #694 (permalink)  
Old 02-15-2008, 08:52 AM
Junior Member
 
Join Date: Feb 2008
Posts: 1
bobo10 is on a distinguished road
swicthing software

hi boys, I would need to turn this indicator or the trading relative sistem into language mql because this functions on metatrader 4. Am I changing broker and software, is someone able' to help me?

{Calculation of Expanded Regression Moving Average}

{BEGINNING}

{"-HShift" - BARS FORWARDS}
DataBars:= Ref(Price,- HShift);

e1:= Mov(DataBars,PeriodMA,TypeMA);
e2:= Mov(e1,PeriodMA,TypeMA);
e3:= Mov(e2,PeriodMA,TypeMA);
e4:= Mov(e3,PeriodMA,TypeMA);
e5:= Mov(e4,PeriodMA,TypeMA);
e6:= Mov(e5,PeriodMA,TypeMA);
c1:= -b*b*b;
c2:= 3*b*b+3*b*b*b;
c3:= -6*b*b-3*b-3*b*b*b;
c4:= 1+3*b+b*b*b+3*b*b;
MV:= c1*e6+c2*e5+c3*e4+c4*e3;

{Calculation of Time of Life MV
for elimination of distortion of initial values}



{T3 Moving Average}
e1:= Mov(Pr,PeriodMA1,TypeMA1);
e2:= Mov(e1,PeriodMA1,TypeMA1);
e3:= Mov(e2,PeriodMA1,TypeMA1);
e4:= Mov(e3,PeriodMA1,TypeMA1);
e5:= Mov(e4,PeriodMA1,TypeMA1);
e6:= Mov(e5,PeriodMA1,TypeMA1);
c1:= -b1*b1*b1;
c2:= 3*b1*b1+3*b1*b1*b1;
c3:= -6*b1*b1-3*b1-3*b1*b1*b1;
c4:= 1+3*b1+b1*b1*b1+3*b1*b1;
MA1:= c1*e6+c2*e5+c3*e4+c4*e3;

{Trend Up and Down}

UpTrend:=Mv>=MA1;
DownTrend:=MA1>=Mv;

{Signal Long and Short}

Long:= cross(Mv,MA1) and Mv>=MA1;
Short:= cross(MA1,Mv) and MA1>=Mv;

{OpenBuy and CloseBuy}

OpenBuy:= cross(Mv,MA1) and Mv>=MA1;
CloseBuy:= cross(MA1,Mv) and MA1>=Mv;

{OpenSell and CloseSell}

OpenSell:= cross(MA1,Mv) and MA1>=Mv;
CloseSell:= cross(Mv,MA1) and Mv>=MA1;
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #695 (permalink)  
Old 02-15-2008, 11:28 AM
Linuxser's Avatar
Moderator
 
Join Date: May 2006
Location: Helliconia (Spring)
Posts: 3,322
Blog Entries: 46
Linuxser has disabled reputation
Quote:
Originally Posted by bobo10 View Post
hi boys, I would need to turn this indicator or the trading relative sistem into language mql because this functions on metatrader 4. Am I changing broker and software, is someone able' to help me?

{T3 Moving Average}
e1:= Mov(Pr,PeriodMA1,TypeMA1);
e2:= Mov(e1,PeriodMA1,TypeMA1);
e3:= Mov(e2,PeriodMA1,TypeMA1);
e4:= Mov(e3,PeriodMA1,TypeMA1);
e5:= Mov(e4,PeriodMA1,TypeMA1);
e6:= Mov(e5,PeriodMA1,TypeMA1);
c1:= -b1*b1*b1;
c2:= 3*b1*b1+3*b1*b1*b1;
c3:= -6*b1*b1-3*b1-3*b1*b1*b1;
c4:= 1+3*b1+b1*b1*b1+3*b1*b1;
MA1:= c1*e6+c2*e5+c3*e4+c4*e3;
All this codes are similar, you could start by looking the T3 code
__________________
Elite Manual Trading | Portfolio | Calendar | Suggestions to improve the forum | My Blog

Remember: Signatures must have three lines as maximum
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #696 (permalink)  
Old 02-16-2008, 01:21 AM
wolfe's Avatar
Senior Member
 
Join Date: Jan 2006
Posts: 723
wolfe is on a distinguished road
Quote:
Originally Posted by nittany1 View Post
Global, put this before init()
Code:
datetime PreviousBar;
In the order placement and/or order close stuff, wrap it in this:

Code:
if(NewBar() == true)
{
  if blah blah blah, gimme pips // not actual functions but you get the idea

  if blah blah blah, close orders // um
}

Common function outside main loop:
Code:
//--- returns true if current bar just formed
bool NewBar()
{
   if(PreviousBar<Time[0])
   {
      PreviousBar = Time[0];
      return(true);
   }
   else
   {
      return(false);
   }
   return(false);  
}
Thanks nitty1 for the help. I'll try it.

Also thanks to waltini & devil2000. I should be able to figure it out now.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #697 (permalink)  
Old 02-18-2008, 12:11 PM
fxgrm's Avatar
Member
 
Join Date: Mar 2007
Posts: 91
fxgrm is on a distinguished road
Account code for running on Demo freely

Hi:

Can someone tell me what code could be inserted to allow an EA that has account security code in it to also run freely on a demo account so users can test it before going live?

Is this even possible?

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #698 (permalink)  
Old 02-18-2008, 01:20 PM
Senior Member
 
Join Date: Dec 2005
Location: In front of my trading desk
Posts: 345
Devil2000 is on a distinguished road
Quote:
Originally Posted by fxgrm View Post
Hi:

Can someone tell me what code could be inserted to allow an EA that has account security code in it to also run freely on a demo account so users can test it before going live?

Is this even possible?

Thanks
From the metaeditor:
Code:
bool IsDemo()
Returns TRUE if the expert runs on a demo account, otherwise returns FALSE.
__________________
Need a professional MQL4 programmer? PM me
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #699 (permalink)  
Old 02-18-2008, 02:15 PM
kat kat is offline
Member
 
Join Date: Apr 2006
Posts: 46
kat is on a distinguished road
Coding "Trend Condition" with StepMA

Buy condition:

StepMA (with Colour Mode: 2) is "long"
Stochastic crosses 20 from below to above

Sell condition:

StepMA (with Colour Mode: 2) is "short"
Stochastic crosses 80 from above to below


double StochCurrent = iStochastic(NULL, 0, 21, 3, 8, MODE_SMA, 0, MODE_MAIN, Bar + 0);
double StochPrevious = iStochastic(NULL, 0, 21, 3, 8, MODE_SMA, 0, MODE_MAIN, Bar + 1);
double TrendLong = iCustom(NULL, 0, "stepma_v7ea", 1, 1.0, 0, 0, 0, 0.0, false, 2, 0, 1, Bar + 0);
double TrendShort = iCustom(NULL, 0, "stepma_v7ea", 1, 1.0, 0, 0, 0, 0.0, false, 2, 0, 2, Bar + 0);


Buy if:

TrendLong && StochCurrent > 20 && StochPrevious < 20


Sell if:

TrendShort && StochCurrent < 80 && StochPrevious > 80



Can someone help me with the code of the "Trend Condition" in the above example, it does not work. I tried to call the buffer 1 and buffer 2 for long and short mode but I don't understand the code of this indicator. Thank you in advance!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #700 (permalink)  
Old 02-18-2008, 02:22 PM
kat kat is offline
Member
 
Join Date: Apr 2006
Posts: 46
kat is on a distinguished road
Coding "Trend Condition" with StepMA

forgotten: for my previous posting the indicator and a screenshot
Attached Images
File Type: jpg example.jpg (54.3 KB, 96 views)
Attached Files
File Type: mq4 stepma_v7ea.mq4 (5.8 KB, 13 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Tags
candle time, CHinGsMAroonCLK, coders guru, expert advisor, forex, how to code, I_XO_A_H, mechanical trading, trading

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

LinkBacks (?)
LinkBack to this Thread: http://www.forex-tsd.com/metatrader-programming/554-how-code.html
Posted By For Type Date
Need an experienced programmer? - Page 2 Post #0 Refback 09-24-2008 07:24 AM

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to code this? iscuba11 Metatrader 4 mql 4 - Development course 1 08-03-2007 05:22 PM


All times are GMT. The time now is 09:01 AM.



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