How to only execute once per tick? - page 2

 
No tick independent variables or something?
 
nadiawicket:

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?


This code is tested. Opens an order while conditions are met, but only once per price in pips.

int digits;
double pipdbl;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   digits=(int)MarketInfo("USDJPY",MODE_DIGITS)-1;
   pipdbl=MarketInfo("USDJPY",MODE_POINT)*10;
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   if(CheckShort())
      OpenShort();
  }
//+------------------------------------------------------------------+
bool CheckShort()
  {
   double high=iCustom("USDJPY",PERIOD_CURRENT,"Stochastic_OHLC_2.0",1,0);
   double close=iCustom("USDJPY",PERIOD_CURRENT,"Stochastic_OHLC_2.0",3,0);
   return((close<80 && high>=80) || (close<50 && high>=50));
  } 
//---
bool OpenShort()
  {
   if(OrdersTotal("USDJPY",OP_SELL)==0)
      return(OrderSend("USDJPY",OP_SELL,.01,MarketInfo("USDJPY",MODE_BID),0,0,0,NULL,0,0,clrNONE));
   return(false);
  }
//---
int OrdersTotal(string symbol,int type)
  {
   int count=0;
   double ask=MarketInfo(symbol,MODE_ASK);
   double bid=MarketInfo(symbol,MODE_BID);
   for(int i=0;i<OrdersTotal();i++)
     { 
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==symbol && OrderType()==type)
        {
         if(type==OP_BUY)
            if(MathAbs(OrderOpenPrice()-ask)<pipdbl)
               count++;
         if(type==OP_SELL)
            if(NormalizeDouble(OrderOpenPrice(),digits)==NormalizeDouble(bid,digits))
               count++;
        }
     }
   return(count);
  }
 
Ernst Van Der Merwe:


This code is tested. Opens an order while conditions are met, but only once per price in pips.

Thing is that your code uses bools to check for conditions.

In my case bools/conditions dont seem to be an option unless there is such a condition which is Tick independant.

Looking like OnTimer or something like that for my case. . Wil post resolution if I get there. .

 
   if(x()==0)
      Print("Was 0");

   Print("x()= ",x());
  }
//+------------------------------------------------------------------+
int x()
  {
   int x=0;
   if OrderSend(_Symbol,OP_SELL,.01,MarketInfo(_Symbol,MODE_BID),0,0,0,NULL,0,0,clrNONE);
   x=x+1;
   return(x);
  }

OnTimer wasn't it.

Now looking like something like this, that has like an Ammo that gets wasted every time I send an order, and gets reloaded every tick. . Any help with this concept is really appreciated. Looks like it is it, just need to figure out how to do it right. Looks like it was booleanism after all. Can't get it down though.

 

Always prints 1 though .

 

It will always print 1, because this line:

x=x+1;

isn't dependent on anything. It will be called every time the function gets called.

Perhaps you meant to write this?

int x()
  {
   int x=0;
   if(OrderSend(_Symbol,OP_SELL,0.01,Bid,3,0,0) >= 0) x=x+1;
   return(x);
  }
 
honest_knave:

It will always print 1, because this line:

isn't dependent on anything. It will be called every time the function gets called.

Perhaps you meant to write this?

Yes I did. Thanks for pointing that out.
 
static double tickCurrent; 
double tickPrevious = tickCurrent; 

tickCurrent = MarketInfo(_Symbol,MODE_BID);

if (tickPrevious != tickCurrent) 
Print ("previous ", tickPrevious," current ",tickCurrent, " BID ", MarketInfo(_Symbol,MODE_BID)  );

if (tickPrevious != tickCurrent) 
OrderSend(_Symbol,OP_SELL,0.01,MarketInfo(_Symbol,MODE_BID),0,0,0,NULL,0,0,clrNONE);

Issue resolved for now,

Slippage/fill-ins/latency guarantee that you will never be 100 per cent completely able to execute at the exact price your code tells it to even with bulletproof code.

 
nadiawicket:

Issue resolved for now,

Slippage/fill-ins/latency guarantee that you will never be 100 per cent completely able to execute at the exact price your code tells it to even with bulletproof code.


If you're trading the current chart's symbol (by using _Symbol) you can use the pre-defined variable Bid rather than MarketInfo

It is also highly beneficial to check the result of your OrderSend:

if(OrderSend(_Symbol,OP_SELL,0.01,Bid,0,0,0)<0) Print("Error sending order: ",_LastError);