larger stoploss after win

 

How can i increase stoploss after win?

For example: IF I WIN FIRST TRADE WITH 30 PIPS STOPLOSS, I WANT OPEN SECOND TRADE WITH 30 + 15 = 45 PIPS STOPLOSS, IF I WIN SECOND TRADE TOO, I WANT OPEN THIRD TRADE WITH 45 + 15 = 60 PIPS STOPLOSS. ETC................ Can you write me code? Thank you.

 
double pipIncrease = 15;
int count,startPips=30;
for(int i=OrdersHistoryTotal()-1;i>=0;i--)
{
OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
if(OrderProfit()>0)count++;else break;
}
StopLossPips = count*pipIncrease+startPips;
Try that.
 
heelflip43:
Try that.
double pipIncrease = 15;
int count,startPips=30;
for(int i=OrdersTotal();i>=0;i--)
{
OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
if(OrderProfit()>0)count++;else break;
}
StopLossPips = count*pipIncrease+startPips;

This is wrong OrdersTotal() are the open trades, OrdersHistoryTotal() are the closed ones

Profit is not only OrderProfit() count also OrderCommision() and OrderSwap() of the trades

Also check Symbol() MagicNumber() .... Ordertime() closed...

 
deVries:

This is wrong OrdersTotal() are the open trades, OrdersHistoryTotal() are the closed ones

Profit is not only OrderProfit() count also OrderCommision() and OrderSwap() of the trades

Also check Symbol() MagicNumber() .... Ordertime() closed...

I only realised that after I clicked submit, I'm more used to open orders. I had edited or was in the process of editing when you posted. The OrderCloseTime should already be > 0 because of the MODE_HISTORY.

double pipIncrease = 15;
int count,startPips=30;
int MagicNo = 0; // Change to your magic number
for(int i=OrdersHistoryTotal()-1;i>=0;i--)
{
OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
if(OrderSymbol()==Symbol()&&MagicNo==OrderMagicNumber()){
if(OrderProfit()-(OrderCommission()+OrderSwap())>0)count++;else break;
}
}
double StopLossPips = count*pipIncrease+startPips;
 
rozirozi:

How can i increase stoploss after win?

For example: IF I WIN FIRST TRADE WITH 30 PIPS STOPLOSS, I WANT OPEN SECOND TRADE WITH 30 + 15 = 45 PIPS STOPLOSS, IF I WIN SECOND TRADE TOO, I WANT OPEN THIRD TRADE WITH 45 + 15 = 60 PIPS STOPLOSS. ETC................ Can you write me code? Thank you.

No need TO SHOUT.

Your premise is wrong. You place the SL where you know the trade is wrong. Lot size = risk amount / (open-SL)/ PointValuePerLot See my code.

No Slaves here, learn to code or pay someone. We're not going to code it FOR you. We are willing to HELP you.
 
heelflip43:

I only realised that after I clicked submit, I'm more used to open orders. I had edited or was in the process of editing when you posted. The OrderCloseTime should already be > 0 because of the MODE_HISTORY.


It´s great:-) Thank you. But i have problem, it doesn´t work with ECN brookers. With ECN brookers i must use OrderModify function for stoploss and takeprofit.

For example:

Normal brooker: Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);

ECN brooker: Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);

OrderModify(Ticket,OrderOpenPrice(),StopLossLevel,TakeProfitLevel,0,DodgerBlue);

What should I change to make it work with ECN brokers? Thank you

 
rozirozi:


It´s great:-) Thank you. But i have problem, it doesn´t work with ECN brookers. With ECN brookers i must use OrderModify function for stoploss and takeprofit.

For example:

Normal brooker: Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);

ECN brooker: Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);

OrderModify(Ticket,OrderOpenPrice(),StopLossLevel,TakeProfitLevel,0,DodgerBlue);

What should I change to make it work with ECN brokers? Thank you


0,0, "Buy(#" + MagicNumber + ")"

change that to get it right and think about why it doesn't work on ECN accounts

 
rozirozi:
It´s great:-) Thank you. But i have problem, it doesn´t work with ECN brookers. With ECN brookers i must use OrderModify function for stoploss and takeprofit.

Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, 
                   "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);
What should I change to make it work with ECN brokers?


Use this and you would have found "Open first and THEN set stops."
    int ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0, 
                           "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);)
    if (ticket < 0)
       Alert("OrderSend failed: ", GetLastError());
    else if (!OrderSelect(ticket, SELECT_BY_TICKET))
       Alert("OrderSelect failed: ", GetLastError());
    else if (!OrderModify(OrderTicket(), StopLossLevel, TakeProfitLevel, 0)
       Alert("OrderModify failed: ", GetLastError());
Reason: