What's wrong with the stoploss?

 

Hi everyone,

this is a simple expert that actually came with the InterbankFX trader I believe. I noticed the stop loss is WAY off here.

https://www.mql5.com/go?link=http://www.forex1000.com/FXFisherman/bullbear.mql

If the stop loss is set at 30 then it will befor example a stop loss of 30.2227 instead of 1.2227 So above is the code in the mql format, can anyone figure out whats wrong with it?

Thanks

 

Real stoploss must be in point. So, replace StopLoss with StopLoss*Point

 

now instead of showing 30.2227 it shows 31.2227

Maybe its not coded right somewhere else?

 

Maybe this is a backtester's bug, you know it. If you compiled it already, then it should work just fine live.

Just to confirm if you replaced it right. Compare the following code with yours:


SetOrder(OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,RED)


SetOrder(OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,RED)

 

Yep thats exactly what I have minus the space between the Bid and -Takeproft*Point

Ill check this afternoon if its only backtesting or not, but before it was both backtesting AND demo trading that had the problem, hopefully it will resolve it

 

Nope its a problem with live trading as well. It's won 4 consective trades of 10 and 11 pips but stop losses are still at 31.xxxx also I noticed in the backtest its only making short trades, on the live testing all 4 were short as well but that might just be the trend.

Also noticed that it hits 10 and 11 pips profit (spread already passed) and then closes the trade. But the trailing stop is set at 10 and take profit at 30..

This doesnt make much sense..

 

It works just fine on my computer. Test below code.


/*[[ Name := bullbear
Author := Copyright © 2003, Company
Link := http://www.company.com/
Lots := 1.00
Stop Loss := 30
Take Profit := 40
Trailing Stop := 5
]]*/

//previous position
var: pos1pre(0);
//current position
var: pos2cur(0);
var: cnt(0);

comment(Bid+(StopLoss*Point));

pos1pre = iBullsPower(13,PRICE_WEIGHTED,1);
pos2cur = iBullsPower(13,PRICE_WEIGHTED,0);

if pos1pre >pos2cur then
{
//close long position
for cnt=1 to TotalTrades
{
If OrderValue(cnt,VAL_TYPE)=OP_BUY then // buy position open
{
if Bid>(OrderValue(cnt,VAL_OPENPRICE)+TrailingStop*Point) then
{
CloseOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_LOTS),Bid,3,Violet); // close long
Exit;
};
};
};
};


if pos2cur<0 then

//close short position

{
for cnt=1 to TotalTrades
{
if Ask<(OrderValue(cnt,VAL_OPENPRICE)-TrailingStop*Point) then
{
If OrderValue(cnt,VAL_TYPE)=OP_SELL then // sell position open
{


CloseOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_LOTS),Ask,3,Violet); // close short
Exit;
};
};
};
};
If TotalTrades<1 then
{
//no current orders. Check for possible short conditions.
print("pos1pre = "+pos1pre+" pos2cur ="+pos2cur);
if pos1pre>pos2cur and pos2cur>0 then
{

SetOrder(OP_SELL,Lots,Bid,3,Bid+(StopLoss*Point),Bid-(TakeProfit*Point),RED); // open short
Exit;

};

//check for long conditions.

If pos2cur<0 then
{
SetOrder(OP_BUY,Lots,Ask,3,Ask-(StopLoss*Point),Ask+(TakeProfit*Point),RED); // open long
Exit;
};
};

Reason: