Multiple orders problem - page 3

 
luisneves:


Hi Kronin,

Yes, I've a lot to learn....Now understand that when there is a need of a value to get accessed from outside a function that must be at Global. 

That is not true and also is often a bad idea.

Part of the reason to make some of your code into a function is to be able to re-use that code.  If the function is hard coded to work with specific global variables it can become less flexible.  You should consider passing variables to the User Defined Function . . .  don't always use globally declared variables.  For example:

 

//+--------------------------------------------------------------------------------+
//| ToStr function - calls DoubleToString (double, Digits) and returns the string  |
//+--------------------------------------------------------------------------------+
string ToStr(double ValueToString)
   {
   return (DoubleToStr(ValueToString, Digits));
   }

//+--------------------------------------------------------------------------------+

  . . .  this doesn't use a globally declared variable,  it uses the variable passed to it when called . . .

Print("Bid price is: ", ToStr(Bid) );
 
luisneves:


Hi Kronin,

Yes, I've a lot to learn....Now understand that when there is a need of a value to get accessed from outside a function that must be at Global. 

The values that are on external are multiplied by 10 because the EA must also run on 5 digits brokers. I'm using this block of code to get that automatically, but get an advise from WHRoeder that is not compatible with metals.  

 The spread of pair could be variable. That's why I'm using code to get out from the Stop Level.

Regarding this issue " But I have adjusted your input params to have not all orders open at pretty much the same time. Maybe you have to verify the default params."

As far I can see (sorry if am not...), OpenDistance maintain as 2 pips and ReturnDistance is now with 2 as well. What I'm see right now is that the order opens but not at 2 pips difference. This is running with a tester from in a platform of an ECN broker (IC Markets). Could this have some importance ?

In fact the orders do not open at same time but  seems that Open Distance and ReturnDist are not take in account to get the right distance to open orders.

You have in code that;

 

 

 I've include the line in bold to call the function OpenOppositeOrder  and here not sure if this is right. For other side can't see where is the comparison of present tick with last tick that happened 2 pips before (OpenDistance).

Sorry if i start to bore you with my issues.

Best regard's

Luis 



Hi Kronin,

 I've just take more attention why have ask what the spread is and just look for the Tester that something is wrong. Here the spread is 50 (5 digits) so 5 actually. Hummm... I will restart the platform and confirm. 

 

Luis 

 
RaptorUK:

That is not true and also is often a bad idea.

Part of the reason to make some of your code into a function is to be able to re-use that code.  If the function is hard coded to work with specific global variables it can become less flexible.  You should consider passing variables to the User Defined Function . . .  don't always use globally declared variables.  For example:

 

  . . .  this doesn't use a globally declared variable,  it uses the variable passed to it when called . . .

 


Hi RaptorUK.

 Thank you for your intervention for maintain me in right direction... 

By the way, Have you heard anything like what I've mention regarding the problem with the Tester, meaning that at this moment the spread is 50 when on Friday wasn't ? 

Best Regards

Luis

 
luisneves:


Hi RaptorUK.

 Thank you for your intervention for maintain me in right direction... 

Best Regards

Luis

Yes, the idea with the function was not really meant to declare them all as void.... I just removed the declaration in your void MM() for LotSize to let the EA trade again...  - I thought we speak later about that again... :-)

On the 'not open on 2 pips level point'
For example I haven't tick data to test, also the spread is more than 2 pips (I could adjust it, but what does it help, if I havent tick data?). All this makes it difficult to test something with that closed stopps reliable.


16:21:09 _help_53198_markettorderdecnqv80 inputs: EquityPercent=1; FixedLotSize=0.01; Multiplier=2; LotDigits=2; StopLoss=50; TakeProfit=20; TrailingStop=2; MinimumProfit=3; Slippage=3; OpenDistance=2; ReturnDist=1; MinStop=1; MagicNumber=8012013; MaxOrders=7;
EURUSD,M1: open #1 buy 0.01 EURUSD at 1.43310 ok
EURUSD,M1: Inital Buy order placed # 1
EURUSD,M1: modify #1 buy 0.01 EURUSD at 1.43310 sl: 1.42810 tp: 1.43510 ok
EURUSD,M1: open #2 sell 0.01 EURUSD at 1.43257 ok
EURUSD,M1: Opposite Sell order placed # 2
EURUSD,M1: modify #2 sell 0.01 EURUSD at 1.43257 sl: 1.43757 tp: 1.43057 ok
EURUSD,M1: open #3 buy 0.01 EURUSD at 1.43283 ok
EURUSD,M1: Opposite Buy order placed # 3
EURUSD,M1: modify #3 buy 0.01 EURUSD at 1.43283 sl: 1.42783 tp: 1.43483 ok
EURUSD,M1: open #4 sell 0.01 EURUSD at 1.43230 ok
EURUSD,M1: Opposite Sell order placed # 4
EURUSD,M1: modify #4 sell 0.01 EURUSD at 1.43230 sl: 1.43730 tp: 1.43030 ok
EURUSD,M1: open #5 buy 0.01 EURUSD at 1.43280 ok
EURUSD,M1: Opposite Buy order placed # 5
EURUSD,M1: modify #5 buy 0.01 EURUSD at 1.43280 sl: 1.42780 tp: 1.43480 ok
EURUSD,M1: open #6 sell 0.01 EURUSD at 1.43200 ok
EURUSD,M1: Opposite Sell order placed # 6
EURUSD,M1: modify #6 sell 0.01 EURUSD at 1.43200 sl: 1.43700 tp: 1.43000 ok
EURUSD,M1: open #7 buy 0.01 EURUSD at 1.43250 ok
EURUSD,M1: Opposite Buy order placed # 7
EURUSD,M1: modify #7 buy 0.01 EURUSD at 1.43250 sl: 1.42750 tp: 1.43450 ok
EURUSD,M1: modify #7 buy 0.01 EURUSD at 1.43250 sl: 1.43267 tp: 1.43450 ok
EURUSD,M1: modify #7 buy 0.01 EURUSD at 1.43250 sl: 1.43283 tp: 1.43450 ok
EURUSD,M1: modify #3 buy 0.01 EURUSD at 1.43283 sl: 1.43300 tp: 1.43483 ok
EURUSD,M1: modify #5 buy 0.01 EURUSD at 1.43280 sl: 1.43300 tp: 1.43480 ok
EURUSD,M1: modify #7 buy 0.01 EURUSD at 1.43250 sl: 1.43300 tp: 1.43450 ok
Tester: stop loss #3 at 1.43300 (1.43300 / 1.43340)
Tester: stop loss #5 at 1.43300 (1.43300 / 1.43340)
Tester: stop loss #7 at 1.43300 (1.43300 / 1.43340)
EURUSD,M1: LastClosedTicket=7
EURUSD,M1: Order with ticketnr: 7 hit SL! Close all open orders
EURUSD,M1: close #6 sell 0.01 EURUSD at 1.43200 sl: 1.43700 tp: 1.43000 at price 1.43340
EURUSD,M1: close #4 sell 0.01 EURUSD at 1.43230 sl: 1.43730 tp: 1.43030 at price 1.43340
EURUSD,M1: close #2 sell 0.01 EURUSD at 1.43257 sl: 1.43757 tp: 1.43057 at price 1.43340
EURUSD,M1: close #1 buy 0.01 EURUSD at 1.43310 sl: 1.42810 tp: 1.43510 at price 1.43300

 

From my point of view, it does what you want. I have never changed your calculation for OpenOpposite or open the inital order .

 
kronin:

Yes, the idea with the function was not really meant to declare them all as void.... I just removed the declaration in your void MM() for LotSize to let the EA trade again...  - I thought we speak later about that again... :-)

On the 'not open on 2 pips level point'
For example I haven't tick data to test, also the spread is more than 2 pips (I could adjust it, but what does it help, if I havent tick data?). All this makes it difficult to test something with that closed stopps reliable.


16:21:09 _help_53198_markettorderdecnqv80 inputs: EquityPercent=1; FixedLotSize=0.01; Multiplier=2; LotDigits=2; StopLoss=50; TakeProfit=20; TrailingStop=2; MinimumProfit=3; Slippage=3; OpenDistance=2; ReturnDist=1; MinStop=1; MagicNumber=8012013; MaxOrders=7;
EURUSD,M1: open #1 buy 0.01 EURUSD at 1.43310 ok
EURUSD,M1: Inital Buy order placed # 1
EURUSD,M1: modify #1 buy 0.01 EURUSD at 1.43310 sl: 1.42810 tp: 1.43510 ok
EURUSD,M1: open #2 sell 0.01 EURUSD at 1.43257 ok
EURUSD,M1: Opposite Sell order placed # 2
EURUSD,M1: modify #2 sell 0.01 EURUSD at 1.43257 sl: 1.43757 tp: 1.43057 ok
EURUSD,M1: open #3 buy 0.01 EURUSD at 1.43283 ok
EURUSD,M1: Opposite Buy order placed # 3
EURUSD,M1: modify #3 buy 0.01 EURUSD at 1.43283 sl: 1.42783 tp: 1.43483 ok
EURUSD,M1: open #4 sell 0.01 EURUSD at 1.43230 ok
EURUSD,M1: Opposite Sell order placed # 4
EURUSD,M1: modify #4 sell 0.01 EURUSD at 1.43230 sl: 1.43730 tp: 1.43030 ok
EURUSD,M1: open #5 buy 0.01 EURUSD at 1.43280 ok
EURUSD,M1: Opposite Buy order placed # 5
EURUSD,M1: modify #5 buy 0.01 EURUSD at 1.43280 sl: 1.42780 tp: 1.43480 ok
EURUSD,M1: open #6 sell 0.01 EURUSD at 1.43200 ok
EURUSD,M1: Opposite Sell order placed # 6
EURUSD,M1: modify #6 sell 0.01 EURUSD at 1.43200 sl: 1.43700 tp: 1.43000 ok
EURUSD,M1: open #7 buy 0.01 EURUSD at 1.43250 ok
EURUSD,M1: Opposite Buy order placed # 7
EURUSD,M1: modify #7 buy 0.01 EURUSD at 1.43250 sl: 1.42750 tp: 1.43450 ok
EURUSD,M1: modify #7 buy 0.01 EURUSD at 1.43250 sl: 1.43267 tp: 1.43450 ok
EURUSD,M1: modify #7 buy 0.01 EURUSD at 1.43250 sl: 1.43283 tp: 1.43450 ok
EURUSD,M1: modify #3 buy 0.01 EURUSD at 1.43283 sl: 1.43300 tp: 1.43483 ok
EURUSD,M1: modify #5 buy 0.01 EURUSD at 1.43280 sl: 1.43300 tp: 1.43480 ok
EURUSD,M1: modify #7 buy 0.01 EURUSD at 1.43250 sl: 1.43300 tp: 1.43450 ok
Tester: stop loss #3 at 1.43300 (1.43300 / 1.43340)
Tester: stop loss #5 at 1.43300 (1.43300 / 1.43340)
Tester: stop loss #7 at 1.43300 (1.43300 / 1.43340)
EURUSD,M1: LastClosedTicket=7
EURUSD,M1: Order with ticketnr: 7 hit SL! Close all open orders
EURUSD,M1: close #6 sell 0.01 EURUSD at 1.43200 sl: 1.43700 tp: 1.43000 at price 1.43340
EURUSD,M1: close #4 sell 0.01 EURUSD at 1.43230 sl: 1.43730 tp: 1.43030 at price 1.43340
EURUSD,M1: close #2 sell 0.01 EURUSD at 1.43257 sl: 1.43757 tp: 1.43057 at price 1.43340
EURUSD,M1: close #1 buy 0.01 EURUSD at 1.43310 sl: 1.42810 tp: 1.43510 at price 1.43300

 

From my point of view, it does what you want. I have never changed your calculation for OpenOpposite or open the inital order .


Hi Kronin,

I'm downloading another platform from another broker and will wait to test it again and let you know about the results. 

Thank you again

Luis

 

Hi Kronin,

 I've just confirm that in Tester the spread have jumped to 5 pips (50).  So today in Tester your code shows to work just fine, now I've put it in a ECN Demo account and will see.

Best regards

Luis 

 

Hi Kronin,

One issue;

When the EA starts shouldn't it wait to price deviates 2 pip before it open the first order ? 

When second order have the condition to open it opens in the right place.

Best Regards

Luis 

 
luisneves:

Hi Kronin,

One issue;

When the EA starts shouldn't it wait to price deviates 2 pip before it open the first order

When second order have the condition to open it opens in the right place.

Best Regards

Luis 

Hi Luis

Well, probably it should according to the strategy, but of course it doesn't according to the code... 

if(OpenDistance*pt && BuyAllowed) //<-- this doesn't make any sense.

The above is read as if(2*0.0001 && true) . Any numeric expression different from 0 is interpreted as true. So the expression is always true if BuyAllowed is true.

I am sorry, I have not payed any attention to the first opening of a serie and as it is only 2 pips, I didn't notice anything unusual. 

Try this:

//global scope
double BuyTrigger,SellTrigger;

//init function
BuyTrigger=Ask+OpenDistance*pt;
SellTrigger=Bid-OpenDistance*pt;

//start function
  OTCurrentTick=OrdersTotal();                   //reinit OrderTotal   <<-- this is already there, place the 4 lines below after this line
  if(OTCurrentTick==0&&OTLastTick>0){
     BuyTrigger=Ask+OpenDistance*pt;
     SellTrigger=Bid-OpenDistance*pt;
  }

if(Ask>BuyTrigger && BuyAllowed)                // <-- use this instead of if(OpenDistance*pt && BuyAllowed)

if(Bid<SellTrigger && SellAllowed)
 

Hi Kronin,

Sorry to bored you with my limitations in understanding the code, nevertheless is not too late to learn and am try my up most to get into the code that you so kindly have provided.

Right now am testing the best settings to use and will introduce your last code updated.

 

Thank you in advance to keep support me in these issues( adventures...I mean....)

Luis 

 

Hi Kronin,

 Your modification is working. You have limited the max orders, bur is that possible to get them all closed, instead ?

I've try to do that with the following code, but seems to  not  work.

if(LastClosedTicket>0|| OrdersTotal()>= MaxOrders)

 Best Regards

Luis 

Reason: