how to calculate to double up my last Takeprofit.

To add comments, please log in or register
dralialadin
142
dralialadin  

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

Keith Watford
Moderator
24223
Keith Watford  

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.

FxAutomatedcom
1054
FxAutomatedcom  
Hey you can do something like TP=TP*2 .
William Roeder
22355
William Roeder  
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()

Tjipke de Vries
6705
Tjipke de Vries  
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; 
FxAutomatedcom
1054
FxAutomatedcom  
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.
Keith Watford
Moderator
24223
Keith Watford  
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.

William Roeder
22355
William Roeder  
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.

Keith Watford
Moderator
24223
Keith Watford  
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.
FxAutomatedcom
1054
FxAutomatedcom  
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.
William Roeder
22355
William Roeder  
RTFM tony "Global variables are kept in the client terminal within 4 weeks since the last access"
To add comments, please log in or register