Virtual TakeProfit and StopLoss
Virtual_TakeProfit_StopLoss
The adviser exposes the stop-loss and take-profit, invisible to the broker. But keep in mind that the adviser must be constantly at work. Those. You can not turn off the computer or close the terminal.
In the tester, the Expert Advisor opens the positions for himself and accompanies them with stops.
Code :
Download : Virtual_TakeProfit_StopLoss.mq4
The adviser exposes the stop-loss and take-profit, invisible to the broker. But keep in mind that the adviser must be constantly at work. Those. You can not turn off the computer or close the terminal.
In the tester, the Expert Advisor opens the positions for himself and accompanies them with stops.
Code :
//+------------------------------------------------------------------+
//| Virtual_TakeProfit_StopLoss.mq4 |
//| Copyright 2018, MetaEditor. |
//| http://www.meta-editor.blogspot.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaEditor."
#property link "http://www.meta-editor.blogspot.com"
#property version "1.00"
#property strict
//--------------------------------------------------------------------
input int Stoploss = 100;
input int Takeprofit = 50;
input int slippage = 30;
//--------------------------------------------------------------------
void OnTick()
{
double OOP;
for (int i=0; i<OrdersTotal(); i++)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if (OrderSymbol()==Symbol())
{
int tip = OrderType();
OOP = NormalizeDouble(OrderOpenPrice(),Digits);
if (tip==OP_BUY)
{
if (Stoploss!=0 && Bid<=OOP - Stoploss * Point) {if (OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),slippage,clrNONE)) continue;}
if (Takeprofit!=0 && Bid>=OOP + Takeprofit * Point) {if (OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),slippage,clrNONE)) continue;}
}
if (tip==OP_SELL)
{
if (Stoploss!=0 && Ask>=OOP + Stoploss * Point) {if (OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),slippage,clrNONE)) continue;}
if (Takeprofit!=0 && Ask<=OOP - Takeprofit * Point) {if (OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),slippage,clrNONE)) continue;}
}
}
}
}
//---
int err;
if (IsTesting() && OrdersTotal()==0)
{
double Lot=0.1;
err=OrderSend(Symbol(),OP_BUY,Lot,NormalizeDouble(Ask,Digits),slippage,0,0,"тест",0);
err=OrderSend(Symbol(),OP_SELL,Lot,NormalizeDouble(Bid,Digits),slippage,0,0,"тест",0);
return;
}
}
//+------------------------------------------------------------------+
Download : Virtual_TakeProfit_StopLoss.mq4


