matheustn12: What is the Array problem?
- Check your return codes and find out why. What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
- Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong
- SL/TP (stops) need to be normalized to tick size (not Point.) (On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 forum) and abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 forum
- Open price for pending orders need to be adjusted. On Currencies, Point == TickSize, so you will get the same answer, but it won't work on Metals. So do it right: Trailing Bar Entry EA - MQL4 forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 forum
- Lot size must also be adjusted to a multiple of LotStep. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
- You assume history is ordered by date, it's not. Could EA Really Live By Order_History Alone? (ubzen) - MQL4 forum
whroeder1:
So you complicate me I do not know anything about mql4. I just asked that a good soul could fix this.
- Check your return codes and find out why. What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
- You assume history is ordered by date, it's not. Could EA Really Live By Order_History Alone? (ubzen) - MQL4 forum
matheustn12:
So you complicate me I do not know anything about mql4. I just asked that a good soul could fix this.
So you complicate me I do not know anything about mql4. I just asked that a good soul could fix this.
Fix what ?
the array does not use the lots I put
For me it's totally meaningless.
Alain Verleyen:
Fix what ?
For me it's totally meaningless.
Look at the pictures, I put the lots 0.1,0.2,0.3. But it is not working.
matheustn12: But it is not working. So you complicate me I do not know anything about mql4. I just asked that a good soul could fix this.
- "Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't
start, won't go in gear, no electrical, missing the key, flat tires -
meaningless. There are no mind readers here.
- I already told you to "check your return codes
and find out why." There are no mind readers here.
- learn
to code it, or pay (Freelance) someone.
We're not going to code it FOR you.
We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem. - Don't post a link to or attach a image, insert the image
- Please use the link button (control-K.) for links See the difference: https://gyazo.com/8352f1b38186d898bec6c8ee261d231e https://gyazo.com/bdd0d897e3a24910df158604d79b1de4
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
What is the Array problem?
This is working everything I wanted but the array does not use the lots I put
extern double Lots =0.1;
extern double StopLoss=50;
extern double TakeProfit=50;
extern int TrailingStop=50;
extern int Slippage=3;
extern double minlot=0.1;
extern double maxlot=10;
//+------------------------------------------------------------------+
// expert start function
//+------------------------------------------------------------------+
double numero[]={0.1,0.2,0.3};
int n,result;
double lotsfactor=1.5,ilots;
double initiallotsfactor=1;
int start()
{
//|---------martingale initialization
int tempfactor,total=OrdersTotal();
if(tempfactor==0 && total>0)
{
for(int cnt=0;cnt<total;cnt++)
{
if(OrderSelect(cnt,SELECT_BY_POS))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
{
tempfactor=NormalizeDouble(OrderLots()/numero[n],1+(MarketInfo(Symbol(),MODE_MINLOT)==0.01));
break;
}
}
}
}
int histotal=OrdersHistoryTotal();
if(tempfactor==0&&histotal>0)
{
for(cnt=0;cnt<histotal;cnt++)
{
if(OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
{
tempfactor=NormalizeDouble(OrderLots()/numero[n],1+(MarketInfo(Symbol(),MODE_MINLOT)==0.01));
break;
}
}
}
}
if(tempfactor>1)
lotsfactor=tempfactor;
double MyPoint=Point;
if(Digits==3 || Digits==5) MyPoint=Point*10;
double TheStopLoss=0;
double TheTakeProfit=0;
if( TotalOrdersCount()==0 )
{
int result=0;
if((Bid>Open[0])) // Here is your open buy rule
{
for(n=0;n<numero[n];n++){
result=numero[n]+OrderLots();
numero[n]=NormalizeDouble(numero[n]=martingalefactor(),1);
if(numero[n]<minlot)numero[n]=minlot;if(numero[n]>maxlot)numero[n]=maxlot;
result=OrderSend(Symbol(),OP_BUY,numero[n],Ask,Slippage,0,0,"Bot",MagicNumber,0,Blue);
if(result>0)
{
TheStopLoss=0;
TheTakeProfit=0;
if(TakeProfit>0) TheTakeProfit=Ask+TakeProfit*MyPoint;
if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
OrderSelect(result,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
}
return(0);
}
}
if((Bid<Open[0])) // Here is your open Sell rule
{
for(n=0;n<numero[n];n++){
result=numero[n]+OrderLots();
numero[n]=NormalizeDouble(numero[n]=martingalefactor(),1);
if(numero[n]<minlot)numero[n]=minlot;if(numero[n]>maxlot)numero[n]=maxlot;
result=OrderSend(Symbol(),OP_SELL,numero[n],Bid,Slippage,0,0,"Bot",MagicNumber,0,Red);
if(result>0)
{
TheStopLoss=0;
TheTakeProfit=0;
if(TakeProfit>0) TheTakeProfit=Bid-TakeProfit*MyPoint;
if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint;
OrderSelect(result,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
}
return(0);
}
}
}
for(int vnt=0;vnt<OrdersTotal();vnt++)
{
OrderSelect(vnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL &&
OrderSymbol()==Symbol() &&
OrderMagicNumber()==MagicNumber
)
{
if(OrderType()==OP_BUY)
{
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>MyPoint*TrailingStop)
{
if(OrderStopLoss()<Bid-MyPoint*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*MyPoint,OrderTakeProfit(),0,Green);
return(0);
}
}
}
}
else
{
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(MyPoint*TrailingStop))
{
if((OrderStopLoss()>(Ask+MyPoint*TrailingStop)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+MyPoint*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
}
}
return(0);
}
int TotalOrdersCount()
{
int result=0;
for(int i=0;i<OrdersTotal();i++)
{
OrderSelect(i,SELECT_BY_POS ,MODE_TRADES);
if (OrderMagicNumber()==MagicNumber) result++;
}
return (result);
}
int martingalefactor()
{
int histotal=OrdersHistoryTotal();
if (histotal>0)
{
for(int cnt=histotal-1;cnt>=0;cnt++)
{
if(OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
{
if(OrderProfit()<0)
{
lotsfactor=numero[n]+OrderLots();
return(lotsfactor);
}
else
{
lotsfactor=numero[n];
if(lotsfactor>=0)
{
lotsfactor=1.5;
}
return(lotsfactor);
}
}
}
}
}
return(lotsfactor);
}