Entery Price + 20 pips?

 
int midpoint = 0;

midpoint = (RectanglePriceMax - RectanglePriceMin)/Point;

if (OrdersTotal() ==0 && sPatternType == "Butterfly" && Bid < RectanglePriceMax && Bid > RectanglePriceMin)
{
   OrderSend(Symbol(),OP_SELL,1,midpoint,5,RectanglePriceMax,Bid-200*Point,"Order Sent", 16385,0,Green);

}


Hello!


Hoping someone could help me out here... Im trying to insert an order so that it enters half way up this yellow rectangle.


RectanglePriceMax = This is the price level of the TOP of the triangle

RectanglePriceMin = This is the price level of the BOTTOM of the triangle


Although no position is entered



Rec

 

trader346 wrote >>

Hello!

Hoping someone could help me out here... Im trying to insert an order so that it enters half way up this yellow rectangle.

RectanglePriceMax = This is the price level of the TOP of the triangle

RectanglePriceMin = This is the price level of the BOTTOM of the triangle

Although no position is entered


Rec

I'm new at this. But, I have been comparing different scripts and changing and modifying with some success. I'm sure someone else can tell you better, but until then try this. First, you didn't say whether you where trying to enter a buy or sell order. I'll have to rely on what the order operation says. I notice that both words "Point" are active. I haven't seen any scripts where that should be active at the place where it is located. So, de-activate it, at both places. ( When you type out the word point completely [ use a small"p"] you will get a drop down menu. Don't click on "Point" within the menu. Click on another part of your document out side of the menu. The drop down menu will disappear, and the word will not be active.

The operation that says " OP_SELL ", this is for an immediate sell at market. If you are trying to sell at a future higher point you need " OP_SELLLIMIT ". If you are trying to do a pending buy at a higher point then you need " OP_BUYSTOP ". and then change the word " Bid " to "Ask".

I'm not sure but, it looks like both words Bid (in the line with the word Butterfly in it) should also be de-activated. You can maybe try that last, after you have tried the other stuff. I'm sure I don't need to tell you that the markets will have to be open for you to know if this resolves the issue. But you can still do preliminary testing with the Compiler function. And see if you get any errors. Also, if you attach it to a chart click on Experts and Journal to see if there are any errors there also. Note that "error 132" just means that the markets are closed. If you need a list of error definitions open up MetaEditor. under Navigator open Include, then open stderror.mqh. At least that is where it is located for me.

If I'm wrong about anything I've said then, someone else, HELP.

Alan

 
trader346:

Hoping someone could help me out here... Im trying to insert an order so that it enters half way up this yellow rectangle. 

RectanglePriceMax = This is the price level of the TOP of the triangle

RectanglePriceMin = This is the price level of the BOTTOM of the triangle

I think Alan's pretty much right, especially in the ambiguities he's flagging up. In particular, two things spring to mind from the example code and rectangle you've given. 


Firstly, the 4th parameter for OrderSend() should be a price. What you're supplying seems to be the size, in pips, of the rectangle: (RectanglePriceMax - RectanglePriceMin)/Point. The price halfway up the rectangle would instead be given by ((RectanglePriceMax - RectanglePriceMin) / 2) + RectanglePriceMin. Depending on your broker, you may need to bear in mind that the resulting price will be fractional (i.e. sub-pip) if the rectangle is an even number of pips in size, and the broker may require you round the price to the nearest pip.


Secondly, Alan's dead right to ask whether you're trying to enter at market (i.e. you know that the price is already at the halfway point), or whether you're trying to place a pending order to be filled in the future when the price hits the halfway point. If the former, then it's easiest simply to set the opening price for the order to Bid, rather than calculating the midpoint. If the latter then, as Alan says, you need to be placing an OP_SELLLIMIT or OP_SELLSTOP depending on whether the current price is above or below your trigger. And also, if you're wanting to place a pending order, then the calculation of your T/P should probably be based on the midpoint minus 200 pips, not the current Bid minus 200 pips.

 
jjc wrote >>

I think Alan's pretty much right, especially in the ambiguities he's flagging up. In particular, two things spring to mind from the example code and rectangle you've given.

Firstly, the 4th parameter for OrderSend() should be a price. What you're supplying seems to be the size, in pips, of the rectangle: (RectanglePriceMax - RectanglePriceMin)/Point. The price halfway up the rectangle would instead be given by ((RectanglePriceMax - RectanglePriceMin) / 2) + RectanglePriceMin. Depending on your broker, you may need to bear in mind that the resulting price will be fractional (i.e. sub-pip) if the rectangle is an even number of pips in size, and the broker may require you round the price to the nearest pip.

Secondly, Alan's dead right to ask whether you're trying to enter at market (i.e. you know that the price is already at the halfway point), or whether you're trying to place a pending order to be filled in the future when the price hits the halfway point. If the former, then it's easiest simply to set the opening price for the order to Bid, rather than calculating the midpoint. If the latter then, as Alan says, you need to be placing an OP_SELLLIMIT or OP_SELLSTOP depending on whether the current price is above or below your trigger. And also, if you're wanting to place a pending order, then the calculation of your T/P should probably be based on the midpoint minus 200 pips, not the current Bid minus 200 pips.

Where jjc changed the formula to ((RectanglePriceMax - RectanglePriceMin) / 2) + RectanglePriceMin, after looking a thinking about it I am quite sure he is correct.

 
aj34997 wrote >>

Where jjc changed the formula to ((RectanglePriceMax - RectanglePriceMin) / 2) + RectanglePriceMin, after looking a thinking about it I am quite sure he is correct.

Thanks guys!! Appreciate it ...

So I've revised my OrderSend command:

if (OrdersTotal() ==0 && sPatternType == "Butterfly" && Ask > RectanglePriceMax && Ask < RectanglePriceMin)
{
   OrderSend(Symbol(),OP_BUYLIMIT,1,RectanglePriceMin -50,3,RectanglePriceMax,RectanglePriceMin +50,"Order Sent", 16384,0,Green);
Print("Recmax:", RectanglePriceMax, "Recmin:", RectanglePriceMin, "This is for the bullish pattern");
   
}

What im trying to do here, instead of calculating the midpoint, just saying to take the rectanglePriceMin (the base of the rectangle) and go into the rectangle 50 pips... then the stop will be the rectanglepricemax (or the bottom of the rectangle)... but my orders never seem to get filled... no errors though...


rec

 
trader346:

Thanks guys!! Appreciate it ...

So I've revised my OrderSend command:

What im trying to do here, instead of calculating the midpoint, just saying to take the rectanglePriceMin (the base of the rectangle) and go into the rectangle 50 pips... 

OrderSend(Symbol(),OP_BUYLIMIT,1,RectanglePriceMin -50,3,RectanglePriceMax,RectanglePriceMin +50,"Order Sent", 16384,0,Green);

Unless I'm going mad, you're still mixing up pips and prices. Your entry price is now "RectanglePriceMin - 50". Let's say that RectanglePriceMin is 1.32935 (though it looks equally plausible that RectanglePriceMax is 1.32935). Therefore, you're trying to place an order at -48.67065. You need to subtract 50 pips from the entry price, not just "50". (And, for robustness, you ought ideally to have a mechanism which adjusts these kinds of parameter depending on whether your broker uses 2/4 decimal places rather than 3/5.)


As fbj reminds us elsewhere ('the error 130 (ERR_INVALID_STOPS) '), you can save a lot of time and heartache by using Print() to check exactly what parameters you're passing to order-placement functions.

Reason: