How to Strategies CloseAllOrder if the profit target

Examples step by step how to make your own automated strategy or user indicator
Message
Author
kuekul
Posts: 1
Joined: Fri Mar 04, 2016 10:51 am

How to Strategies CloseAllOrder if the profit target

#1 Postby kuekul » Fri Aug 02, 2019 12:12 pm

How to Strategies CloseAllOrder if the profit target
I can't convert mq4 to FT4

close all orders if the profit target

ferdijo
Posts: 2
Joined: Mon Aug 24, 2020 9:29 am

Re: How to Strategies CloseAllOrder if the profit target

#2 Postby ferdijo » Mon Aug 24, 2020 9:46 am

you can use this coding... ive been using it in ForexTester strategy execution and perfectly fine

extern double TargetProfit = 1000;
bool CloseProfit = true;
double CurrentProfit;

int OnInit()
{
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---

}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
CurrentProfit = AccountEquity()-AccountBalance();
if(CurrentProfit>TargetProfit && CloseProfit)
{
TutupSemua();
}
}

void TutupSemua()
{
double total;
int cnt;
while(OrdersTotal()>0)
{
// close opened orders first
total = OrdersTotal();
for (cnt = total-1; cnt >=0 ; cnt--)
{
if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
{
switch(OrderType())
{
case OP_BUY :
OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),3,Violet);break;

case OP_SELL :
OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),3,Violet); break;
}
}
}
// and close pending
total = OrdersTotal();
for (cnt = total-1; cnt >=0 ; cnt--)
{
if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
{
switch(OrderType())
{
case OP_BUYLIMIT :OrderDelete(OrderTicket()); break;
case OP_SELLLIMIT :OrderDelete(OrderTicket()); break;
case OP_BUYSTOP :OrderDelete(OrderTicket()); break;
case OP_SELLSTOP :OrderDelete(OrderTicket()); break;
}
}
}
}
}


Return to “Programming lessons”

Who is online

Users browsing this forum: No registered users and 23 guests