Stoploss wont move with each candle...help

Back to topics list To post a new topic, please log in or register
avatar
5
bondstrader 2015.09.01 06:31
 
Hopefully someone can help me out of this.
In the following code opening a long position if the current price is higher than the previous candle's High.
Then I set a profit target, and a stop loss. The profit target is static, so that works fine, but the stop loss is variable. I have set it to look for the lowest price of the last 5 candles, and set that as a stop loss. However, in my code, what it does is that it sets the stop loss based on the lowest price of the 5 candles before the trade candle, and fixes it at that value. 
I want the stop to keep on moving with each candle, i-e, after each candle, it evaluates the lowest value of the last 5 candles and sets the stop as that....

Any ideas on what Im missing?

 

        OrderSelect(LongTicket,SELECT_BY_TICKET);
if (OrderCloseTime() != 0 || LongTicket == 0)
{    

bool buy_condition_1 = Ask >= High[1]; 

 if( buy_condition_1)
{
     LongTicket = OrderSend(Symbol(),OP_BUY,LotSize,Ask,0,0,0,"Buy Order",MagicNumber,0,Green);
     OrderSelect(LongTicket,SELECT_BY_TICKET); 
     double OpenPrice = OrderOpenPrice();
                      double LongStopLoss =  Low[iLowest(NULL,0,MODE_LOW,5,1)];
                      double LongTakeProfit = OpenPrice + (TakeProfit * TickPoints);
            
if(LongStopLoss > 0 || LongTakeProfit > 0) 
{
                       bool LongMod = OrderModify(OrderTicket(),OpenPrice,LongStopLoss, LongTakeProfit,0);
}
}
}
avatar
Moderator
3419
GumRai 2015.09.01 06:43 #
 

As your code will only be executed if the trade is closed or doesn't exist, it cannot modify an open trade

Add additional code to check and modify the order, if necessary, and  outside of that block of code 

Back to topics list  

To add comments, please log in or register