how to calculate to double up my last Takeprofit.

 

I want create a EA. EA work like. Take profit start with 50 pips. then every next trade TP will be double form last trade. What is the calculation solve this problem.

1. Trade TP : 50

2. Trade TP : 100

3. Trade TP : 200

4. Trade TP : 400

 

You would store TP as a static or Global variable, then next time conditions are met you would multiply TP*2

If OrderSend() fails then TP/2 to return it to the same value.

 
Hey you can do something like TP=TP*2 .
 
GumRai: You would store TP as a static or Global variable, then next time conditions are met you would multiply TP*2

And when the terminal is restarted (chart accidentally closed, power fail, OS crash, etc.) you've lost the variable.

Code the EA to recover. Read history and find the last closed order. TP = OrderTakeProfit() - OrderOpenPrice()

 
tonny:
Hey you can do something like TP=TP*2 .


Wrong that will fail if all trades close

then you can't restart with first TP-level

double FirstTP = 50;
double TP = MathPow(2,EATrades) * FirstTP; 
 
deVries:


Wrong this will fail if all trades close

then you can't restart with first TP-level

Ofcourse he'll need to implement more code to neutralize some bugs that might appear. Im just giving a quick idea because im currently replying from mobile and cant post much code example.
 
WHRoeder:

And when the terminal is restarted (chart accidentally closed, power fail, OS crash, etc.) you've lost the variable.

Code the EA to recover. Read history and find the last closed order. TP = OrderTakeProfit() - OrderOpenPrice()


In the case of chart accidentally closed or power failure, a Global variable will still be there.

You would write code in init() to recover values as necessary.

You are saying that we should never use static or global scope variables and should recalculate values every time in case there is a shutdown?

The OP did not stipulate that TP should be double the TP of the last closed order, just the last trade.

 
GumRai: You are saying that we should never use static or global scope variables and should recalculate values every time in case there is a shutdown?

I didn't say that. I said the EA must recover. That means either recalculate values or read from persistent storage (files) when you don't have them in static/globals and write them to disk on any modification.

It isn't clear to me that Global Variables will always be written to disk in a timely manner. Will they be written shortly after being set (not at terminal close?) So I only recommend the above two.

 
WHRoeder:

I didn't say that. I said the EA must recover. That means either recalculate values or read from persistent storage (files) when you don't have them in static/globals and write them to disk on any modification.

It isn't clear to me that Global Variables will always be written to disk in a timely manner. Will they be written shortly after being set (not at terminal close?) So I only recommend the above two.



I can only say that pressing F2 will show the Global Variable immediately after it is written. I've suffered power cuts and the GV is there after re-starting.
 
GumRai:

I can only say that pressing F2 will show the Global Variable immediately after it is written. I've suffered power cuts and the GV is there after re-starting.
True gv only expires after several days if it has never been accessed within that time.
 
RTFM tony "Global variables are kept in the client terminal within 4 weeks since the last access"
Reason: