Re: Coding Help
511Dear Mladen and Mr Tools help restore the performance of the indicator 3wpr__mtf, on new builds.
"Only the price on the chart can show the entrance to the deal..."
Code: Select all
//----- close order By Bbandsstop signal-----
int Bbandsstopclose() {
double trendCurr = iCustom(Symbol(),0,"@BBands stop v3",0,UpBandPrice, LoBandPrice, MA_Length, MA_Mode,Deviation,DeviationLength,MoneyRisk,SignalMode,LineMode,6,shift);
for (int cnt = OrdersTotal()-1 ; cnt >= 0; cnt--) {
if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol()==Symbol() && (OrderMagicNumber() == MagicNumberBuy || OrderMagicNumber() == MagicNumberSell))
if (trendCurr ==-1 && OrderType() == OP_BUY) closeAll(OP_BUY);
if (trendCurr ==1 && OrderType() == OP_SELL) closeAll(OP_SELL);
}
}
return(0);
}
void closeAll(int OrdrType) {
double closePrice = 0;
for (int cnt = OrdersTotal()-1 ; cnt >= 0; cnt--) {
if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES) && OrderMagicNumber() != MagicNumberBuy && OrderMagicNumber() != MagicNumberSell && OrderSymbol() == Symbol() && OrderType() == OrdrType) {
for (int retries =0; retries<3; retries++) {
RefreshRates();
{
if((OrderType()==OP_BUY)&&(( OrdrType==0)||( OrdrType==1)))
if (OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(MarketInfo(OrderSymbol(),MODE_BID),MarketInfo(OrderSymbol(),MODE_DIGITS)),5*Spread,Blue))
if((OrderType()==OP_SELL)&&(( OrdrType==0)||( OrdrType==-1)))
if (OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(MarketInfo(OrderSymbol(),MODE_ASK),MarketInfo(OrderSymbol(),MODE_DIGITS)),5*Spread,Red))break;
}
}
}
}
}
Guys, please : to be able to answer questions like that I need to know what exactly do you expect from some code to do.Steven wrote: Sat Sep 09, 2017 1:10 pm Hello mladen , i want to build a simple close ea follow by Bbandsstop .
I wish you can give advise for me and point me out where i have wrong in this code .
Thank you.
Code: Select all
//----- close order By Bbandsstop signal----- int Bbandsstopclose() { double trendCurr = iCustom(Symbol(),0,"@BBands stop v3",0,UpBandPrice, LoBandPrice, MA_Length, MA_Mode,Deviation,DeviationLength,MoneyRisk,SignalMode,LineMode,6,shift); for (int cnt = OrdersTotal()-1 ; cnt >= 0; cnt--) { if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol()==Symbol() && (OrderMagicNumber() == MagicNumberBuy || OrderMagicNumber() == MagicNumberSell)) if (trendCurr ==-1 && OrderType() == OP_BUY) closeAll(OP_BUY); if (trendCurr ==1 && OrderType() == OP_SELL) closeAll(OP_SELL); } } return(0); } void closeAll(int OrdrType) { double closePrice = 0; for (int cnt = OrdersTotal()-1 ; cnt >= 0; cnt--) { if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES) && OrderMagicNumber() != MagicNumberBuy && OrderMagicNumber() != MagicNumberSell && OrderSymbol() == Symbol() && OrderType() == OrdrType) { for (int retries =0; retries<3; retries++) { RefreshRates(); { if((OrderType()==OP_BUY)&&(( OrdrType==0)||( OrdrType==1))) if (OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(MarketInfo(OrderSymbol(),MODE_BID),MarketInfo(OrderSymbol(),MODE_DIGITS)),5*Spread,Blue)) if((OrderType()==OP_SELL)&&(( OrdrType==0)||( OrdrType==-1))) if (OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(MarketInfo(OrderSymbol(),MODE_ASK),MarketInfo(OrderSymbol(),MODE_DIGITS)),5*Spread,Red))break; } } } } }
Hi , sorry about not explain clearly .mladen wrote: Sat Sep 09, 2017 5:33 pm Guys, please : to be able to answer questions like that I need to know what exactly do you expect from some code to do.
So : what exactly it does not do the way you expect it to do?
That means you already have two " int start() " in your indicator , you only need place the code without the " int start() " in your indicator .Sanele wrote: Tue Sep 12, 2017 3:09 am Hi All
How can i protect my indicator with password or Time expiry or User account?, the methods that are on MQL4 site give errors like "'start' - function already defined and has different type" or "function defination unexpected"
your help will be appreciated
Problem solve .Steven wrote: Sat Sep 09, 2017 7:06 pm
Hi , sorry about not explain clearly .
I have use bbandsstop indicator for my trading signal .
So i want to make a ea to close my position went the signal is reverse , so i no need to sit in front the monitor for few hour.
Example : The signal is up i have buy position , when the signal is reverse to sell and the ea will close all my buy position on chart .
My problem is now the ea does not close any position , so i need help to check is that my code have any problem ?
I not good in mql , but i want to learn somethings new .
Thanks .