| 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 (2) | Thread Tools | Display Modes |
|
|||
|
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 |
|
|||
|
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. |
|
|||
|
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! |
|
|||
|
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 |
|
|||
|
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 |
|
||||
|
Quote:
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 |
![]() |
| Bookmarks |
| Tags |
| histogram |
| Thread Tools | |
| Display Modes | |
|
|
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 | |