Fixed SOME kinks in my EA

 

Can someone elaborate why limit orders on back-testing fail?


I've been trying to program an EA to set buystops and sellstops but it doesnt work. But when i change it to buy/sell respectively, it start's making trades. I am trying to get this damn thing to manage trades if the sellstop or buystop level changes and make 1 trade at a time. I don't know if I am doing something wrong with the code or is the backtest failing to recognize limits/stops.



int start()
{
//----
double Up,Dn;
int trend, ticket, ticketsell;
trend = iCustom(Symbol(),PERIOD_M1,"X",15,14,4,1,4,0);

if(trend>0 && Up==0){Dn= iCustom(Symbol(),PERIOD_M1,"X",15,14,4,1,0,0);

Print("Sell: ",Dn);
if(OrdersTotal()==0 && (Ask>=Dn) && (iStdDev(Symbol(),0,20,0,MODE_SMA,PRICE_CLOSE,0) <=risk))
{
ticketsell =OrderSend(Symbol(),OP_SELLSTOP,Lots,Bid,0,Bid+30*Point,Bid-TakeProfit*Point,"SELL",16384,0,Red);

} else if (OrdersTotal()>0 && (Up > iCustom(Symbol(),PERIOD_M1,"X",15,14,3,1,0,x+1)){
OrderModify(ticketsell,Up, Up+5*Point,Up-TakeProfit*Point,0,Red); // close position
}

RefreshRates();
}


if(trend<0 && Dn==0){Up= iCustom(Symbol(),PERIOD_M1,"X",15,14,4,1,1,0);
Print("Long: ",Up);
if(OrdersTotal()==0 && (Bid<=Up) && (iStdDev(Symbol(),0,20,0,MODE_SMA,PRICE_CLOSE,0) <=risk)){
ticket =OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask,0,Ask-30*Point,Ask+TakeProfit*Point,"BUY",16345,0,Green);
} else if(Dn<iCustom(Symbol(),PERIOD_M1,"X",15,14,3,1,1,x+1){
OrderModify(ticket,Dn,Dn-5*Point,Dn+TakeProfit*Point,0,Green);
}

RefreshRates();
}

//----
return(0);
}



When i replace the OP_BUYSTOP & OP_SELLSTOP with OP_BUY & OP_SELL respectively, and remove the "else if" part of the code after the ordersend this is the result:




Settings for the above were: $0.25/pip, 10 PIP t/p, No stop. Scalp's break-outs on the M1 time frame.. very accurate.. would be more accurate of the damn stops worked.


I like using low initial deposit values so I don't delude myself. I am happy with 20%+ return trading quarters.


I used visual mode and ran the program very slow and trades where stops would have been great were not made... Trades were only made when the Ask/Buy was equal to the value of the Sell/Buy recommendation value from the indicator..


I'm trying to get the stopsell level in the order to change if the indicator spits out a higher stopsell level than previous... if anyone can help by clarifying or showing me a simple script which sends limit orders based on a condition and then changes the limit order if the base condition changes, it would be greatly appreciated.



Please also let me know what you think of the results.


Cheers!


 
twizt wrote >>


ticketsell =OrderSend(Symbol(),OP_SELLSTOP,Lots,Bid,0,Bid+30*Point,Bid-TakeProfit*Point,"SELL",16384,0,Red);

hello, to place sellstop, u can't place at Bid price and similar for bustop, u can't place at Ask price !

you have to place them further away, if you understand what a sellstop or buystop means

 
Thanks. I wasn't trying to place @ Bid. I was thinking more if the asking price hit the bid price for the particular time. Other than that, does the So does the order modifying part look right?
Reason: