double price = 0; start() { if ( price == 0 || Bid < price ) { price = Bid; } else if ( ( Bid - price ) / Point ) >= 5 ) { OrderSend( ... ); price = Bid; } }
Something like the following perhaps, which is an EA that would make an order whenever it discovers a price rise of 5 pips or more.
double price = 0; start() { if ( price == 0 || Bid < price ) { price = Bid; } else if ( ( Bid - price ) / Point ) >= 5 ) { OrderSend( ... ); price = Bid; } }
Something like the following perhaps, which is an EA that would make an order whenever it discovers a price rise of 5 pips or more.
double price = 0; start() { if ( price == 0 || Bid < price ) { price = Bid; } else if ( ( Bid - price ) / Point ) >= 5 ) { OrderSend( ... ); price = Bid; } }Great. Is there a way to send a message every time the price rises by 5 pips as well? Thanks so much.
Brave0Heart.
might need to put that previous price in a global var, and read it next time, as
price would have no value each run.
double price = 0;
start() {
price=GlobalVariableGet("price");// get what you put in last trade
if ( price == 0 || Bid < price ) {
price = Bid;
} else if ( ( Bid - price ) / Point ) >= 5 ) {
OrderSend( ... );
price = Bid;
GlobalVariableSet("price",price); // set new price of last trade
}
}
might need to put that previous price in a global var, and read it next time, as
price would have no value each run.
double price = 0;
start() {
price=GlobalVariableGet("price");// get what you put in last trade
if ( price == 0 || Bid < price ) {
price = Bid;
} else if ( ( Bid - price ) / Point ) >= 5 ) {
OrderSend( ... );
price = Bid;
GlobalVariableSet("price",price); // set new price of last trade
}
}
double price = 0;
double OffSet = 0;
price = Bid; // make price = bid
OffSet = MathAbs(Price - Bid); // to start with, the offset between the price and the bid will be <5
While (OffSet < 5) // Keep going as long as the offset < 5
{
Print("The Offset is ",OffSet); // just to show off,keep printing this
OffSet = MathAbs(Price - Bid); // every cycle refresh the offset
}
// now make an order because Offset must be >= 5
But my problem with the above is this sort of thing is CPU intensive, isn't it? How do indicators get around this problem. Is there some sort of function that tells us when the next tick has happened? If so, then we would simply check what it was.
Thanks so much, hoping you can help me clarify this soon.
Steve
might need to put that previous price in a global var, and read it next time, as
price would have no value each run.
double price = 0;
start() {
price=GlobalVariableGet("price");// get what you put in last trade
if ( price == 0 || Bid < price ) {
price = Bid;
} else if ( ( Bid - price ) / Point ) >= 5 ) {
OrderSend( ... );
price = Bid;
GlobalVariableSet("price",price); // set new price of last trade
}
}
double price = 0;
double OffSet = 0;
price = Bid; // make price = bid
OffSet = MathAbs(Price - Bid); // to start with, the offset between the price and the bid will be <5
While (OffSet < 5) // Keep going as long as the offset < 5
{
Print("The Offset is ",OffSet); // just to show off,keep printing this
OffSet = MathAbs(Price - Bid); // every cycle refresh the offset
}
// now make an order because Offset must be >= 5
But my problem with the above is this sort of thing is CPU intensive, isn't it? How do indicators get around this problem. Is there some sort of function that tells us when the next tick has happened? If so, then we would simply check what it was.
Thanks so much, hoping you can help me clarify this soon.
Steve
//+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { double Price = 0; double OffSet = 0; Price = Bid; // make price = bid OffSet = MathAbs(Price - Bid); // to start with, the offset between the price and the bid will be <5 while(OffSet < 5) // Keep going as long as the offset < 5 { Print("The Offset is ",OffSet); // just to show off,keep printing this OffSet = MathAbs(Price - Bid); // every cycle refresh the offset } // now make an order because Offset must be >= 5 return(0); } //+------------------------------------------------------------------+ //| Calculate optimal lot size | //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ // the end.
In my first snippet, the Bid price of the start() invocation is stored away in a variable that is declared outside of functions. Such a declaration makes the variable "live" throughout the EA instance life-time, and in particular it is preserved between successive start() function invocations. More precisely, the last assignment made to it in one start() function call can be retrieved in the subsequent start() method call.
A global variable, as oldman suggest, could be useful, to make the value live and be accessible also between EA instances, but it is not needed for use within the same EA instance, and should even be avoided unless you do want interactions between EA instances.
Thus, (https://docs.mql4.com/runtime/start) when a "tick" arrives, the start() method is invoked, and it is expected to return so that when the next "tick" arrives, the start() method is invoked again. If the start() method has not returned when the next "tick" arrives, then your EA will fail to observe that "tick".
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
How can I create a buy order every 5 pips?
Thanks
Brave0Heart