i believe this wont happen?
x=Ask;
}
if (Ask==(x-(300*Point)))
i believe this wont happen?
x=Ask;
}
if (Ask==(x-(300*Point)))
Do you have any idea for this?
Thanks so much for your answer.
Show you calculation on the chart using Comment and you'll most probably see where you code does follow your intention..
Carl Schreiber: I can be as 300 is an integer Point is converted to an integer and becomes zero!
| Wrong, the int becomes a double. Typecasting - Data Types - Language Basics - MQL4 Reference |
trader92: , and when Ask price is equal to x-300*Point | Doubles rarely compare 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 |
NextTrade=midnight+DAY+StartHour*HOUR+StartMinute*MINUTE;
if(now>=NextTrade)
{
x=Ask;
}
When it passes midnight on Monday, NextTrade will be 12:20 on Wednesday.
So the if condition will never be true.
Even if it could be true x would be constantly updated so
if(Ask==(x-(300*Point)))
do
{
int ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,1,0,Ask+(TP*Point),comment,magic,0,0);
}
while(OrderSend(Symbol(),OP_BUY,Lots,Ask,1,0,Ask+(TP*Point),comment,magic,0,0)==0);
int ticket=-1;
if(Ask==(x-(300*Point)))
{
do
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,1,0,Ask+(TP*Point),comment,magic,0,0);
}
while(ticket==-1);
}
{
static bool get_price=true;
static datetime current_midnight=0;
datetime now=TimeCurrent();
datetime midnight=now -(now%DAY);
if(midnight>current_midnight)
{
current_midnight=midnight;
NextTrade=midnight+StartHour*HOUR+StartMinute*MINUTE;
get_price=true;
}
if(get_price && now>=NextTrade)
{
x=Ask-(300*Point);
get_price=false;
}
int ticket=-1;
if(Ask<=x)
{
do
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,1,0,Ask+(TP*Point),comment,magic,0,0);
}
while(ticket==-1);
}
}
I think that you need to do something like
{
static bool get_price=true;
static datetime current_midnight=0;
datetime now=TimeCurrent();
datetime midnight=now -(now%DAY);
if(midnight>current_midnight)
{
current_midnight=midnight;
NextTrade=midnight+StartHour*HOUR+StartMinute*MINUTE;
get_price=true;
}
if(get_price && now>=NextTrade)
{
x=Ask-(300*Point);
get_price=false;
}
int ticket=-1;
if(Ask<=x)
{
do
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,1,0,Ask+(TP*Point),comment,magic,0,0);
}
while(ticket==-1);
}
}
result of this code is:
2 2017.01.04 13:47 buy 2 0.10 85.376 0.000 85.377 0.00 300.00
3 2017.01.04 13:47 buy 3 0.10 85.375 0.000 85.376 0.00 300.00
4 2017.01.04 13:47 buy 4 0.10 85.374 0.000 85.375 0.00 300.00
5 2017.01.04 13:47 buy 5 0.10 85.373 0.000 85.374 0.00 300.00
6 2017.01.04 13:47 buy 6 0.10 85.372 0.000 85.373 0.00 300.00
7 2017.01.04 13:47 buy 7 0.10 85.373 0.000 85.374 0.00 300.00
8 2017.01.04 13:47 buy 8 0.10 85.372 0.000 85.373 0.00 300.00
9 2017.01.04 13:47 buy 9 0.10 85.373 0.000 85.374 0.00 300.00
10 2017.01.04 13:47 buy 10 0.10 85.372 0.000 85.373 0.00 300.00
11 2017.01.04 13:47 buy 11 0.10 85.373 0.000 85.374 0.00 300.00
12 2017.01.04 13:47 buy 12 0.10 85.372 0.000 85.373 0.00 300.00
13 2017.01.04 13:47 buy 13 0.10 85.373 0.000 85.374 0.00 300.00
Wrong, the int becomes a double. Typecasting - Data Types - Language Basics - MQL4 Reference | |
| Doubles rarely compare 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 |
{
datetime now = TimeCurrent();
datetime midnight = now - (now % DAY);
NextTrade = midnight + DAY + StartHour*HOUR + StartMinute*MINUTE;
if(now >= NextTrade){
double x=Ask;
if ((Ask-x)>=-_Point*300)
{
do {
int ticket =OrderSend(Symbol(),OP_BUY,Lots,Ask,1,0,Ask+(TP*Point),comment,magic,0,0);
}
while (OrderSend(Symbol(),OP_BUY,Lots,Ask,1,0,Ask+(TP*Point),comment,magic,0,0)==0 );
}
}
}
And i tried to understand information of links but because of my poor language i can't understand !
And i tried this to but not work again !!
{
datetime now = TimeCurrent();
double x=Ask;
double z=(x/Point);
double y=(z-10); //with this 3 steps , first Fixed Ask is now an integer number but when i used it in AUDJPY it set Point=0.00001 why ? it should set Point=0.001 !
if(now >= NextTrade)
{ double s=Ask;
double g=(s/Point); //And with this 2 steps ,Variable Asks is now an integer
if (y<=g)
{
do {
ticket =OrderSend(Symbol(),OP_BUY,Lots,Ask,1,0,Ask+(TP*Point),comment,magic,0,0);
}
while (ticket==0);
}
}
if(ticket < 0)
{
printf("OrderSend() failed. Error code: %i", GetLastError());
}
else
{
datetime midnight = now - (now % DAY);
NextTrade = midnight + DAY + StartHour*HOUR + StartMinute*MINUTE;
printf("Next Trade scheduled for %s", TimeToString(NextTrade));
}
}
Thanks so much for your answer .
Thanks for your answer
result of this code is:
2 2017.01.04 13:47 buy 2 0.10 85.376 0.000 85.377 0.00 300.00
3 2017.01.04 13:47 buy 3 0.10 85.375 0.000 85.376 0.00 300.00
4 2017.01.04 13:47 buy 4 0.10 85.374 0.000 85.375 0.00 300.00
5 2017.01.04 13:47 buy 5 0.10 85.373 0.000 85.374 0.00 300.00
6 2017.01.04 13:47 buy 6 0.10 85.372 0.000 85.373 0.00 300.00
7 2017.01.04 13:47 buy 7 0.10 85.373 0.000 85.374 0.00 300.00
8 2017.01.04 13:47 buy 8 0.10 85.372 0.000 85.373 0.00 300.00
9 2017.01.04 13:47 buy 9 0.10 85.373 0.000 85.374 0.00 300.00
10 2017.01.04 13:47 buy 10 0.10 85.372 0.000 85.373 0.00 300.00
11 2017.01.04 13:47 buy 11 0.10 85.373 0.000 85.374 0.00 300.00
12 2017.01.04 13:47 buy 12 0.10 85.372 0.000 85.373 0.00 300.00
13 2017.01.04 13:47 buy 13 0.10 85.373 0.000 85.374 0.00 300.00
int ticket=-1;
if(Ask<=x)
{
do
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,1,0,Ask+(TP*Point),comment,magic,0,0);
if(ticket>0)
x=0;
}
while(ticket==-1);
}
int ticket=-1;
if(Ask<=x)
{
do
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,1,0,Ask+(TP*Point),comment,magic,0,0);
if(ticket>0)
x=0;
}
while(ticket==-1);
}
Thanks so much for your answer
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
This code should give price at 12:20 and add it to x
Then check every thick , and when Ask price is equal to x-300*Point then set order while order not equal to 0 (this is for low that code maximum order once a day)
But not work!!
Please help me
Thanks
#define HOUR 3600 // hour is 3600 seconds
#define MINUTE 60 // minute is 60 seconds
input double Lots = 0.1;
input int TP = 200;
input int SL = 200;
input int slippage = 3;
input string comment = "MyOrder";
input int magic = 1234;
input int StartHour = 12;
input int StartMinute = 20;
datetime NextTrade = StartHour*HOUR + StartMinute*MINUTE;
double x=0;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
datetime now = TimeCurrent();
datetime midnight = now - (now % DAY);
NextTrade = midnight + DAY + StartHour*HOUR + StartMinute*MINUTE;
if(now >= NextTrade){
x=Ask;
}
if (Ask==(x-(300*Point)))
{
do {
int ticket =OrderSend(Symbol(),OP_BUY,Lots,Ask,1,0,Ask+(TP*Point),comment,magic,0,0);
}
while (OrderSend(Symbol(),OP_BUY,Lots,Ask,1,0,Ask+(TP*Point),comment,magic,0,0)==0 );
}
}
//---