zoop Posted February 1, 2010 Report Share Posted February 1, 2010 another question, i have a tight bollinger band, 2period, 1 dev i would like the ea to stop trading when the upper and lower touch or come very close together double upper1=iBands(NULL,bbtimeframe,bbperiod,deviation,0,PRICE_OPEN,MODE_UPPER,0); double lower1=iBands(NULL,bbtimeframe,bbperiod,deviation,0,PRICE_OPEN,MODE_LOWER,0); the code below is wrong just example if (upper1=lower1) return(0); //stoptrading // much much thanks Quote Link to comment Share on other sites More sharing options...
⭐ birt Posted February 1, 2010 Report Share Posted February 1, 2010 Re: (ask) how to code this When it's a condition, you have to use "==" instead of "=". A single "=" sign means an assignment. So, in your case, the condition should be something like: value1 == value2 If you want a threshold for the values being in proximity of each other, you can do something like: MathAbs(value1 - value2) < threshold Quote Link to comment Share on other sites More sharing options...
zoop Posted February 1, 2010 Author Report Share Posted February 1, 2010 Re: (ask) how to code this Thanks Birt i changed it and it works great double upper1=iBands(NULL,bbtimeframe,bbperiod,deviation,0,PRICE_OPEN,MODE_UPPER,0); double lower1=iBands(NULL,bbtimeframe,bbperiod,deviation,0,PRICE_OPEN,MODE_LOWER,0); if((upper1==lower1))return(0); but not sure how to implement the threshold MathAbs(upper1-lower1) < threshold return(0); thanks for your help Quote Link to comment Share on other sites More sharing options...
Starting Posted February 1, 2010 Report Share Posted February 1, 2010 Re: (ask) how to code this zoop, mate, if (MathAbs(value1 - value2) < threshold) return (0); //difference in values are within the threshlod if (MathAbs(value1 - value2) > threshold) return (1); //difference in values matters (more than a threshold, thus returning positive (1)) :) Quote Link to comment Share on other sites More sharing options...
scarface Posted February 1, 2010 Report Share Posted February 1, 2010 Re: (ask) how to code this Hi birt, & Starting, Good day, I'm glad you guys joined the support team in our forum II. This is going to be a great experience for all of us. Thanks a lot for the great assistance. Best wishes, Quote a New Year 2011 has come, and the challenge has just started 8-) Link to comment Share on other sites More sharing options...
zoop Posted February 2, 2010 Author Report Share Posted February 2, 2010 Re: (ask) how to code this thanks starting and Birt question on the on the subject, double ma=iMA(NULL,bbtimeframe,bbperiod,0,MODE_SMA,PRICE_OPEN,shift); double upper=iBands(NULL,bbtimeframe,bbperiod,deviation,0,PRICE_OPEN,MODE_UPPER,shift); double lower=ma-iBands(NULL,bbtimeframe,bbperiod,deviation,0,PRICE_OPEN,MODE_LOWER,shift); if i add a ma to the bollinger center band, how would a approach coding if upperband deviates to the center ma or lowerband deviates to the center ma, return 0, stop trading, at 0 or x value thanks Quote Link to comment Share on other sites More sharing options...
⭐ birt Posted February 2, 2010 Report Share Posted February 2, 2010 Re: (ask) how to code this thanks starting and Birt question on the on the subject, double ma=iMA(NULL,bbtimeframe,bbperiod,0,MODE_SMA,PRICE_OPEN,shift); double upper=iBands(NULL,bbtimeframe,bbperiod,deviation,0,PRICE_OPEN,MODE_UPPER,shift); double lower=ma-iBands(NULL,bbtimeframe,bbperiod,deviation,0,PRICE_OPEN,MODE_LOWER,shift); if i add a ma to the bollinger center band, how would a approach coding if upperband deviates to the center ma or lowerband deviates to the center ma, return 0, stop trading, at 0 or x value thanks Uhh, I'm not sure I understand what you want... What do you mean by "upperband deviates to the center ma"? Do you perhaps mean "upper bollinger band crosses the ma downwards"? In this case, you just have to check the value of the upper band against the MA - if it's smaller, exit. Reverse for lower band. Quote Link to comment Share on other sites More sharing options...
Starting Posted February 2, 2010 Report Share Posted February 2, 2010 Re: (ask) how to code this Uhh, I'm not sure I understand what you want... What do you mean by "upperband deviates to the center ma"? Do you perhaps mean "upper bollinger band crosses the ma downwards"? In this case, you just have to check the value of the upper band against the MA - if it's smaller, exit. Reverse for lower band. Mate, I think zoop wants to have a middle line between BBands borders and code behaviour based on touching it by one of the BB line. Zoop, Please draw a picture on what do you want to code. It's really not clear for understanding. One picture worths 100 of words! Quote Link to comment Share on other sites More sharing options...
zoop Posted February 2, 2010 Author Report Share Posted February 2, 2010 Re: (ask) how to code this ok this is a screen shot to explain it better HQ image link [url]http://img40.imageshack.us/img40/6938/bbandsnotrade.gif[/url] bollinger band settings period 2 deviations 1 apply to open http://img40.imageshack.us/img40/6938/bbandsnotrade.gif P.S: please use ImageShack uploader to display image clearly to everyone so they understand your request thanks Quote Link to comment Share on other sites More sharing options...
⭐ birt Posted February 2, 2010 Report Share Posted February 2, 2010 Re: (ask) how to code this ok this is a screen shot to explain it better ... Well, if I'm not mistaken, the middle line is the average of the two bands, (upper + lower) / 2. Thus, it pretty much boils down to one of your original questions, which was not trading when the distance is lower than a threshold. Quote Link to comment Share on other sites More sharing options...
zoop Posted February 2, 2010 Author Report Share Posted February 2, 2010 Re: (ask) how to code this Well, if I'm not mistaken, the middle line is the average of the two bands, (upper + lower) / 2. Thus, it pretty much boils down to one of your original questions, which was not trading when the distance is lower than a threshold. yes sounds right birt, so what would the code look like then? ( remember im a learner experimenting) :.) ie how do i put a value to the upper / lower/mid bands to make it work? Quote Link to comment Share on other sites More sharing options...
⭐ birt Posted February 2, 2010 Report Share Posted February 2, 2010 Re: (ask) how to code this yes sounds right birt, so what would the code look like then? ( remember im a learner experimenting) :.) ie how do i put a value to the upper / lower/mid bands to make it work? What do you mean, put a value to the bands? You don't put a value. iBands returns a value so, if anything, you get one. If you want the value of the mid, you just average the upper and the lower. If you want to check how close two values are, you compare their difference to a threshold you configure, perhaps as an external parameter. I've already explained how to do that. Quote Link to comment Share on other sites More sharing options...
zoop Posted February 3, 2010 Author Report Share Posted February 3, 2010 Re: (ask) how to code this thanks birt, its cleared a few things up just another question, how to project indicator output values as a comment? ie difference between upper and lower value as comment double upper=iBands(NULL,bbtimeframe,bbperiod,deviation,0,PRICE_OPEN,MODE_UPPER,shift); double lower=iBands(NULL,bbtimeframe,bbperiod,deviation,0,PRICE_OPEN,MODE_LOWER,shift); thanks...sorry for so many questions Quote Link to comment Share on other sites More sharing options...
scarface Posted February 3, 2010 Report Share Posted February 3, 2010 Re: (ask) how to code this Hi zoop, Good day, In your case, just you comments return value say by using the difference example you mentioned. You can use either the message box or the normal comments function. If it is clear please let me know and if not, please let me know I can give you an example related to what you want. Thanks birt, for the great help. Best wishes, Quote a New Year 2011 has come, and the challenge has just started 8-) Link to comment Share on other sites More sharing options...
Starting Posted February 3, 2010 Report Share Posted February 3, 2010 Re: (ask) how to code this thanks birt, its cleared a few things up just another question, how to project indicator output values as a comment? ie difference between upper and lower value as comment double upper=iBands(NULL,bbtimeframe,bbperiod,deviation,0,PRICE_OPEN,MODE_UPPER,shift); double lower=iBands(NULL,bbtimeframe,bbperiod,deviation,0,PRICE_OPEN,MODE_LOWER,shift); thanks...sorry for so many questions Mate, one good advice from me. If you open Metaeditor and just start to write up what you want, let's say "Comme.." you will see that Metaeditor tries to catch up and proposes to help you to finish the right word in dropdown menue. So you select a word you meant, it'll be Comment, then you put your cursor inside this word, like here: Comm|ent and push F1 button for help on syntax. In your case it will be something like this Comment(upper); You may also check if commenting value is not goodlooking, to convert it to String first, using DoubleToStr(upper,2); function like here string UPPER = DoubleToStr(upper,2); Comment(UPPER); It looks like you haven't checked that Metaeditor feature before. So help in Metaeditor is the first fast aid for you in your MQL4 research. Keep it as granted. It'll greatly help you to progress really faster. Have a great day! :) Quote Link to comment Share on other sites More sharing options...
⭐ birt Posted February 3, 2010 Report Share Posted February 3, 2010 Re: (ask) how to code this One thing to keep in mind is that Comment() overwrites your previous chart comment. So, doing this: Comment(DoubleToStr(value1, Point)); Comment(DoubleToStr(value2, Point)); will only display value2. In order to display both of them, you can try: Comment(DoubleToStr(value1, Point) + "\n" + DoubleToStr(value2, Point)); In case you're wondering, "\n" means new line. Quote Link to comment Share on other sites More sharing options...
jdonut Posted February 20, 2010 Report Share Posted February 20, 2010 Re: (ask) how to code this Req. I need some help with order spacing and some more... I am really new to Forex and MetaTrader and new to this board. Hello everyone. I found a simple moving average Ea that works pretty good after I changed some < to > and == sort of things. I really don't know what I am doing but I am trying. I also cut and pasted an equity stop into it whcih works but now it doesn't allow for a take profit. This Ea I think has promise. With multiple positions opened, it puts them all close together. They need a pip increment - distance between them. I have been monkeying around with it but I can't seem to get it right. I was wondering if anyone could help me clean up the code and make it work? Here is the code; #define OrSt "Simple moving average EA" extern string IS="---------------- Indicator Settings"; extern double MA_Period=20; extern double MODE_MA=0; //0=simple, 1=exponential, etc... extern string LM="---------------- Lot Management"; extern double Lots=0.01; extern bool MM=false; //money management extern double Risk=10; //risk in percentage extern string TSTB="---------------- TP SL TS BE"; bool RealSL_Enabled=false; int RealSL=5; //stop loss under 15 pîps bool RealTP_Enabled=false; int RealTP=10; //take profit under 10 pîps extern int SL=0; //stop loss extern int TP=0; //take profit extern int TS=25; //trailing stop extern int TS_Step=25; //trailing stop step extern double Incremental_Eq_target=1; extern int BE=10; //breakeven extern string EXT="---------------- Extras"; extern bool Reverse=false; extern bool Add_Positions=false; //positions cumulated extern int MaxOrders=3; //maximum number of orders - if I can get the pips to increment- could be more??? extern int Magic=0; int i; int Slip=3;static int TL=0;double MML=0; // Expert start function int start(){int j=0,limit=1;double BV=0,SV=0;BV=0;SV=0;double MA1,MA2; if(CntO(OP_BUY,Magic)>0) TL=1;if(CntO(OP_SELL,Magic)>0) TL=-1;for(int i=1;i<=limit;i++){ MA1=iMA(Symbol(),0,MA_Period,0,MODE_MA,PRICE_CLOSE,i+1); MA2=iMA(Symbol(),0,MA_Period,0,MODE_MA,PRICE_CLOSE,i); if(MA2>MA1){if(Reverse) SV=1; else BV=1; break;} if(MA2<MA1){if(Reverse) BV=1; else SV=1; break;}} // Expert money management if(MM){if(Risk<0.1 || Risk>100) {Comment("Invalid Risk Value."); return(0);} else {MML=MathFloor((AccountFreeMargin() *AccountLeverage()*Risk*Point*100)/(Ask*MarketInfo(Symbol(),MODE_LOTSIZE)*MarketInfo(Symbol(),MODE_MINLOT )))*MarketInfo(Symbol(),MODE_MINLOT );}} if(MM==false){MML=Lots;} // Expert init positions int cnt=0,OP=0,OS=0,OB=0,CS=0,CB=0;OP=0;for(cnt=0; cnt<OrdersTotal();cnt++) {OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if((OrderType()==OP_SELL || OrderType()==OP_BUY) && OrderSymbol()==Symbol() && ((OrderMagicNumber()==Magic) || Magic==0)) OP=OP+1;} if(OP>=1){OS=0; OB=0;}OB=0;OS=0;CB=0;CS=0; // Expert conditions to open position if(SV>0){OS=1;OB=0;}if(BV>0){OB=1;OS=0;} // Expert conditions to close position if((SV>0) || (RealSL_Enabled && (OrderOpenPrice()-Bid)/Point>=RealSL)||(RealTP_Enabled && (Ask-OrderOpenPrice())/Point>=RealTP)){CB=0;} if((BV>0) || (RealSL_Enabled && (Ask-OrderOpenPrice())/Point>=RealSL)||(RealTP_Enabled && (OrderOpenPrice()-Bid)/Point>=RealTP)){CS=0;} for(cnt=0;cnt<OrdersTotal();cnt++){OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && ((OrderMagicNumber()==Magic) || Magic==0)){if (CB==1){OrderClose(OrderTicket(),OrderLots(),Bid,Slip,Red); return(0);}} if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && ((OrderMagicNumber()==Magic) || Magic==0)){ if(CS==1){OrderClose(OrderTicket(),OrderLots(),Ask,Slip,Red);return(0);}}}double SLI=0,TPI=0;int TK=0; // Expert open position value if((AddP() && Add_Positions && OP<=MaxOrders) || (OP==0 && !Add_Positions)) { if(OS==1){if (TP==0) TPI=0; else TPI=Bid+TP*Point;if (SL==0) SLI=0; else SLI=Bid+SL*Point;TK=OrderSend(Symbol(),OP_SELL,MML,Bid,Slip,SLI,TPI,OrSt,Magic,0,Red);OS=0;return(0);} if(OB==1){if(TP==0) TPI=0; else TPI=Ask-TP*Point;if(SL==0) SLI=0; else SLI=Ask-SL*Point;TK=OrderSend(Symbol(),OP_BUY,MML,Ask,Slip,SLI,TPI,OrSt,Magic,0,Lime);OB=0; return(0);}} for(j=0;j<OrdersTotal();j++){if(OrderSelect(j,SELECT_BY_POS, MODE_TRADES)){if (OrderSymbol()==Symbol() && ((OrderMagicNumber()==Magic) || Magic==0)) {TrP();}}}return(0);} // Expert number of orders int CntO(int Type,int Magic){int _CntO;_CntO=0; for(int j=0;j<OrdersTotal();j++){OrderSelect(j, SELECT_BY_POS, MODE_TRADES);if(OrderSymbol()==Symbol()) {if((OrderType()==Type && (OrderMagicNumber()==Magic) || Magic==0)) _CntO++;}}return(_CntO);} // Expert trailing stop void TrP(){double pb,pa,pp;pp=MarketInfo(OrderSymbol(),MODE_POINT);if (OrderType()==OP_BUY){pb=MarketInfo(OrderSymbol(),MODE_BID); // Expert incremental equity stop - isn't working right yet...Help! if (AccountProfit()>=Incremental_Eq_target) { for(i=OrdersTotal()-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),Slip,Pink); //Close opened short positions case OP_SELL : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),Slip,Pink); } if(result == false) { Sleep(3000); } } Print ("Account Balance Profit Reached. All Open Trades Have Been Closed"); return(0); } Comment("Balance: ",AccountBalance(),", Account Equity: ",AccountEquity(),", Account Profit: ",AccountProfit(), "\nMy Account Balance Profit Target: ",Incremental_Eq_target); return(0); //Expert breakeven if(BE>0){if((pb-OrderOpenPrice())>BE*pp){if((OrderStopLoss()-OrderOpenPrice())<0){ModSL(OrderOpenPrice()+0*pp);}}} if(TS>0){if((pb-OrderOpenPrice())>TS*pp){if(OrderStopLoss()<pb-(TS+TS_Step-1)*pp){ModSL(pb-TS*pp);return;}}}} if(OrderType()==OP_SELL){pa=MarketInfo(OrderSymbol(),MODE_ASK);if(BE>0){if((OrderOpenPrice()-pa)>BE*pp){if((OrderOpenPrice()-OrderStopLoss())<0){ModSL(OrderOpenPrice()-0*pp);}}} if (TS>0){if (OrderOpenPrice()-pa>TS*pp){if (OrderStopLoss()>pa+(TS+TS_Step-1)*pp || OrderStopLoss()==0){ModSL(pa+TS*pp);return;}}}}} //Expert stoploss void ModSL(double ldSL){bool fm;fm=OrderModify(OrderTicket(),OrderOpenPrice(),ldSL,OrderTakeProfit(),0,CLR_NONE);} //Expert add positions function bool AddP(){int _num=0; int _ot=0; for (int j=0;j>OrdersTotal();j++){if(OrderSelect(j,SELECT_BY_POS)==true && OrderSymbol()==Symbol() && OrderType()<3 && ((OrderMagicNumber()==Magic) || Magic==0)) { _num++;if(OrderOpenTime()>_ot) _ot=OrderOpenTime();}} if(_num==0) return(true);if(_num>0 && ((Time[0]-_ot))>0) return(true);else return(false); } Symbol EURUSD (Euro vs. United States Dollar) Period 30 Minutes (M30) 2009.01.05 01:00 - 2009.05.29 22:30 (2009.01.05 - 2009.05.31) Model Every tick (the most precise method based on all available least timeframes) Parameters IS="---------------- Indicator Settings"; MA_Period=20; MODE_MA=0; LM="---------------- Lot Management"; Lots=0.01; MM=true; Risk=5; TSTB="---------------- TP SL TS BE"; SL=0; TP=0; TS=25; TS_Step=25; Incremental_Eq_target=1; BE=10; EXT="---------------- Extras"; Reverse=false; Add_Positions=true; MaxOrders=2; Magic=0; Bars in test 5990 Ticks modelled 4472597 Modelling quality 90.00% Mismatched charts errors 2 Initial deposit 500.00 Total net profit 1984.64 Gross profit 2016.25 Gross loss -31.61 Profit factor 63.79 Expected payoff 1.49 Absolute drawdown 177.64 Maximal drawdown 1877.30 (85.35%) Relative drawdown 85.35% (1877.30) Total trades 1334 Short positions (won %) 177 (97.74%) Long positions (won %) 1157 (98.44%) Profit trades (% of total) 1312 (98.35%) Loss trades (% of total) 22 (1.65%) Largest profit trade 97.20 loss trade -8.24 Average profit trade 1.54 loss trade -1.44 Maximum consecutive wins (profit in money) 502 (331.30) consecutive losses (loss in money) 3 (-23.12) Maximal consecutive profit (count of wins) 389.47 (90) consecutive loss (count of losses) -23.12 (3) Average consecutive wins 73 consecutive losses Quote Link to comment Share on other sites More sharing options...
scarface Posted February 26, 2010 Report Share Posted February 26, 2010 Re: (ask) how to code this Hi jdonut, Good day, I believe you made it even harder to me by missing around in the code. In this case I have either to bring the original code or you tell me what you did so I can fix it. I'm wondering why did you miss the code?? :-? did you want to do something to modify it?? :) You can explain what you want to do, and then I can help you out with it adding anything you want. P.S. if you are willing to learn mql4 you can check out the lessons in mql4 forum. Please let me know about the code. If you have any question, please feel free to ask anything, anything. Best wishes, Quote a New Year 2011 has come, and the challenge has just started 8-) Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.