Orders Execution
0
Views
0
Downloads
0
Favorites
StealthStopLoss
//+------------------------------------------------------------------+
//| StealthStopLoss.mq4 |
//| |
//| This indicator is for monitoring how close a position is to a |
//| hidden StopLoss, referred to as a Stealth StopLoss. It is |
//| in the sense that it does not show up on the Broker's server. |
//| This avoids Stop Hunting by the Broker, whether real or imagined.|
//| |
//| An indicator can't close positions, so coded to easily add to an |
//| EA. |
//| |
//| Could create an EA to consistently control all open positions. |
//| To be specific to a Magic.Number, would need to add code. |
//| |
//+------------------------------------------------------------------+
#property copyright "Mark"
#property link ""
#property indicator_chart_window
extern double Stealth.Stop.Loss=120; //Maximum pip loss allowed
extern bool Display.Lower.Left.Corner=true; //False puts it in lower right corner
//extern int Slippage=3; //If you cut this too close, you'll miss an exit
//Slippage only relevant in an EA for closing positions
//+------------------------------------------------------------------+
int init()
{
Stealth.Stop.Loss=Stealth.Stop.Loss*Point;
ObjectCreate("SLStatus",OBJ_LABEL,0,0,0);
ObjectSetText("SLStatus","",8,"Arial",Green);
ObjectSet("SLStatus",OBJPROP_CORNER,3);
ObjectSet("SLStatus",OBJPROP_XDISTANCE,5);
ObjectSet("SLStatus",OBJPROP_YDISTANCE,5);
return(0);
}
//+------------------------------------------------------------------+
int deinit()
{
ObjectsDeleteAll(0,OBJ_LABEL);
return(0);
}
//+------------------------------------------------------------------+
int start()
{
if(Stealth.Stop.Loss<=0)
{
DisplayComment("Stealth S/L not selected",1);
return(0);
}
double dCalc1=1,dCalc2=0;
string sComment="No orders for Stealth S/L to monitor";
for(int i=0;i<=OrdersTotal();i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if (OrderSymbol() == Symbol()) //((OrderSymbol() == Symbol()) && (OrderMagicNumber() == Magic.Number))
{
if(OrderType()==OP_BUY)
{
dCalc1=Bid-OrderOpenPrice();
dCalc2=Stealth.Stop.Loss+dCalc1;
if(Stealth.Stop.Loss>0 && dCalc2<0)
{
sComment="Stealth.Stop.Loss Activated. Closing Longs";
//OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Blue);
//Print("Long Order # "+OrderTicket()+" exited by Stealth S/L");
//return(0);
}
else sComment= "Stealth S/L Active. S/L="+DoubleToStr(Stealth.Stop.Loss/Point,0)+" | Pips="+DoubleToStr(dCalc1/Point,0)+" | To S/L="+DoubleToStr(dCalc2/Point,0);
}
if(OrderType()==OP_SELL)
{
dCalc1=OrderOpenPrice()-Ask;
dCalc2=Stealth.Stop.Loss+dCalc1;
if(Stealth.Stop.Loss>0 && dCalc2<0)
{
sComment="Stealth.Stop.Loss Activated. Closing Shorts";
//OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Red);
//Print("Short Order # "+OrderTicket()+" exited by Stealth S/L");
//return(0);
}
else sComment= "Stealth S/L Active. S/L="+DoubleToStr(Stealth.Stop.Loss/Point,0)+" | Pips="+DoubleToStr(dCalc1/Point,0)+" | To S/L="+DoubleToStr(dCalc2/Point,0);
}
}
}
DisplayComment(sComment,dCalc1);
return(0);
}
//+------------------------------------------------------------------+
void DisplayComment(string tComment, double tResult)
{
if(tResult>0) ObjectSetText("SLStatus",tComment,8,"Arial",Green);
else ObjectSetText("SLStatus",tComment,8,"Arial",Red);
if(Display.Lower.Left.Corner) ObjectSet("SLStatus",OBJPROP_CORNER,2);
else ObjectSet("SLStatus",OBJPROP_CORNER,3);
return(0);
}
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---