How to store & get the open,close price from previous closed candle with a certain condition in MQL4 / MT4?
How to store & get the open,close price from previous closed candle with a certain condition in MQL4 / MT4?
Loading saved threads...
Roller · External communityPost link
External question — Stack Overflow Stack Exchange
Author: Roller
Original post: https://stackoverflow.com/questions/64772281
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
Hi, how do I store and get the value of high and open price of previous closed candle since the value will keep changing on every previous closed candle? The idea is to get the High & open from a certain condition when the condition true store the value of Open and High.
Technical term called as a pullback area.
double high=0,open=0,
AskPrice=MarketInfo(OrderSymbol(),MODE_ASK),
BidPrice=MarketInfo(OrderSymbol(),MODE_BID);
bool sellcondition = Open[1] > Close[1] && High[1] > Open[1] && Close[1] > Low[1];
if( sellcondition )
{
open=Open[1];
high=High[1];
}
if(Bid > open && Bid < high)
{
OrderSend(Symbol(),OP_SELL,0.01,BidPrice,3,0, 0,"",0,0,clrRed);
}
Quote
Report
Enivid · External communityPost link
External answer — Stack Overflow Stack Exchange
Author: Enivid
Original post: https://stackoverflow.com/a/65064986
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
If you declare your
high
and
open
as
global scope
or
static
variables and then will only assign values to them when your condition is met, then at any future bar, they will contain the High and Open values of the last time the condition has been met. For example, your code snippet can be modified as follows:
static double high=0,open=0,
AskPrice=MarketInfo(OrderSymbol(),MODE_ASK),
BidPrice=MarketInfo(OrderSymbol(),MODE_BID);
bool sellcondition = Open[1] > Close[1] && High[1] > Open[1] && Close[1] > Low[1];
if( sellcondition )
{
open=Open[1];
high=High[1];
}
if(Bid > open && Bid < high)
{
OrderSend(Symbol(),OP_SELL,0.01,BidPrice,3,0, 0,"",0,0,clrRed);
}
Quote
Report
Post Reply
Checking account access…