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 (2) Thread Tools Display Modes
  #111 (permalink)  
Old 05-21-2006, 02:50 AM
Ted Ted is offline
Junior Member
 
Join Date: May 2006
Posts: 2
Ted is on a distinguished road
Problem with breakeven and trailing stop

Hello,

I am learning coding using the MQL4 tutorial from Codersguru, and I'm working on "My_First_EA". It really is my first EA. It works very well, but I am trying to write a breakeven stop and I can't figure it out. The problem I have is that the breakeven stop follows the price just like a trailing stop. I would like the initial stoploss to move to keep 1 pip profit when I make 15 pips (for example), then I want the stoploss to stay at the breakeven stop (1 pip profit) until the trailing stop begins working at 25 pips profit. Then I want the trailing stop to work as usual moving every pip of profit. I think the problem might be the "OrderStopLoss()", but I don't know anything anymore. My brain is mush. Thankyou

Here is the relevent code I've done:

extern double TrailingStop=25.0;
extern double BreakEvenProfit=15;
extern double BreakEvenStop=1;
......................
my entry and open orders code here works fine
......................

for (cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if (OrderType()<=OP_SELL&&OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY)//Long position is opened
{
//should it be closed?

if (FSAR > FMA) //my exit signal
{
//----CLOSE LONG POSITION works fine
OrderClose(OrderTicket(),OrderLots(),Bid,3,Magenta );
return(0);//exit
}
////////////////////THIS IS THE PROBLEM AREA BELOW/////////
//----CHECK FOR BREAKEVEN STOP LONG POSITION------
if (Bid-OrderOpenPrice() > BreakEvenProfit*Point)
{
if (OrderStopLoss() < OrderOpenPrice()+ BreakEvenStop*Point)
{
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOp enPrice() + BreakEvenStop*Point,OrderTakeProfit(),0,Yellow);
return(0);
}
}
//-----EVERYTHING BELOW HERE WORKS AS A TYPICAL TRAILING STOP
//----check for trailing stop LONG POSITION
if(TrailingStop>0)
{
if (Bid-OrderOpenPrice()>Point*TrailingStop)
{
if (OrderStopLoss()<Bid-Point*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Yellow);
return(0);
}
}
}
}
else//go to short position
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #112 (permalink)  
Old 05-21-2006, 02:12 PM
Senior Member
 
Join Date: Oct 2005
Posts: 284
Bongo is on a distinguished road
Correlation

CodersGuru,
I'm looking for this. Coul you please help. Thanks.
Bongo
I’m looking for these functions:

Strategies:
1)
For trading 2 pairs: EUR/USD & USD/CHF.

If CHF/USD jump up 2 ticks, sell EUR/USD and vv
If CHF/USD jump down 2 ticks, buy EUR/USD.

If EUR/USD jump up 2 ticks, sell USD/CHF and vv
If EUR/USD jump down 2 ticks, buy USD/CHF.

2)
For trading only 1 pairs: EUR/USD.

If USD/CHF jump up 2 ticks, sell EUR/USD and vv
If USD/CHF jump down 2 ticks, buy EUR/USD but
If EUR/USD jump 2 ticks first don’t trade USD/CHF,
Wait for USD/CHF to jump first.

3)
For trading only 1 pairs: EUR/USD.

If USD/CHF jump up 2 ticks, sell EUR/USD and vv
If USD/CHF jump down 2 ticks, buy EUR/USD.

Trading on the own movement:
If EUR/USD jump up 2 ticks, buy EUR/USD,
If EUR/USD jump down 2 ticks, sell EUR/USD.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #113 (permalink)  
Old 05-21-2006, 02:50 PM
elihayun's Avatar
Senior Member
 
Join Date: Jan 2006
Posts: 350
elihayun is on a distinguished road
Quote:
Originally Posted by hellkas
Hi all coders...

What I've to do to solve this error: zero divide?

Thank you for any help...
The problem is the line of code

bb=100*(aa1-MyLow)/(MyHigh-MyLow);

where MyHigh equal to MyLow.
To correct it use this
double dDif = (MyHigh-MyLow); if (dDif == 0) dDif = 0.00001;
bb=100*(aa1-MyLow)/dDif;

here the corrected version
Attached Files
File Type: mq4 TTM Stoch.mq4 (4.4 KB, 70 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #114 (permalink)  
Old 05-26-2006, 04:43 PM
Junior Member
 
Join Date: May 2006
Posts: 2
thiagomartini is on a distinguished road
Several Trades Simultaneously

Hi,

i´ve got a question: how to allow the expert to place more than one order independently?

Using the command

total=OrdersTotal();
if(total<1)

we got the control of the number of trades being executed simultaneously (if < 1, one at a tima, if >2, two at a time and so on)

But in real world, that command ends up with the expert placing two or more orders using the same entering conditions (same as using several lots).

I want to allow the expert to place another orders even if there is one or more orders opened, but not place them at thge same moment; mayba a delay form one order to other (15 or 30 min), so my question is:

HOW TO ALLOW THE EXPERT TO PLACE MORE THAN ONE ORDER, WITHOUT PLACING THEM AT ONE TIMA?

thank you, waiting for help!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #115 (permalink)  
Old 05-26-2006, 05:16 PM
Junior Member
 
Join Date: May 2006
Posts: 21
viktoriwan is on a distinguished road
Can an EA set Parameter of an Attached Indicator ?

Hello,
i have an idea to build a system that has an EA and also visual representation of the sytem. but i have no idea how an EA can set parameter for attached indicator.

let say for if the indicator has EnableAlerts... when user set the Enable Alerts to 1 in an EA, than the attached indicator also change it's Enable Alerts Variable to 1 and vice versa..

i hope you got my point.

Thanks

Victor
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #116 (permalink)  
Old 05-26-2006, 05:24 PM
Junior Member
 
Join Date: May 2006
Posts: 21
viktoriwan is on a distinguished road
Why using indicator buffers instead of array ?

Hello,
i create another thread for this same question, but i think this is the correct one to ask.

i sometimes see this line of code :

//---- 2 additional buffers are used for counting.
IndicatorBuffers(3);
SetIndexBuffer(1,PosBuffer);
SetIndexBuffer(2,NegBuffer);

i wonder why we use Indicator Buffers to save variables instead we use array ? what's the main idea for this method..

thank you
Victor
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #117 (permalink)  
Old 05-26-2006, 07:06 PM
Junior Member
 
Join Date: May 2006
Posts: 21
viktoriwan is on a distinguished road
Question about MSN Style Pop Alert!

Hello,
i read your article about customizing pop alert. May i know the tools you use to build the the object ? or can i do custom alert ?

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #118 (permalink)  
Old 05-27-2006, 12:48 AM
wannatrade2's Avatar
Junior Member
 
Join Date: May 2006
Posts: 3
wannatrade2 is on a distinguished road
Quote:
Originally Posted by codersguru
Hi folks,

I've got a lot of private messages asking me for helping with some pieces of code.

Here you can post your questions related to MQL4, and I'll do my best to answer them.
Hi codersguru,
First I'd like to thank you for your great posts...you really are a "coders guru"!
I would very much like to learn to write my own indicators using MQL4.
Could you please tell me how i can find all your MQL4 lessons. I tried the links within the lessons but they no longer work. I am a TOTAL newbie to all this...FX and MQL4...so your help would be greatly appreciated.
Thank you in advance
Bob
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #119 (permalink)  
Old 05-28-2006, 06:31 AM
niva's Avatar
Senior Member
 
Join Date: Mar 2006
Posts: 101
niva is on a distinguished road
How can I use mql to process historical data, convert data into some result and out put to a file?
__________________
Forex TSD is NO. 1
EA's blog: http://eaconfigs.blogspot.com/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #120 (permalink)  
Old 05-28-2006, 07:08 AM
elihayun's Avatar
Senior Member
 
Join Date: Jan 2006
Posts: 350
elihayun is on a distinguished road
Quote:
Originally Posted by niva
How can I use mql to process historical data, convert data into some result and out put to a file?
I have this script to write historical data. U can reverse the write command with the read command. Hope it will help you
Attached Files
File Type: mq4 HistorySave.mq4 (3.0 KB, 47 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Tags
histogram

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 On
Forum Jump

LinkBacks (?)
LinkBack to this Thread: http://www.forex-tsd.com/questions/270-ask.html
Posted By For Type Date
OzFx System:) - Page 639 This thread Refback 06-21-2008 09:53 PM
Forex SRDC Sidus Sibkis EA MT4 Forum OTCSmart This thread Refback 12-08-2007 11:46 AM


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



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