| 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 |
|
|||
|
Use this indicator http://www.forex-tsd.com/93349-post473.html (it is daily, weekly and monthly).
Or this one Narrow Range Day Indicator Or this one Daily data |
|
|||
|
Hello All
Here is the ea i am using. Can someone please tell me what to change in order to have a BUY-STOP and a SELL_Stop taken at the same time. The way it is now, either a buy-stop or a sell-stop is triggered. i'd like to have both. Secondly, what should i do to limit the number of orders for each candle. I thank you all in advance. here is the code: void start() { //---- check for history and trading if(Bars<100 || IsTradeAllowed()==false) return; co=CalculateCurrentOrders(Symbol()); CheckForSignals(); if (co>0) CheckForClose(); CheckForOpen(); co=CalculateCurrentOrders(Symbol()); if (mkt>0) { BreakEvenStop(BreakEven,0); double pcnt =( (AccountEquity()-AccountBalance()) / AccountBalance())*100; Print("Account equity = ",AccountEquity()); Print("Account balance = ",AccountBalance()); if(pcnt>EquityGainPercent) { int total = OrdersTotal(); for(int i=total-1;i>=0;i--) { OrderSelect(i, SELECT_BY_POS); int type = OrderType(); bool result = false; switch(type) { //Close opened long positions case OP_BUY : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red ); break; //Close opened short positions case OP_SELL : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red ); break; //Close pending orders case OP_BUYLIMIT : case OP_BUYSTOP : case OP_SELLLIMIT : case OP_SELLSTOP : result = OrderDelete( OrderTicket() ); } if(result == false) { Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() ); Sleep(3000); } } Print("ALL ORDERS CLOSE-->Locked in on Profits"); } return(0); } } //+------------------------------------------------------------------+ //| Calculate open positions | //+------------------------------------------------------------------+ int CalculateCurrentOrders(string symbol) { int ord; mkt=0; //---- for(int i=0;i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false ) continue; if(OrderSymbol()==symbol && OrderMagicNumber()==MagicNumber) { ord++; if (OrderType()==OP_BUY || OrderType()==OP_SELL) mkt++; } } //---- return orders volume return(ord); } //+------------------------------------------------------------------+ //| Check for open order conditions | //+------------------------------------------------------------------+ void CheckForSignals() { //check long,short,exit signals buysig=false; sellsig=false; closebuy=false; closesell=false; remorder=false; int isins,isouts,iskeyrev,is2brev; if (InsideBar) isins=IsInsideBar(shift); if (OutSideBar) isouts=IsOutSideBar(shift); if (KeyReversalBar) iskeyrev=IsKeyReversalBar(shift); if (TwoBarReversal) is2brev=IsTwoBarReversal(shift); //long entry signal condition if (isins>0 || isouts>0 || iskeyrev>0 || is2brev>0) { buysig=true; closesell=true; } //short entry signal if (isins<0 || isouts<0 || iskeyrev<0 || is2brev<0) { buysig=false; sellsig=true; closebuy=true; } if (last>0 && (Time[0]-last)/(Period()*60)>=CancelOrderBars) { remorder=true; } } void CheckForOpen() { int res,tr; //---- sell conditions co=CalculateCurrentOrders(Symbol()); if(sellsig && lastsig!=-1) { co=CalculateCurrentOrders(Symbol()); if (co==0) { res = OpenStop(OP_SELLSTOP,LotsRisk(StopLoss), Low[shift]-OrderPipsDiff*Point, StopLoss, TakeProfit1); } lastsig=-1; last=Time[0]; return; } //---- buy conditions if(buysig && lastsig!=1) { co=CalculateCurrentOrders(Symbol()); if (co==0) { res = OpenStop(OP_BUYSTOP,LotsRisk(StopLoss), High[shift]+OrderPipsDiff*Point, StopLoss, TakeProfit1); } last=Time[0]; lastsig=1; return; } } void BreakEvenStop(int BES, int BELP) { //move stoploss to lock some profit bool bres; double StopLoss; if ( BES > 2 ) { for (int i = 0; i < OrdersTotal(); i++) { if ( OrderSelect (i, SELECT_BY_POS) == false ) continue; if ( OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber ) continue; if ( OrderType() == OP_BUY ) { if ( Bid < OrderOpenPrice()+BES*Point ) continue; StopLoss = OrderOpenPrice()+BELP*Point; if ( StopLoss > OrderStopLoss() ) { bres=OrderModify (OrderTicket(), OrderOpenPrice(), StopLoss, OrderTakeProfit(), 0, White); if (!bres) Print("Error Modifying BUY order : ",ErrorDescription(GetLastError())); } } if ( OrderType() == OP_SELL ) { if ( Ask > OrderOpenPrice()-BES*Point ) continue; StopLoss = OrderOpenPrice()-BELP*Point; if ( StopLoss < OrderStopLoss() ) { bres=OrderModify (OrderTicket(), OrderOpenPrice(), StopLoss, OrderTakeProfit(), 0, Gold); if (!bres) Print("Error Modifying SELL order : ",ErrorDescription(GetLastError())); } } } } return; } int IsKeyReversalBar(int shift) { //Key Reversal Bar, The open of the key bar should be at least ?pips higher than the high of the previous bar. //The close of the key bar should be with in the high and close of the previous bar. The open of the current bar should be //lower than the close of the key bar. A SellStop order should be place on the low of the key bar if it is not executed within //the next 4 bars then cancel the order. See picture below - short! if (Open[shift]<Low[shift+1] && Close[shift]>=Low[shift+1] && Close[shift]<=Close[shift+1] && Open[shift-1]>Close[shift]) return(1); if (Open[shift]>High[shift+1] && Close[shift]<=High[shift+1] && Close[shift]>=Close[shift+1] && Open[shift-1]<Close[shift]) return(-1); return(0); } int IsTwoBarReversal(int shift) { //Two Bar Reversal, The open of the first bar should be near the low the previous bar and the close should be much lower and //have a good size body. The open of the second bar should be very near the close of the first bar but both should be well below //the midpoint of each bar with the close to be very near the low 2 bar previous. A BuyStop Order should be place at the high of //the bar 1 if it is not executed within 4 bars cancel order. See picture below if (MathAbs(Open[shift+1]-Close[shift+1])> MathAbs(Open[shift+1]-Low[shift+2])<= MathAbs(Close[shift]-Low[shift+2])<= MathAbs(Open[shift]-Close[shift+1]) && Close[shift+1]<(High[shift+1]+Low[shift+1])/2 && Open[shift]<(High[shift]+Low[shift])/2) return(1); if (MathAbs(Open[shift+1]-Close[shift+1])> MathAbs(Open[shift+1]-High[shift+2])<= MathAbs(Close[shift]-Low[shift+2])<= MathAbs(Open[shift]-Close[shift+1]) && Close[shift+1]>(High[shift+1]+Low[shift+1])/2 && Open[shift]>(High[shift]+Low[shift])/2) return(-1); return(0); } int OpenStop(int mode,double lot, double prc, int SL, int TP) { int res,tr,col; string mail; double openprice,sl,tp,stlev; tries=0; stlev=(1+MarketInfo(Symbol(),MODE_STOPLEVEL))*Poin t; while (res<=0 && tries<OrderTriesNumber) { tr=0; while (tr<5 && !IsTradeAllowed()) { tr++; Sleep(2000); } RefreshRates(); if (mode==OP_SELLSTOP) { if (prc<=Bid-stlev) openprice=prc; else openprice=Bid-stlev; if (SL>0) sl=openprice+SL*Point; if (TP>0) tp=openprice-TP*Point; col=Red; } else if (mode==OP_BUYSTOP) { if (prc>=Ask+stlev) openprice=prc; else openprice=Ask+stlev; if (SL>0) sl=openprice-SL*Point; if (TP>0) tp=openprice+TP*Point; col=Blue; } else return; Print(Ask," ",Bid," ",Symbol()," ",mode," ",lot," ",openprice," ",sl," ",tp," "); res=OrderSend(Symbol(),mode,lot,openprice,slippage ,sl,tp,EAName+"_"+MagicNumber,MagicNumber,0,col); tries++; } if (res<=0) Print("Error opening pending order : ",ErrorDescription(GetLastError())); return(res); } void CheckForClose() { bool bres; int tr; for(int i=0;i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false ) continue; if(OrderMagicNumber()!=MagicNumber || OrderSymbol()!=Symbol()) continue; //---- check order type if(OrderType()==OP_BUY && closebuy) { bres=CloseAtMarket(OrderTicket(),OrderLots()); continue; } if(OrderType()==OP_SELL && closesell) { bres=CloseAtMarket(OrderTicket(),OrderLots()); continue; } if(OrderType()==OP_BUYSTOP && (closebuy || remorder)) { bres=DeletePending(OrderTicket()); continue; } if(OrderType()==OP_SELLSTOP && (closesell || remorder)) { bres=DeletePending(OrderTicket()); continue; } } } bool DeletePending(int ticket) { bool bres=false; int tr; tries=0; while (!bres && tries<OrderTriesNumber) { bres=OrderDelete(ticket); tries++; tr=0; while (tr<5 && !IsTradeAllowed()) { tr++; Sleep(2000); } } if (!bres) Print("Error deleting order : ",ErrorDescription(GetLastError())); return (bres); } |
|
|||
|
It is here How to LOCK/Encrypt EA (post #7)
|
|
|||
|
Quote:
I have my initialization code (which has a time expiration in it) set up like such: int init() {if (TimeCurrent()>D'2008.06.07 12:00:00'){Comment("please renew your subscription"); return(0);} return(0); } } if (Account != AccountNumber()){ Comment("Trade on account :"+AccountNumber()+" FORBIDDEN!"); return(0); }else {Comment("");} And now I am returning this error: '}' - unbalanced parentheses What am I doing wrong here? Also, does "int Account = 111111;" go with the EA's setting? Thanks. Last edited by Yoda_Glenn; 06-21-2008 at 09:48 AM. |
|
|||
|
If I want to reference continually back to the bar that the position was originally opened on, how do I do this in MT4? I want to reference the opened position bar low to the current bar low. The problem I see is that as time progresses, the bar back has to change. How do I make the open position bar a special bar to reference back to?
Dave <><<< I would appreciate someones programming wisdom on this! I give my appreciation to you in advance! |
|
|||
|
One way you could do it off the top of my head is to write the price to a file. Take a look at the help system and read all the 'File' functions. Especailly filewrite, fileread etc.
Good luck Lux
__________________
Build An Expert Advisor. FREE E-course As Seen On TV ![]() ForexArea.com Users of Gap Trader from 'Forex-Assistant' MUST Read This |
![]() |
| Bookmarks |
| 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 | |