random distance

 

Hi all,

So, the issue have to do with the open of an order that should be opened from a distance of other.

Say that one want to open an Sell order 2 pips (20 points) down from  the open price of the Buy order.

With the code that follows some times it opens at the Opposite distance, others more than the Oppositedistance and even others less the Oppositedistance.

Could anyone see if is anything wrong ?

Thanks in advance

Luis

void OpenOppositeOrder()
    {     
    int Op;
    
   for(int Counter = OrdersTotal()-1; Counter >= 0; Counter--)
      {//
      if(!OrderSelect(Counter,SELECT_BY_POS,MODE_TRADES))continue;          
         {//
         if(OrderSymbol() == Symbol()&& OrderMagicNumber() == MagicNumber)           
            {//16
             Op = OrderType();
             RefreshRates();            
         if(Op == OP_BUY && Bid < (OrderOpenPrice() - (OppositeDistance*pips2dbl)) && SellAllowed)  
                               
               {//  
                while(IsTradeContextBusy()) 
                      Sleep(10);
                      RefreshRates();                             
                SellTicket = OrderSend(Symbol(), OP_SELL, MLots, Bid, Slippage*pips2points, 0, 0, "Open Opposite Sell Order", MagicNumber, 0, Red);
                if(SellTicket > -1) 
                  {//
                  BuyAllowed=true;SellAllowed=false;                                          
                  Print("Opposite Sell order placed # ", SellTicket);                
                  AddLimitsSell();                                    
                  return;
                  }//
               else
                  {//
                  Print("Opposite Sell Order Failed,order number:",OrderTicket(),"Error:",GetLastError());
                  }//
                }// 
                RefreshRates();           
            if(Op == OP_SELL &&  Ask > (OrderOpenPrice() + (OppositeDistance*pips2dbl)) && BuyAllowed)
                      
              {//  
               while(IsTradeContextBusy()) 
                    Sleep(10);
                         RefreshRates();                                
               BuyTicket = OrderSend(Symbol(), OP_BUY, MLots, Ask, Slippage*pips2points, 0, 0, " Open Opposite Buy Order", MagicNumber, 0, Green); 
               if(BuyTicket > -1)
                  {//
                  BuyAllowed=false;SellAllowed=true;                                                          
                  Print("Opposite Buy order placed # ", BuyTicket);                             
                  AddLimitsBuy();
               return;
                  }//
               else
                  {//  
                  Print("Opposite Buy Order Failed, order number:",OrderTicket(),"Error:",GetLastError());
                  }//   
               }//
            }//
         }//    
      }//      
    }//
    
 
luisneves:

Hi all,

So, the issue have to do with the open of an order that should be opened from a distance of other.

Say that one want to open an Sell order 2 pips (20 points) down from  the open price of the Buy order.

With the code that follows some times it opens at the Opposite distance, others more than the Oppositedistance and even others less the Oppositedistance.

I can understand how it can be at or greater than the oppositedistance,  not how it can possibly be less . . .

Your code says . . .

Bid < (OrderOpenPrice() - (OppositeDistance*pips2dbl)

 if OrderOpenPrice() were 1.5000 and OppositDistance were 20  if Bid was 1.4  the test returns true because Bid (1.4000) is <  1.5000 - 0.0020

Bid and Ask don't move pip by pip or point by point,  sometimes Bid will move 1 point for a tick sometimes it will move 10 pips for a tick,  if for one tick your test fails and the next tick it is true if Bid has moved 10 pips in one tick Bid may well be further than oppositedistance.  Don't be tempted to use 

Bid == (OrderOpenPrice() - (OppositeDistance*pips2dbl)

 if Bid is 1 point further than you want the trade won't be placed, also you will have issues with comparing doubles . . .  you seem to be ignoring that issue at the moment.

 

Don't open new trades in a loop where you look for the open trades you have

a new trade.....

you have the info when the loop is ended

at that moment you know if it is needed to do a new trade

if you martingale with distance two pips

then the margin you need will lead in a short time to a margincall

for most currency the spread can have times that it is more as 2 pips

Profit you get is that way almost all for broker 

 
deVries:

Don't open new trades in a loop where you look for the open trades you have

a new trade.....

you have the info when the loop is ended

at that moment you know if it is needed to do a new trade

if you martingale with distance two pips

then the margin you need will lead in a short time to a margincall

for most currency the spread can have times that it is more as 2 pips

Profit you get is that way almost all for broker 


Hi, RaptorUK and deVries;

Thank you for your attention to my issue.

RaptorUK, when you say that a tick is not a pip then am I right to say that the TickValue is the bad guy ?

In fact and take the deVries advise I take a print from TickValue and the value is something 0.7834, so is this the relation between pips and tick and if yes is there a way to include this relation to compensate the difference?

 Another question, is that possible to use OrderProfit() instead and say if profit is above  (or under) than order open price the Opposite Distance the an opposite order will open ?

 

 deVries, you are right to to call my attention for this kind of strategy is in the minimum a suicide I know, but am looking to learn the most I can of mql and some (stupid..) strategies.

Meanwhile I'm working out the pending order ea that you so start to get me in understand  the new approach  for taking the ea market state.


Thank you again for your support

Luis 

 

 words of Raptor

Bid and Ask don't move pip by pip or point by point,  sometimes Bid will move 1 point for a tick sometimes it will move 10 pips for a tick,  if for one tick your test fails and the next tick it is true if Bid has moved 10 pips in one tick Bid may well be further than oppositedistance 

here is tick the next pricequote you get from broker

if price was 1.34567   and next price now is  1.34539    then price has moved  29 points    or 2.9 pips

With news times pricedifference can come huge sometimes both directions in short time  

through requote or other reason you can miss entrypoints very easily 

 
luisneves:


Hi, RaptorUK and deVries;

Thank you for your attention to my issue.

RaptorUK, when you say that a tick is not a pip then am I right to say that the TickValue is the bad guy ? 

No,  think of TickValue as being PointValue,  meaning for 1 lot what is the account currency value of 1 point.

 

The ticks I am talking about are the ticks that call your start() function that are the result of price movement . . .  what I am saying is that price does not move in set increments,  it may move 1 point, 1 point, 1 point, 5 points, 2 points, 10 points, 1 point, 3 points, 15 points, 1 point, 6 points etc  with each move being a tick.

 
RaptorUK:

No,  think of TickValue as being PointValue,  meaning for 1 lot what is the account currency value of 1 point.

 

The ticks I am talking about are the ticks that call your start() function that are the result of price movement . . .  what I am saying is that price does not move in set increments,  it may move 1 point, 1 point, 1 point, 5 points, 2 points, 10 points, 1 point, 3 points, 15 points, 1 point, 6 points etc  with each move being a tick.


Hi and good morning RaptorUK,

 So, in that case  and as far I understand so far, there is no way for one have control when a precise distance needs to be get. I thought that using the order profit one could get a precise indication of the movement (always learning...)

Thank you for your support.

Luis 

Reason: