You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
ok i figured out the pivot calculation. Thanks for your assistance.
The problem I face now is that when it correctly opens the pending order in the correct price locations it continues to open pending orders over and over every time the price action moves 1 pip.
I have looked and will continue to research why this is happening but wanted to see if you could give me a hint or help if you see a logic error I am doing.
As always thanks for your time.
extern int look_price_hour = 1; // Change for your time zone (my is +1 Hour). Should be 9AM London time.
extern int look_price_min = 35; // Offset in minutes when to look on price.
extern int close_hour = 12; // Close all orders after this hour
bool use_close_hour = true; // set it to false to ignore close_hour
int take_profit = 20;
extern int Currency_Spread = 4;
int open_long = 21;
int open_short = 21;
int stop_long = 30;
int stop_short = 30;
extern int slippage = 0;// Put what your brooker requires
extern double lots = 0.20; // Position size
extern int magic = 123;
bool clear_to_send = true;
void ReportStrategy()
{
int totalorders = HistoryTotal();
double StrategyProfit = 0.0;
double StrategyProfitOpen = 0.0;
int StrategyOrders = 0;
int StrategyOrdersOpen = 0;
for(int j=0; j<totalorders;j++)
{ if(OrderSelect(j, SELECT_BY_POS, MODE_HISTORY) &&
(OrderMagicNumber() == magic))
{
if((OrderType() == OP_BUY) ||
(OrderType() == OP_SELL))
{
StrategyOrders++;
StrategyProfit += OrderProfit();
}
}
}
totalorders = OrdersTotal();
for(j=0; j<totalorders;j++)
{ if(OrderSelect(j, SELECT_BY_POS, MODE_TRADES) &&
(OrderMagicNumber() == magic))
{
if((OrderType() == OP_BUY) ||
(OrderType() == OP_SELL))
{
StrategyOrdersOpen++;
StrategyProfitOpen += OrderProfit();
}
}
}
Comment("Daily20Pip EA Executed ", StrategyOrders,"+",StrategyOrdersOpen, " trades with ", StrategyProfit,"+",
StrategyProfitOpen," = ",StrategyProfit+StrategyProfitOpen," of profit\n",
"Server hour: ", TimeHour(CurTime()), " Local hour: ", TimeHour(LocalTime()));
return;
}
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
ReportStrategy();
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
ReportStrategy();
if(Hour() >= close_hour &&
use_close_hour){
// we are after closing time
int totalorders = OrdersTotal();
for(int j=0;j<totalorders;j++){
OrderSelect(j, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()==Symbol() &&
OrderMagicNumber() == magic){
if(OrderType() == OP_BUY)
OrderClose(OrderTicket(), OrderLots(), Bid, 0, Red);
if(OrderType() == OP_SELL)
OrderClose(OrderTicket(), OrderLots(), Ask, 0, Red);
if(OrderType() == OP_BUYSTOP || OrderType() == OP_SELLSTOP)
OrderDelete(OrderTicket());
}
}
return(0);
}
if(Hour() == look_price_hour &&
Minute() >= look_price_min &&
clear_to_send){
// Probably I need to close any old positions first:
totalorders = OrdersTotal();
for(j=0;j<totalorders;j++){
OrderSelect(j, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()==Symbol() &&
OrderMagicNumber() == magic){
if(OrderType() == OP_BUY)
OrderClose(OrderTicket(), OrderLots(), Bid, 0, Red);
if(OrderType() == OP_SELL)
OrderClose(OrderTicket(), OrderLots(), Ask, 0, Red);
if(OrderType() == OP_BUYSTOP || OrderType() == OP_SELLSTOP)
OrderDelete(OrderTicket());
}
}
}
double PIVOT;
PIVOT = (iHigh(NULL,PERIOD_D1,1) + iLow(NULL,PERIOD_D1,1) + iClose(NULL,PERIOD_D1,1))/3;
// Send orders:
OrderSend(Symbol(),
OP_BUYSTOP,
lots,
PIVOT+(open_long+Currency_Spread)*Point, // Spread included
slippage,
PIVOT+((open_long+Currency_Spread)-stop_long)*Point,
PIVOT+((open_long+Currency_Spread)+take_profit)*Point,
NULL,
magic,
0,
FireBrick);
OrderSend(Symbol(),
OP_SELLSTOP,
lots,
PIVOT-open_short*Point,
slippage,
PIVOT-(open_short-stop_short)*Point,
PIVOT-(open_short+take_profit)*Point,
NULL,
magic,
0,
FireBrick);
clear_to_send = false; // mark that orders are sent
if(!clear_to_send){ // there are active orders
int long_ticket = -1;
int short_ticket = -1;
bool no_active_order = true;
totalorders = OrdersTotal();
for(j=0;j<totalorders;j++){
OrderSelect(j, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()==Symbol() &&
OrderMagicNumber() == magic){
if(OrderType() == OP_BUYSTOP)
long_ticket = OrderTicket();
if(OrderType() == OP_SELLSTOP)
short_ticket = OrderTicket();
if(OrderType() == OP_BUY ||
OrderType() == OP_SELL) // Active order
no_active_order = false; }
}
if(short_ticket == -1 && long_ticket != -1)
OrderDelete(long_ticket);
if(long_ticket == -1 && short_ticket != -1)
OrderDelete(short_ticket);
if(long_ticket == -1 && short_ticket == -1 && no_active_order &&
Hour() != look_price_hour && Minute() >= look_price_min)
clear_to_send = true;
if(Hour() == (look_price_hour-1) &&
MathAbs(Minute() - look_price_min) < 10)
clear_to_send = true;
}
//----
return(0);
}
Regarding my previous post,
It looks like the "clear_to_send = false;" is not switching after the pending order. Any ideas?
This happened once i make the pivot my point of reference for pending orders. If I can not solve this logic then I guess I will try and figure out how to reference a piviot from an indicator and call to it from the EA. not sure if that is posible but i see those as my options.
Any advice or assistance is appriciated.
extern int look_price_hour = 1; // Change for your time zone (my is +1 Hour). Should be 9AM London time.
extern int look_price_min = 35; // Offset in minutes when to look on price.
extern int close_hour = 12; // Close all orders after this hour
bool use_close_hour = true; // set it to false to ignore close_hour
int take_profit = 20;
extern int Currency_Spread = 4;
int open_long = 21;
int open_short = 21;
int stop_long = 30;
int stop_short = 30;
extern int slippage = 0;// Put what your brooker requires
extern double lots = 0.20; // Position size
extern int magic = 123;
bool clear_to_send = true;
void ReportStrategy()
{
int totalorders = HistoryTotal();
double StrategyProfit = 0.0;
double StrategyProfitOpen = 0.0;
int StrategyOrders = 0;
int StrategyOrdersOpen = 0;
for(int j=0; j<totalorders;j++)
{ if(OrderSelect(j, SELECT_BY_POS, MODE_HISTORY) &&
(OrderMagicNumber() == magic))
{
if((OrderType() == OP_BUY) ||
(OrderType() == OP_SELL))
{
StrategyOrders++;
StrategyProfit += OrderProfit();
}
}
}
totalorders = OrdersTotal();
for(j=0; j<totalorders;j++)
{ if(OrderSelect(j, SELECT_BY_POS, MODE_TRADES) &&
(OrderMagicNumber() == magic))
{
if((OrderType() == OP_BUY) ||
(OrderType() == OP_SELL))
{
StrategyOrdersOpen++;
StrategyProfitOpen += OrderProfit();
}
}
}
Comment("Daily20Pip EA Executed ", StrategyOrders,"+",StrategyOrdersOpen, " trades with ", StrategyProfit,"+",
StrategyProfitOpen," = ",StrategyProfit+StrategyProfitOpen," of profit\n",
"Server hour: ", TimeHour(CurTime()), " Local hour: ", TimeHour(LocalTime()));
return;
}
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
ReportStrategy();
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
ReportStrategy();
if(Hour() >= close_hour &&
use_close_hour){
// we are after closing time
int totalorders = OrdersTotal();
for(int j=0;j<totalorders;j++){
OrderSelect(j, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()==Symbol() &&
OrderMagicNumber() == magic){
if(OrderType() == OP_BUY)
OrderClose(OrderTicket(), OrderLots(), Bid, 0, Red);
if(OrderType() == OP_SELL)
OrderClose(OrderTicket(), OrderLots(), Ask, 0, Red);
if(OrderType() == OP_BUYSTOP || OrderType() == OP_SELLSTOP)
OrderDelete(OrderTicket());
}
}
return(0);
}
if(Hour() == look_price_hour &&
Minute() >= look_price_min &&
clear_to_send){
// Probably I need to close any old positions first:
totalorders = OrdersTotal();
for(j=0;j<totalorders;j++){
OrderSelect(j, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()==Symbol() &&
OrderMagicNumber() == magic){
if(OrderType() == OP_BUY)
OrderClose(OrderTicket(), OrderLots(), Bid, 0, Red);
if(OrderType() == OP_SELL)
OrderClose(OrderTicket(), OrderLots(), Ask, 0, Red);
if(OrderType() == OP_BUYSTOP || OrderType() == OP_SELLSTOP)
OrderDelete(OrderTicket());
}
}
}
double PIVOT;
PIVOT = (iHigh(NULL,PERIOD_D1,1) + iLow(NULL,PERIOD_D1,1) + iClose(NULL,PERIOD_D1,1))/3;
// Send orders:
if (clear_to_send){
OrderSend(Symbol(),
OP_BUYSTOP,
lots,
PIVOT+(open_long+Currency_Spread)*Point, // Spread included
slippage,
PIVOT+((open_long+Currency_Spread)-stop_long)*Point,
PIVOT+((open_long+Currency_Spread)+take_profit)*Point,
NULL,
magic,
0,
FireBrick);
OrderSend(Symbol(),
OP_SELLSTOP,
lots,
PIVOT-open_short*Point,
slippage,
PIVOT-(open_short-stop_short)*Point,
PIVOT-(open_short+take_profit)*Point,
NULL,
magic,
0,
FireBrick);
clear_to_send = false; // mark that orders are sent
}
if(!clear_to_send){ // there are active orders
int long_ticket = -1;
int short_ticket = -1;
bool no_active_order = true;
totalorders = OrdersTotal();
for(j=0;j<totalorders;j++){
OrderSelect(j, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()==Symbol() &&
OrderMagicNumber() == magic){
if(OrderType() == OP_BUYSTOP)
long_ticket = OrderTicket();
if(OrderType() == OP_SELLSTOP)
short_ticket = OrderTicket();
if(OrderType() == OP_BUY ||
OrderType() == OP_SELL) // Active order
no_active_order = false; }
}
if(short_ticket == -1 && long_ticket != -1)
OrderDelete(long_ticket);
if(long_ticket == -1 && short_ticket != -1)
OrderDelete(short_ticket);
if(long_ticket == -1 && short_ticket == -1 && no_active_order &&
Hour() != look_price_hour && Minute() >= look_price_min)
clear_to_send = true;
if(Hour() == (look_price_hour-1) &&
MathAbs(Minute() - look_price_min) < 10)
clear_to_send = true;
}
//----
return(0);
}
Try this code out.
Ryanklefas ,
You are brilliant simply brilliant in this area.
The testing I did from you modification worked.
Not sure why adding the pivot logic interfered with current "If" logic. I probably needed to establish the pivot code in a different location. However, I see how you isolated the pending order code and that works so far.
Thank you for the URL that pointed me to code examples. That will be a great resource as I improve my programing skills.
I find it interesting/frustrating how solving one issue sometimes causes another.
Current issue: I now need to find out why this code only allows pending orders for prices with 5 digits and not 3.
Example: 1.1234 works fine but 1.12 gives an error that 1.123333 is not a valid price for OrderSend.
So it works on GBP/USD but not on USD/JPY.
Again thanks for your time.
Ryanklefas ,
You are brilliant simply brilliant in this area.
Thank you.
As for your problem:
Make sure before you send the pivot values to the orderSend function, you have normailized then with the NormalizeDouble function; use the predeifined value "Digits" as the second parameter to round the double to the appropriate nuimber of digits for your currency.
my problem has been how to round the the calculted value to the nearest decimal place.
I think the normalizeDouble function would work for you too. I've also seen code that uses the MathFloor and MathCeiling functions to accomplish the same thing.
Another help
Can anybody tell me how to do this?
Can anybody tell me how to do this?
I think it is related to this thread https://www.mql5.com/en/forum/176969
Set color of level in code
Can someone please show me how I can set the level1 30 to Green and leve2 70 to Red ?
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 DodgerBlue
#property indicator_level1 30
#property indicator_level2 70
#property indicator_minimum 0
#property indicator_maximum 100
Thanks in advance
Can someone please show me how I can set the level1 30 to Green and leve2 70 to Red ?
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 DodgerBlue
#property indicator_level1 30
#property indicator_level2 70
#property indicator_minimum 0
#property indicator_maximum 100
Thanks in advanceI think this section of the MetaEditor will be what you are looking for:
MQL4 Reference - Basics - Preprocessor - Controlling compilation