Download MetaTrader 5

How to only execute once per tick?

To add comments, please log in or register
nadiawicket
397
nadiawicket  

Hello all and thanks in advanced.

I am trying to only open new orders if they are going to be opened in not the same price as any of the already currently active opened orders (MODES_TRADES, not MODE_HISTORY). In other words, I don't want 2 open orders with the same OrderOpenPrice() for my scalping strategy because it kills my margin.

The following code executes a lot of orders per tick, and I only want it to execute one order per tick. Upon playing with the correlation between the prints and ordersends and other trial and error methods, I finally figured that the counter counts the current open orders once, and then proceeds to execute the following commands as long as  the conditions *were* true for that tick since the first (and evidently final) time it counted orders for that tick. Hence, since it only scans once for conditions, problem is that it fails to notice that it just placed a new order for the current price and it just does not count the just sent new order which should have just invalidated the code's ability to send new orders for that tick (at least according to how I thought mql worked).

The only info I've found is about opening orders "only once per candle" and as I dreaded implies messing with datetime variables; which seems to me would not work in my case because upon meeting the required datetime conditions, would just continue to place many trades per tick.

I only want to create orders when the current order price is not the same as current market bid for the selected symbol:

for(int a=OrdersTotal()-1;a>=0;a--)
{
if(!OrderSelect(a,SELECT_BY_POS) && OrderOpenPrice() != (MarketInfo("USDJPY_",MODE_BID)))
continue;
OrderSend("USDJPY_", OP_SELL,.01,Bid,0,0,0,NULL,0 ,0,clrNONE); 
Print ("NOTSAME ", MarketInfo("USDJPY_",MODE_BID)," ", OrderTicket(), " ", OrderOpenPrice());
}
}

How do I have it recognize it just placed an order at a different price already and that creating any new onces would mean that it created a new order at the same price as the just created latest one for that tick? Many orders per tick means   they would not be at a different price than the latest new onces it just placed after condition was met for first time.

I end up with many orders at the same order open price, which is precisely what I need to avoid.

In other words, How do I only send one order per tick instead of sending many orders when condition was met in first scan of tick? Where am I incorrect?


Cheers and thx again.

Mohamad Zulhairi Baba
6099
Mohamad Zulhairi Baba  
nadiawicket:

Hello all and thanks in advanced.

I am trying to only open new orders if they are going to be opened in not the same price as any of the already currently active opened orders (MODES_TRADES, not MODE_HISTORY). In other words, I don't want 2 open orders with the same OrderOpenPrice() for my scalping strategy because it kills my margin.

The following code executes a lot of orders per tick, and I only want it to execute one order per tick. Upon playing with the correlation between the prints and ordersends and other trial and error methods, I finally figured that the counter counts the current open orders once, and then proceeds to execute the following commands as long as  the conditions *were* true for that tick since the first (and evidently final) time it counted orders for that tick. Hence, since it only scans once for conditions, problem is that it fails to notice that it just placed a new order for the current price and it just does not count the just sent new order which should have just invalidated the code's ability to send new orders for that tick (at least according to how I thought mql worked).

The only info I've found is about opening orders "only once per candle" and as I dreaded implies messing with datetime variables; which seems to me would not work in my case because upon meeting the required datetime conditions, would just continue to place many trades per tick.

I only want to create orders when the current order price is not the same as current market bid for the selected symbol:

How do I have it recognize it just placed an order at a different price already and that creating any new onces would mean that it created a new order at the same price as the just created latest one for that tick? Many orders per tick means   they would not be at a different price than the latest new onces it just placed after condition was met for first time.

I end up with many orders at the same order open price, which is precisely what I need to avoid.

In other words, How do I only send one order per tick instead of sending many orders when condition was met in first scan of tick? Where am I incorrect?


Cheers and thx again.

Put a bool flag, or additinal logic where next incoming tick, this loop never execute again.
nadiawicket
397
nadiawicket  
Mohamad Zulhairi Baba:
Put a bool flag, or additinal logic where next incoming tick, this loop never execute agai

Hey! Thanks for your reply!

Situation is Bools are scanned for once per tick not at every ordersend. The counter counts once per tick and makes many orders based on assumptions made from first scan. Once bool condition is met, it will place orders as long as condition was met at first scan. I need it to recognize it just placed an order at current price so it doesn't place a second one WITHIN THE SAME TICK.

I dont think you got my problem or maybe I'm not understanding you correctly.Why are you talking about next tick? My problem is that it places many orders in same tick. For next tick, I've got no problems as it rescans and finds price is different correctly. Problem is within the same tick that it does not rescan and doesn't notice that it ts placing many trades at the same price, which is precisely what I want to prevent.

Can you please provide an example of how to implement your solutions to my specific problem/code?

I will restate my issue:

How do you prevent it from placing 2 orders at the same strike price in the same tick?

Mohamad Zulhairi Baba
6099
Mohamad Zulhairi Baba  
nadiawicket:

Counter counts once per tick and makes many orders based on assumptions made from first scan. Once bool condition is met, it will place orders as long as condition was met at first scan. I need it to recognize it just placed an order at current price so it doesnt place a second one WITHIN THE SAME TICK.

I dont think you got my problem.Why are you talking about next tick?

Can you please provide an example of how to implement your solutions to my specific problem/code?


Your "for" loops has OrderOpenPrice, which need to be select (and verified) first, on it existing. Dont combine it on a single logic.

nadiawicket
397
nadiawicket  
Mohamad Zulhairi Baba:


Your "for" loops has OrderOpenPrice, which need to be select (and verified) first, on it existing. Dont combine it on a single logic.

Tried that before posting; gave it another shot and same issue with the following code again:

for(int a=OrdersTotal()-1;a>=0;a--)
{
if(!OrderSelect(a,SELECT_BY_POS))
continue;
if (OrderOpenPrice() != (MarketInfo("USDJPY_",MODE_BID)))
OrderSend("USDJPY_", OP_SELL,.01,Bid,0,0,0,NULL,0 ,0,clrNONE); 
}

Attached a screen .

Any more ideas? Going berserk.

Messed with datetime hoping mql treats it differently (not in a per tick  way) to no avail. Any help?

nadiawicket
397
nadiawicket  

Can anyone crack this?

nadiawicket
397
nadiawicket  

Even putting the code in script form, it still creates more than one order with same price, for same reasons as in EA mode.

   for(int a=OrdersTotal()-1;a>=0;a--)
     {
      if(!OrderSelect(a,SELECT_BY_POS))
         continue;
      if(OrderOpenPrice()!=MarketInfo("USDJPY_",MODE_BID))
         OrderSend("USDJPY_",OP_SELL,.01,Bid,0,0,0,NULL,0,0,clrNONE);
     }
  }

Sleeping until next tick afterwards won't work because it will still spitfire the barrage of orders since it only scans once per tick for conditions

Ernst Van Der Merwe
5076
Ernst Van Der Merwe  
      if(!OrderSelect(a,SELECT_BY_POS) || OrderSymbol()!="USDJPY_")
         continue;
      double bid=MarketInfo("USDJPY_",MODE_BID);
      int digits=(int)MarketInfo("USDJPY_",MODE_DIGITS)-1;
      if(NormalizeDouble(OrderOpenPrice(),digits)!=NormalizeDouble(bid,digits))
         OrderSend("USDJPY_",OP_SELL,.01,bid,0,0,0,NULL,0,0,clrNONE);
whroeder1
15913
whroeder1  

nadiawicket: Sleeping until next tick afterwards won't work because it will still spitfire the barrage of orders since it only scans once per tick for conditions

Once bool condition is met, it will place orders as long as condition was met at first scan

  1. You are waiting for "a condition," and opening a order. "Once per tick" will always result in "the barrage of orders."
  2. Wait for a change in condition
    static bool condition=false; bool previous=condition;
    condition = isTimeToOpen();
    if(condition && !previous) Open();


nadiawicket
397
nadiawicket  
Ernst Van Der Merwe:

I appreciate your input, however I tried your code, still the same exact situation.

How would you explain your reasoning? What are you going for? Cant decipher it from just looking at it, I'm not very good at this.  Looks like you are trying to read out the amount of digits in the print out from the expert and compare it some way or something along those lines.

However this will still result in barrage of orders as the condition, upon met, will result in many orders being placed until the arrival of next tick when it can count the conditions as false.

I need a way to have it scan for conditions multiple times within the same tick or any other method which works for stopping the barrage. However I've got no other conditions to stop the barrage from happening so as to have it only find one time the correct conditions and therefore prevent the barrage from happening.

Did you actually get it to stop sending the spitfire barrage with your method?
nadiawicket
397
nadiawicket  
whroeder1:
  1. You are waiting for "a condition," and opening a order. "Once per tick" will always result in "the barrage of orders."
  2. Wait for a change in condition


1. Exactly.

2. How do you scan for a change in condition within the same tick? Has to be a way.

Really grateful, however the thing is that for my case, the option of boolean is just not going to cut it because it will do the barrage of orders anyway at the first tick where they are true as you have pointed out.

Is there absolutely no way to not be bound by "ONCE PER TICK"?

For me, having it to be able to scan multiple times per tick is the only way.

12
To add comments, please log in or register