Forex Factory (https://www.forexfactory.com/)
-   Platform Tech (https://www.forexfactory.com/forum/69-platform-tech)
-   -   How do I get rid of TP option in EA? (https://www.forexfactory.com/thread/490998-how-do-i-get-rid-of-tp-option)

Thepipster Jun 20, 2014 11:57am | Post# 1

How do I get rid of TP option in EA?
 
I have an EA that closes all trades when equity target is reached. It also has an option for hard TP for each trade. If I select "0" as the setting for TP value, the EA closes that trade as soon as it is opened. Can I just add this line to completely rid the TP option?

input bool UseTP = false;


Or do I have to dive into the modifying orders section of the code, too, and put a "if" command, too? having the EA have to modify the orders with TPs is taking too much time when it's opening the pending orders.

rockit Jun 20, 2014 12:21pm | Post# 2

No, you cannot just insert the line of code because the EA is not aware of such a switch (I persume).
You would also need to make the code that reacts to the switch.

Thepipster Jun 20, 2014 12:35pm | Post# 3

darn....what if I delete the TP input setting line entirely, will that cause an error, too?

(sorry I have to ask, I don't have access to plateform where I am at, or I would just try it, trial and error.)

rockit Jun 20, 2014 12:42pm | Post# 4

Deleting the input will cause a compile error.
You can comment out the TP set code. But for that you'd need to understand the code logic (without seeing the part of code nobody can help you out with this either).

Thepipster Jun 20, 2014 12:45pm | Post# 5

Does this help?

//+------------------------------------------------------------------+
//| Open Buy Pending Orders function |
//+------------------------------------------------------------------+
bool OpenBuyPendingOrder(double BOP)
{
int TicketNumberBuy;
double TProfit, SLoss;
double Spread = MarketInfo(Pair,MODE_SPREAD)*Point;
bool PlacedTrade = false;
bool ModifiedTrade = false;
double Free = AccountBalance();
double OneLot = MarketInfo(Pair,MODE_MARGINREQUIRED);
double Step = MarketInfo(Pair,MODE_LOTSTEP);

TicketNumberBuy = OrderSend(Pair,OP_BUYSTOP,LS,BOP,Slip,0,0,"Gold Mine Buy");

if(TicketNumberBuy == -1)
{
Alert("Buy Order failed, Error NO: "+GetLastError());
PlacedTrade = false;
}
else
{
PlacedTrade = true;
}
if(PlacedTrade)
{
if(OrderSelect(TicketNumberBuy,SELECT_BY_TICKET)==true)
{
TProfit = OrderOpenPrice() + TP*Point;
if(UseSL)
{
SLoss = OrderOpenPrice() - Spread - SL*Point;
}
else
{
SLoss = OrderStopLoss();
}
if(OrderModify(OrderTicket(),OrderOpenPrice(),SLoss,TProfit,0,0)==true)
{
ModifiedTrade = true;
}
else
Alert("Error modifying BuyTrade= "+GetLastError());
}
}
return(true);
}

rockit Jun 20, 2014 12:53pm | Post# 6

Yes.

Inserted Code
bool OpenBuyPendingOrder(double BOP)
{
 int TicketNumberBuy;
 double Spread = MarketInfo(Pair,MODE_SPREAD)*Point;
 double Free = AccountBalance();
 double OneLot = MarketInfo(Pair,MODE_MARGINREQUIRED );
 double Step = MarketInfo(Pair,MODE_LOTSTEP);
 TicketNumberBuy = OrderSend(Pair,OP_BUYSTOP,LS,BOP,Sl ip,0,0,"Gold Mine Buy");
 if(TicketNumberBuy == -1)
 {
    Alert("Buy Order failed, Error NO: "+GetLastError());
    PlacedTrade = false;
 }
 return(true);
}

Magix Jun 20, 2014 12:56pm | Post# 7

I have an EA that closes all trades when equity target is reached. It also has an option for hard TP for each trade. If I select "0" as the setting for TP value, the EA closes that trade as soon as it is opened. Can I just add this line to completely rid the TP option? input bool UseTP = false; Or do I have to dive into the modifying orders section of the code, too, and put a "if" command, too? having the EA have to modify the orders with TPs is taking too much time when it's opening the pending orders.

The Easy way...

Set the TP to a profit that will never be reached in accordance to your lot size. TP=Eleventy Billion!!

Adding lines of code isn't necessarily the necessity...removing the close on tp might do the trick...

Unless code is posted, all anybody can do is guess. Go with the first suggestion if you don't want to post your code.

Thepipster Jun 20, 2014 1:13pm | Post# 8

{quote} The Easy way... Set the TP to a profit that will never be reached in accordance to your lot size. TP=Eleventy Billion!! Adding lines of code isn't necessarily the necessity...removing the close on tp might do the trick... Unless code is posted, all anybody can do is guess. Go with the first suggestion if you don't want to post your code.
This is what I have been currently doing, but I need the EA to place 20 orders in 1 second...MT4 is a joke getting that job done, so I need the order placing process to go ASAP! Since I will never use hard TP, I can save 1/2 per order by not having the EA modify the order before placing the next one. Thanks for the idea, though.

Magix Jun 20, 2014 2:44pm | Post# 9

{quote} This is what I have been currently doing, but I need the EA to place 20 orders in 1 second...MT4 is a joke getting that job done, so I need the order placing process to go ASAP! Since I will never use hard TP, I can save 1/2 per order by not having the EA modify the order before placing the next one. Thanks for the idea, though.

I don't believe it is MT4 you would be having an issue with in getting the job done...

I would say that broker fills on 20 orders in one minute is where the issue is.

Given latency and liquidity, your expectations, as far as I'd be aware, are not exactly what is available.

Thepipster Jun 20, 2014 2:55pm | Post# 10

I am working on bettering the latency problem, too, like getting a VPS right next to the broker's server..got total time to liquidity provider down to 80ms...but eliminating extra steps helps. My next battle is closing a bunch of opened trades ASAP.....arrg

Magix Jun 20, 2014 3:17pm | Post# 11

I am working on bettering the latency problem, too, like getting a VPS right next to the broker's server..got total time to liquidity provider down to 80ms...but eliminating extra steps helps. My next battle is closing a bunch of opened trades ASAP.....arrg

Been there before too...

Just because you want out and have the EA hammer closing all your trades, does not necessarily mean they will close as required.

Additionally...

I know that a part of the reason for the upgrades to build 6+, was so that brokers wouldn't use the same counter measure software on HFTs...but between you and I...how fucking stupid do they really think we are?

spikedog Jun 20, 2014 5:44pm | Post# 12

The problem is in this line of code

Inserted Code
TProfit = OrderOpenPrice() + TP*Point;

If you use TP=0 then this returns OrderOpenPrice and the subsequent OrderModify will close the order.

Change to

Inserted Code
if (TP!=0)
   TProfit = OrderOpenPrice() + TP*Point;
else
  TProfit=0;

fxdaytrader_ Jun 20, 2014 8:39pm | Post# 13

insert an input like double TakeProfitPips = 0.0;

then check

double tp = 0.0;
if (TakeProfitPips!=0.00000) double tp=TakeProfitPips*pips2dbl+Ask/Bid


if (tp!=0.00000) OrderModify(xyz,tp,xyz);

Thepipster Jun 23, 2014 5:53pm | Post# 14

Thanks for all your suggestions, guys, ....I updated the code and tried a trial last night at market open....it didn't change a thing on opening the orders any faster.......It took 2 seconds per order for 10 pending orders to be placed....tried it a few times in a row...20 seconds...I know I've seen grid EAs put up 50 orders in 4-5 seconds...??? I used rokits coding idea.

fxdaytrader_ Jun 23, 2014 6:03pm | Post# 15

you could attach the ea (mql4-file) ...

rockit Jun 24, 2014 3:33am | Post# 16

I updated the code and tried a trial last night at market open....it didn't change a thing on opening the orders any faster... It took 2 seconds per order for 10 pending orders to be placed....tried it a few times in a row...20 seconds...I know I've seen grid EAs put up 50 orders in 4-5 seconds...???
I made this test script to use with my broker (live); it took ~1900ms (1.9 sec) to place 10 pending orders (buy limit) on E/U. My ping time is <50ms and it took ~80-90ms per order (and ~100ms inbetween).
If you get a higher number here then check your ping time to trade server(s) and also execution time, meaning it is an issue with your broker rather than with the EA code.
Check it!
Inserted Code
// TEST script
 
void OnStart()
{
  int i = 0;
  int tm = GetTickCount();
  for(; i < 10;) {
    if(OrderSend(NULL, OP_BUYLIMIT, 0.01, 0.00001, 0, 0, 0) != -1) i++;
  }
  Print("time (ms): ", GetTickCount() - tm);
}


© Forex Factory