How to code? - page 20

 

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];

}

 
timbobo:
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

 
yossi1177:
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

 
yossi1177:
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.

 
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.

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);

}

}