I want to accumulated a static variable but only once per bar. If someone could suggest a way to do this I'd be grateful. My problem is that it gets re-added on every tick when I only want to run the calculation once per bar on the very first tick.
Please help me I am using code posting above and its not working 100%. If I get 1 signal it will not trade but if it wil get second signal it will trade . Its very strange why in second signal trade but in first not??
yossi1177: someone can help me to do code or EA for trailing profit? i think that it is very good idea
This is a simple 3 candles profit trailing (PT) code or more like a trailing stop. It is activated by GapPT=number of pips in profit. Attached is chart example of 3 candles method.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
https://www.mql5.com/en/forum/173060
https://www.mql5.com/en/forum/173060
static variable accumulation on open
I want to accumulated a static variable but only once per bar. If someone could suggest a way to do this I'd be grateful. My problem is that it gets re-added on every tick when I only want to run the calculation once per bar on the very first tick.
static datetime myTime = 0;
if(myTime != Time[0])
{
//do what you want to be done once after openning new bar
myTime = Time[0];
}
static datetime myTime = 0;
if(myTime != Time[0])
{
//do what you want to be done once after openning new bar
myTime = Time[0];
}Thank you timbobo!
Please help me I am using code posting above and its not working 100%. If I get 1 signal it will not trade but if it wil get second signal it will trade . Its very strange why in second signal trade but in first not??
It is necessary to see your EA to correct.
i need help to code - trailing profit
someone can help me to do code or EA for trailing profit?
i think that it is very good idea
someone can help me to do code or EA for trailing profit? i think that it is very good idea
exactly the opposite from trailing stop
someone can help me to do code or EA for trailing profit? i think that it is very good idea
Well, to call it a trailing profit is somewhat of a mis-nomer because it wouldn't trail price action. But I'll see what I can do.
someone can help me to do code or EA for trailing profit? i think that it is very good idea
This is a simple 3 candles profit trailing (PT) code or more like a trailing stop. It is activated by GapPT=number of pips in profit. Attached is chart example of 3 candles method.
Wackena
extern int GapPT=10;
int c, n, p;
double LongPT, ShortPT;
c=0; p=0;
for(n=0;n<=6;n++)
{
if(High[c+1]Low[c+2]) {n--;}
c++;
p++;
if(n==3) break;
}
ShortPT=NormalizeDouble(High,Digits);
LongPT=NormalizeDouble(Low,Digits);
int total = OrdersTotal();
for(int cnt=0;cnt<total;cnt++) {
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()==OP_BUY && OrderClosePrice()-OrderOpenPrice() >= GapPT*Point)
{
OrderModify(OrderTicket(),OrderOpenPrice(),LongPT,OrderTakeProfit(),0,GreenYellow);
}
if(OrderType()==OP_SELL && OrderOpenPrice()-OrderClosePrice() >= GapPT*Point)
{
OrderModify(OrderTicket(),OrderOpenPrice(),ShortPT,OrderTakeProfit(),0,Red);
}
}