# About Pivot Points and Pending Orders.

31

Hello all,

Firstly i want to say that i m very new in MQL.I want to buy orders at pivot point at the start of day and place of pending orders.I have no idea of MQL startup and whether i don't know also how much this program is critical.I read about pivot point and pending orders.

How will i start to write the program plz suggest me the logic.

Thanx..

776

ajay009ajay:

Hello all,

Firstly i want to say that i m very new in MQL.I want to buy orders at pivot point at the start of day and place of pending orders.I have no idea of MQL startup and whether i don't know also how much this program is critical.I read about pivot point and pending orders.

How will i start to write the program plz suggest me the logic.

Thanx..

2. Use iCustom to access the indicator, from the EA: (https://docs.mql4.com/indicators/iCustom)

• access: sup3, sup2, sup1, pivot, res1, res2, res3
• set indexbuffer number in the indicator is assigned to each pivot level

3. Use ordersend function to send buy orders or pending orders, when current close price(Close[0]) hits any of the pivot points in the indicator: (https://docs.mql4.com/trading/OrderSend)

• This is completed with an if function.
• if(Close[0]==sup3 || Close[0]==sup2 || Close[0]==sup1 || Close[0]==pivot || Close[0]==res3 || Close[0]==res1 || Close[0]==res1) {"execute ordersend function to place order."}
31

c0d3:

2. Use iCustom to access the indicator, from the EA: (https://docs.mql4.com/indicators/iCustom)

• access: sup3, sup2, sup1, pivot, res1, res2, res3
• set indexbuffer number in the indicator is assigned to each pivot level

3. Use ordersend function to send buy orders or pending orders, when current close price(Close[0]) hits any of the pivot points in the indicator: (https://docs.mql4.com/trading/OrderSend)

• This is completed with an if function.
• if(Close[0]==sup3 || Close[0]==sup2 || Close[0]==sup1 || Close[0]==pivot || Close[0]==res3 || Close[0]==res1 || Close[0]==res1) {"execute ordersend function to place order."}

First Thanx to give reply me.I downloaded the code of indicator and this is running well in my EA.

Can u look a bit on it,Whether i am doing wrong or right.

Files:
776

ajay009ajay:

First Thanx to give reply me.I downloaded the code of indicator and this is running well in my EA.

Can u look a bit on it,Whether i am doing wrong or right.

i looked at your code, and you have to use iCustom, to access the indicator, to get the values of each pivot point.

here is how you would access res3 with iCustom in your EA

`double res3=iCustom(NULL, 0, "Pivot Points - Daily (Shifted)",0,0);`

Below is the code from the indicator:(changing the red number in the iCustom function, changes which pivot point is read by the EA.

`   SetIndexBuffer( 0, Res3);   SetIndexBuffer( 1, Res2);   SetIndexBuffer( 2, Res1);   SetIndexBuffer( 3, Pivot);   SetIndexBuffer( 4, Sup1);   SetIndexBuffer( 5, Sup2);   SetIndexBuffer( 6, Sup3);`

So if you want to read Sup1, into your EA from the indicator, you would access it like this:

`double sup1=iCustom(NULL, 0, "Pivot Points - Daily (Shifted)",4,0);`
31

c0d3:

i looked at your code, and you have to use iCustom, to access the indicator, to get the values of each pivot point.

here is how you would access res3 with iCustom in your EA

Below is the code from the indicator:(changing the red number in the iCustom function, changes which pivot point is read by the EA.

So if you want to read Sup1, into your EA from the indicator, you would access it like this:

"

I renamed the indicator file to " PivotPoints.mq4" and compiled it.The concept behind this is i m taking the pivot value by this " PivotPoints.ex4" from indicator diretory.

and again compairing this to the close price if any pivot value will be equal to close price then this will go to BUY ORDERS.

right ?

Again plz look the code and i am sending u the screeenshot also.

thanx...

Files:
776

ajay009ajay:

I renamed the indicator file to " PivotPoints.mq4" and compiled it.The concept behind this is i m taking the pivot value by this " PivotPoints.ex4" from indicator diretory.

and again compairing this to the close price if any pivot value will be equal to close price then this will go to BUY ORDERS.

right ?

Again plz look the code and i am sending u the screeenshot also.

thanx...

Yup you got it, the code is right, so far. Your next issue is to buy, or to sell. In theory, if a price touches a res1, res2, res3 you should SELL. If a price touches sup1, sup2, sup3 you should BUY. I'm not sure you want to always BUY when a pivot is touched, as you currently have in your code.

So you could have the EA always scanning the close price, and wait until the pivots are touched. Or you can send 6 pending orders, each order will represent a pivot price, if during the day, the price goes to that pivot values, the orders will be live. This will save your CPU, and the EA will not run 24/6, it will run once a day, and set 1 through 6 pending orders, at the pivot levels.

It really depends on what you want to do.

31

c0d3:

Yup you got it, the code is right, so far. Your next issue is to buy, or to sell. In theory, if a price touches a res1, res2, res3 you should SELL. If a price touches sup1, sup2, sup3 you should BUY. I'm not sure you want to always BUY when a pivot is touched, as you currently have in your code.

So you could have the EA always scanning the close price, and wait until the pivots are touched. Or you can send 6 pending orders, each order will represent a pivot price, if during the day, the price goes to that pivot values, the orders will be live. This will save your CPU, and the EA will not run 24/6, it will run once a day, and set 1 through 6 pending orders, at the pivot levels.

It really depends on what you want to do.

What is difference between pending orders and new orders.The function " ( int OrderSend( string symbol, int cmd, double volume, double price, int slippage,
double stoploss, double takeprofit, string comment=NULL, int magic=0, datetime
expiration=0, color arrow_color=CLR_NONE) ) "

which used for new orders or pending . How will i know this is placing pending orders or making new orders.

Like when close price tuches the "pivot" this will new orders to buy.And when close price touches the res1,res2,res3 this will SELL and when close price touches the sup1,sup2,sup3 this will BUY orders.

//////////////////////////////////////

if(Close[0]==pivot) // touches the pivot point //////

if(Close[0]==sup3 || Close[0]==sup2 || Close[0]==sup1) /// touches at sup ///

if(Close[0]==res3 || Close[0]==res1 || Close[0]==res1)///

ticket=OrderSend(Symbol(),OP_SELL,1,Bid,3,Bid-25*Point,Bid+25*Point,"My order #2",16384,0,Green);

///////////////////////////////

is this right ?

plz clear a bit the last quotation " So you could have the EA always scanning the close price, and wait until the pivots are touched. Or you can send 6 pending orders..............................................".

Thanx...

776

ajay009ajay:

What is difference between pending orders and new orders.The function " ( int OrderSend( string symbol, int cmd, double volume, double price, int slippage,
double stoploss, double takeprofit, string comment=NULL, int magic=0, datetime
expiration=0, color arrow_color=CLR_NONE) ) "

which used for new orders or pending . How will i know this is placing pending orders or making new orders.

Like when close price tuches the "pivot" this will new orders to buy.And when close price touches the res1,res2,res3 this will SELL and when close price touches the sup1,sup2,sup3 this will BUY orders.

//////////////////////////////////////

if(Close[0]==pivot) // touches the pivot point //////

if(Close[0]==sup3 || Close[0]==sup2 || Close[0]==sup1) /// touches at sup ///

if(Close[0]==res3 || Close[0]==res1 || Close[0]==res1)///

ticket=OrderSend(Symbol(),OP_SELL,1,Bid,3,Bid-25*Point,Bid+25*Point,"My order #2",16384,0,Green);

///////////////////////////////

is this right ?

plz clear a bit the last quotation " So you could have the EA always scanning the close price, and wait until the pivots are touched. Or you can send 6 pending orders..............................................".

Thanx...

• The following is correct, your SELL order had incorrect StopLoss and TakeProfit:
• if(Close[0]==sup3 || Close[0]==sup2 || Close[0]==sup1) /// touches at sup ///

• if(Close[0]==res3 || Close[0]==res1 || Close[0]==res1)///
• ticket=OrderSend(Symbol(),OP_SELL,1,Bid,3,Bid+25*Point,Bid-25*Point,"My order #2",16384,0,Green);

• "So you could have the EA always scanning the close price, and wait until the pivots are touched. Or you can send 6 pending orders"
• Research the information in the following link, this is for the ordersend function: https://docs.mql4.com/constants/trading
• Once you understand these pending orders, you would basically send out 6 ordersend functions, one for each pivot point
8

Good day Dear colleagues,

I need a help

I want to open an order, when the price touch first level of support S1 or resistant R1 and close the order when the price touch PP.

I write the code that you explain , but in fact I make a mistake somewhere.

My strategy is 32 pip stop loss under or above the first level.
The order close only with stop loss and never with take profit.

I want to put limit orders on S1 or R1.
Can you help me?

Best regards
Files:
17124

if(Close[4]==sup1) /// touches at sup ///
1. Doubles are rarely equal.

Understand the links in The == operand. - MQL4 forum Ask >= OOP+n could be true because of round off and Ask >= OOP+n - 0.000005 and could be false at Ask >= OOP+n + 0.000005.

If the equality is important use (must be true at Ask == OOP+n) Use "definitely >=": Ask - (OOP+n) > -_Point/2. // Note the minus

If the equality is important use (must be false at Ask == OOP+n) Use "definitely >" Ask - (OOP+n) > _Point/2.

If the equality is not important (false when equal or true when not) just use Ask > OOP+n

2. Your if is not if price touched sup, your if is four bars ago closed exactly at sup. Test for a touch: H >= sup && L <= sup.
8

whroeder1:
if(Close[4]==sup1) /// touches at sup ///
1. Doubles are rarely equal.

Understand the links in The == operand. - MQL4 forum Ask >= OOP+n could be true because of round off and Ask >= OOP+n - 0.000005 and could be false at Ask >= OOP+n + 0.000005.

If the equality is important use (must be true at Ask == OOP+n) Use "definitely >=": Ask - (OOP+n) > -_Point/2. // Note the minus

If the equality is important use (must be false at Ask == OOP+n) Use "definitely >" Ask - (OOP+n) > _Point/2.

If the equality is not important (false when equal or true when not) just use Ask > OOP+n

2. Your if is not if price touched sup, your if is four bars ago closed exactly at sup. Test for a touch: H >= sup && L <= sup.
Thanks for the answer , but I'm really beginner in mq4 programming. I can't understand how I can change the program. Sorry for that. What i must change. I can't  definite the open price and tp price.

if(Close[4]==sup1) /// touches at sup ///......       its my mistake i mean the last daily bar ...  if(Close[0]==sup1)