I am using 3x variations of my EA across 15+ pairs. On version_2 of my EA, I am getting an error of 4051 (as I have recently placed all my prints back in - don't know why I greyed them out in the first place :P)
I'm guessing it's because of the number of lots that are currently open can not be divisible by the "Second_Target" value of "4"... In which case, how do I close out the CLOSEST lot value to the math shown in here:
"double Target_2 = MathFloor(OrderLots()/Second_Target/lotStep)*lotStep;"
Is the 4051 due to the lots ? have you confirmed this ? is the resultant lots value >= the min lots value ? where do you check in your code ?
Is the 4051 due to the lots ? have you confirmed this ? is the resultant lots value >= the min lots value ? where do you check in your code ?
Yea, It is the lots I am trying to close relative to what I am trying to divide it by. I have updated my original post^
Current lots open is 0.58 lots... divide by "4" gives me 0.145....? It is telling me that the lots to close is "0.00000" ? I thought Mathfloor took care of rounding it down? (correct me if I am wrong) - Need to understand how to tell it to close out a pre-defined lot value, as CLOSE to the answer (in which case, what I am wanting to divide it by = "4") as possible... ?
Yea, It is the lots I am trying to close relative to what I am trying to divide it by. I have updated my original post^
Current lots open is 0.58 lots... divide by "4" gives me 0.145....? It is telling me that the lots to close is "0.00000" ? I thought Mathfloor took care of rounding it down? (correct me if I am wrong) - Need to understand how to tell it to close out a pre-defined lot value, as CLOSE to the answer (in which case, what I am wanting to divide it by = "4") as possible... ?
MathFloor will round down to the nearest integer, 0 can be the nearest integer, you said the calculation should be 0.58/5 = 0.145 OK, what is lotStep ? if it's greater than 0.145 then MathFloor would round down to 0.
"double Target_2 =MathFloor(OrderLots()/Second_Target/lotStep)*lotStep;" = MathFloor(0.58/4/0.01)*0.01 ---- "Second_Target" I have as an "extern double" up in the global area. So I have that currently set to "4".
I have lotstep printing out, which is: "0.01000"
"double Target_2 =MathFloor(OrderLots()/Second_Target/lotStep)*lotStep;" = MathFloor(0.58/4/0.01)*0.01 ---- "Second_Target" I have as an "extern double" up in the global area. So I have that currently set to "4".
I have lotstep printing out, which is: "0.01000"
Looks OK to me . . . to be certain I always, always add brackets . . . so . . .
double Target_2 = MathFloor( ( OrderLots() / Second_Target ) / lotStep) * lotStep;
. . . try it, see if it fixes the issue. If it does then we have one more question to resolve about the documentation . . .
In the code above you are not printing OrderLots(), perhaps you have the wrong Order selected and have the wrong Lots value compared to what you think you have . . . add a print for OrderLots() and check.
Ok, I have printed out the order lots using OrderSymbol() too, and I can confirm that the correct order is being selected AND the correct lot sizing too...? This is really odd :s?
Ok, I have printed out the order lots using OrderSymbol() too, and I can confirm that the correct order is being selected AND the correct lot sizing too...? This is really odd :s?
Break it down, print each step, find what is going wrong . . . there is always an explanation. For example . . .
Print("OrderLots(): ", OrderLots(), " Second_Target: ", Second_Target, " Lots/target: ", OrderLots() / Second_Target ); double Target_2 = MathFloor( ( OrderLots() / Second_Target ) / lotStep) * lotStep;
etc, print every variable and each part of the workings in the Target_2 calculation so you can see where it is going wrong . . .
I have tried that...
Lots are 0.58
Current Order selected is GBPUSD
Lot step is: 0.01
SecondTarget_Buy: 1.34584 & yen prices!
FirstTarget_Buy: 1.34254 & yen prices!
The Lots to close is: 0.00000
The SecondTarget_Buy and FirstTarget_Buy seem to be giving me the price of the EURUSD...? Which is odd, because I call this "void CloseHalfOrder()" from this: (therefore, I thought it would have the correct order selected?)
Update: It seems to be pulling price's even from the Yen Pairs... ? So when I print firsttarget_buy and secondtarget_buy I am getting conflicting prices?
//+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { if(IsNewCandle()) { CheckForMaTrade();//signals, deletions and candle trails only need checked on a new candle. } if(OpenOrdersThisPair(Symbol())>0) { if(UseMoveToBreakEven)MoveToBreakEven();//Move to b/e, normal trail and MA_trail need to trail on each tick if(Use_MA_Trail)MA_Trail(); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// int PositionIndex; int TotalNumberOfOrders; TotalNumberOfOrders = OrdersTotal(); for(PositionIndex = TotalNumberOfOrders - 1; PositionIndex >= 0 ; PositionIndex --) { if( ! OrderSelect(PositionIndex, SELECT_BY_POS, MODE_TRADES) ) continue; if( OrderMagicNumber() == MagicNumber // <-- does the Order's Magic Number match our EA's magic number ? && OrderSymbol() == Symbol() ) // <-- does the Order's Symbol match the Symbol our EA is working on ? { if(OpenOrdersThisPair(Symbol())>0 && OrderType()==OP_SELL) { CloseHalfOrder1(); } if(OpenOrdersThisPair(Symbol())>0 && OrderType()==OP_BUY) { CloseHalfOrder(); <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Called here? Would this not pass through to the void the correct order? Or does that all need to be done again within the void properly? } } } }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I am using 3x variations of my EA across 15+ pairs. On version_2 of my EA, I am getting an error of 4051 (as I have recently placed all my prints back in - don't know why I greyed them out in the first place :P)
I'm guessing it's because of the number of lots that are currently open can not be divisible by the "Second_Target" value of "4"... In which case, how do I close out the CLOSEST lot value to the math shown in here:
"double Target_2 = MathFloor(OrderLots()/Second_Target/lotStep)*lotStep;" ----- See code below with arrows.
Also, when I print out the above^ code, it is saying that the lots to close is "0.00000", on a position with "0.58" lots open. Now technically, this should be: "0.145" - I'm not sure if this third decimal number is messing it up? If so, how do I drop that and round it up to: "0.15" lots?