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.
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()
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;
Wrong this will fail if all trades close
then you can't restart with first TP-level
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.
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 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.
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.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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